Skip to content

Commit 0e645cd

Browse files
authored
Merge pull request #144 from Raicuparta/dev
Master <- Dev
2 parents 535f89c + dc39c2a commit 0e645cd

File tree

6 files changed

+27
-20
lines changed

6 files changed

+27
-20
lines changed

QSB/Events/EventHandler.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ private void OnServerReceiveMessage(EventMessage message)
4545
private void OnClientReceiveMessage(EventMessage message)
4646
{
4747
var player = PlayerRegistry.GetPlayer(message.SenderId);
48-
player.IsReady = true;
4948
if (message.SenderId == PlayerRegistry.LocalPlayer.NetId)
5049
{
5150
return;

QSB/Events/PlayerJoin.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ private void OnClientReceiveMessage(JoinMessage message)
4848
{
4949
var player = PlayerRegistry.CreatePlayer(message.SenderId);
5050
player.Name = message.PlayerName;
51-
player.IsReady = true;
5251
DebugLog.ToAll(message.PlayerName, "joined!");
5352
}
5453
}

QSB/PlayerInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class PlayerInfo
1717
public QSBTool Translator => GetToolByType(ToolType.Translator);
1818
public QSBTool ProbeLauncher => GetToolByType(ToolType.ProbeLauncher);
1919
public string Name { get; set; }
20-
public bool IsReady { get; set; }
20+
public bool IsReady => Body != null;
2121
public State State { get; private set; }
2222

2323
public PlayerInfo(uint id)

QSB/Tools/PlayerToolsManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ private static void CreateTranslator()
124124
tool.ArrivalDegrees = 5f;
125125
tool.Type = ToolType.Translator;
126126
tool.ToolGameObject = group.gameObject;
127-
oldTranslator.enabled = false;
127+
Object.Destroy(oldTranslator);
128128

129129
GetRenderer(translatorRoot, "Props_HEA_Translator_Geo").material = _playerToolsMaterial;
130130
GetRenderer(translatorRoot, "Props_HEA_Translator_RotatingPart").material = _playerToolsMaterial;

QSB/TransformSync/SectorSync.cs

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
using QSB.Messaging;
1+
using System.Collections.Generic;
2+
using QSB.Messaging;
23
using UnityEngine;
34
using System.Linq;
45
using QSB.Utility;
5-
using UnityEngine.SceneManagement;
66

77
namespace QSB.TransformSync
88
{
99
public class SectorSync : MonoBehaviour
1010
{
11-
private Sector[] _allSectors;
11+
private readonly List<Sector> _allSectors = new List<Sector>();
1212
private MessageHandler<SectorMessage> _sectorHandler;
1313

1414
private readonly Sector.Name[] _sectorBlacklist =
@@ -19,7 +19,19 @@ public class SectorSync : MonoBehaviour
1919

2020
private void Awake()
2121
{
22-
SceneManager.sceneLoaded += OnSceneLoaded;
22+
QSB.Helper.Events.Subscribe<Sector>(OWML.Common.Events.AfterAwake);
23+
QSB.Helper.Events.Event += OnEvent;
24+
}
25+
26+
private void OnEvent(MonoBehaviour behaviour, OWML.Common.Events ev)
27+
{
28+
if (behaviour is Sector sector && ev == OWML.Common.Events.AfterAwake)
29+
{
30+
if (!_allSectors.Contains(sector))
31+
{
32+
_allSectors.Add(sector);
33+
}
34+
}
2335
}
2436

2537
private void Start()
@@ -29,11 +41,6 @@ private void Start()
2941
_sectorHandler.OnServerReceiveMessage += OnServerReceiveMessage;
3042
}
3143

32-
private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
33-
{
34-
_allSectors = FindObjectsOfType<Sector>();
35-
}
36-
3744
private void SendSector(uint id, Sector sector)
3845
{
3946
DebugLog.ToScreen($"Sending sector {sector.name} for id {id}");
@@ -50,23 +57,24 @@ private void SendSector(uint id, Sector sector)
5057
private Sector FindSectorByName(Sector.Name sectorName, string goName)
5158
{
5259
return _allSectors?
53-
.FirstOrDefault(sector => sector.GetName() == sectorName && sector.name == goName);
60+
.FirstOrDefault(sector => sector != null &&
61+
sector.GetName() == sectorName &&
62+
sector.name == goName);
5463
}
5564

5665
private void OnClientReceiveMessage(SectorMessage message)
5766
{
58-
var sectorName = (Sector.Name)message.SectorId;
5967
DebugLog.ToScreen($"Received sector {message.SectorName} for id {message.SenderId}");
6068

61-
var sector = FindSectorByName(sectorName, message.SectorName);
69+
var sector = FindSectorByName((Sector.Name)message.SectorId, message.SectorName);
6270

6371
if (sector == null)
6472
{
65-
DebugLog.ToScreen($"Sector {sectorName} not found");
73+
DebugLog.ToScreen($"Sector {message.SectorName} not found");
6674
return;
6775
}
6876

69-
DebugLog.ToScreen($"Found sector {sectorName} for {message.SenderId}");
77+
DebugLog.ToScreen($"Found sector {message.SectorName} for {message.SenderId}");
7078
PlayerRegistry.GetTransformSync(message.SenderId).ReferenceTransform = sector.transform;
7179
}
7280

@@ -105,7 +113,8 @@ private void UpdateTransformSync(TransformSync transformSync)
105113
private Sector GetClosestSector(Transform trans)
106114
{
107115
return _allSectors?
108-
.Where(sector => !_sectorBlacklist.Contains(sector.GetName()))
116+
.Where(sector => sector != null &&
117+
!_sectorBlacklist.Contains(sector.GetName()))
109118
.OrderBy(sector => Vector3.Distance(sector.transform.position, trans.position))
110119
.First();
111120
}

QSB/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
"name": "Quantum Space Buddies",
55
"description": "Adds online multiplayer to the game.",
66
"uniqueName": "Raicuparta.QuantumSpaceBuddies",
7-
"version": "0.3.1",
7+
"version": "0.3.2",
88
"owmlVersion": "0.7.2"
99
}

0 commit comments

Comments
 (0)