mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-02-20 15:41:01 +00:00
use common QSBRotatingElements base class + auth queue
This commit is contained in:
parent
0a9ccfd0db
commit
a5d7eeb1f7
@ -1,13 +1,13 @@
|
||||
using QSB.EchoesOfTheEye.AirlockSync.VariableSync;
|
||||
using QSB.Utility.LinkedWorldObject;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace QSB.EchoesOfTheEye.AirlockSync.WorldObjects;
|
||||
|
||||
internal class QSBGhostAirlock : LinkedWorldObject<GhostAirlock, AirlockVariableSyncer>
|
||||
internal class QSBGhostAirlock : QSBRotatingElements<GhostAirlock, AirlockVariableSyncer>
|
||||
{
|
||||
public override void SendInitialState(uint to) { }
|
||||
protected override IEnumerable<SingleLightSensor> LightSensors => AttachedObject._interface._lightSensors;
|
||||
|
||||
protected override GameObject NetworkObjectPrefab => QSBNetworkManager.singleton.AirlockPrefab;
|
||||
protected override bool SpawnWithServerAuthority => true;
|
||||
protected override bool SpawnWithServerAuthority => false;
|
||||
}
|
||||
|
@ -1,16 +1,17 @@
|
||||
using QSB.EchoesOfTheEye.EclipseDoors.VariableSync;
|
||||
using QSB.Utility.LinkedWorldObject;
|
||||
using HarmonyLib;
|
||||
using QSB.EchoesOfTheEye.EclipseDoors.VariableSync;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace QSB.EchoesOfTheEye.EclipseDoors.WorldObjects;
|
||||
|
||||
internal class QSBEclipseDoorController : LinkedWorldObject<EclipseDoorController, EclipseDoorVariableSyncer>
|
||||
internal class QSBEclipseDoorController : QSBRotatingElements<EclipseDoorController, EclipseDoorVariableSyncer>
|
||||
{
|
||||
public override void SendInitialState(uint to) { }
|
||||
protected override IEnumerable<SingleLightSensor> LightSensors => AttachedObject._lightSensors;
|
||||
|
||||
public override string ReturnLabel()
|
||||
=> $"{base.ReturnLabel()}\r\n- SyncerValue:{NetworkBehaviour.Value}\r\n- HasAuth:{NetworkBehaviour.hasAuthority}";
|
||||
=> $"{base.ReturnLabel()}\r\n- SyncerValue:{NetworkBehaviour.Value.Join()}\r\n- HasAuth:{NetworkBehaviour.hasAuthority}";
|
||||
|
||||
protected override GameObject NetworkObjectPrefab => QSBNetworkManager.singleton.DoorPrefab;
|
||||
protected override bool SpawnWithServerAuthority => true;
|
||||
protected override bool SpawnWithServerAuthority => false;
|
||||
}
|
||||
|
@ -1,16 +1,17 @@
|
||||
using QSB.EchoesOfTheEye.EclipseElevators.VariableSync;
|
||||
using QSB.Utility.LinkedWorldObject;
|
||||
using HarmonyLib;
|
||||
using QSB.EchoesOfTheEye.EclipseElevators.VariableSync;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace QSB.EchoesOfTheEye.EclipseElevators.WorldObjects;
|
||||
|
||||
internal class QSBEclipseElevatorController : LinkedWorldObject<EclipseElevatorController, EclipseElevatorVariableSyncer>
|
||||
internal class QSBEclipseElevatorController : QSBRotatingElements<EclipseElevatorController, EclipseElevatorVariableSyncer>
|
||||
{
|
||||
public override void SendInitialState(uint to) { }
|
||||
protected override IEnumerable<SingleLightSensor> LightSensors => AttachedObject._lightSensors;
|
||||
|
||||
public override string ReturnLabel()
|
||||
=> $"{base.ReturnLabel()}\r\n- SyncerValue:{NetworkBehaviour.Value}\r\n- HasAuth:{NetworkBehaviour.hasAuthority}";
|
||||
=> $"{base.ReturnLabel()}\r\n- SyncerValue:{NetworkBehaviour.Value.Join()}\r\n- HasAuth:{NetworkBehaviour.hasAuthority}";
|
||||
|
||||
protected override GameObject NetworkObjectPrefab => QSBNetworkManager.singleton.ElevatorPrefab;
|
||||
protected override bool SpawnWithServerAuthority => true;
|
||||
protected override bool SpawnWithServerAuthority => false;
|
||||
}
|
||||
|
50
QSB/EchoesOfTheEye/QSBRotatingElements.cs
Normal file
50
QSB/EchoesOfTheEye/QSBRotatingElements.cs
Normal file
@ -0,0 +1,50 @@
|
||||
using Cysharp.Threading.Tasks;
|
||||
using Mirror;
|
||||
using QSB.AuthoritySync;
|
||||
using QSB.EchoesOfTheEye.LightSensorSync.WorldObjects;
|
||||
using QSB.Utility.LinkedWorldObject;
|
||||
using QSB.WorldSync;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using UnityEngine;
|
||||
|
||||
namespace QSB.EchoesOfTheEye;
|
||||
|
||||
internal abstract class QSBRotatingElements<T, U> : LinkedWorldObject<T, U>
|
||||
where T : MonoBehaviour
|
||||
where U : NetworkBehaviour
|
||||
{
|
||||
public override void SendInitialState(uint to) { }
|
||||
|
||||
protected abstract IEnumerable<SingleLightSensor> LightSensors { get; }
|
||||
private QSBLightSensor[] _qsbLightSensors;
|
||||
|
||||
public override async UniTask Init(CancellationToken ct)
|
||||
{
|
||||
await base.Init(ct);
|
||||
|
||||
await UniTask.WaitUntil(() => QSBWorldSync.AllObjectsAdded, cancellationToken: ct);
|
||||
_qsbLightSensors = LightSensors.Select(x => x.GetWorldObject<QSBLightSensor>()).ToArray();
|
||||
|
||||
foreach (var lightSensor in _qsbLightSensors)
|
||||
{
|
||||
lightSensor.OnDetectLocalLight += OnDetectLocalLight;
|
||||
lightSensor.OnDetectLocalDarkness += OnDetectLocalDarkness;
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnRemoval()
|
||||
{
|
||||
base.OnRemoval();
|
||||
|
||||
foreach (var lightSensor in _qsbLightSensors)
|
||||
{
|
||||
lightSensor.OnDetectLocalLight -= OnDetectLocalLight;
|
||||
lightSensor.OnDetectLocalDarkness -= OnDetectLocalDarkness;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDetectLocalLight() => NetworkBehaviour.netIdentity.UpdateAuthQueue(AuthQueueAction.Add);
|
||||
private void OnDetectLocalDarkness() => NetworkBehaviour.netIdentity.UpdateAuthQueue(AuthQueueAction.Remove);
|
||||
}
|
@ -35,10 +35,7 @@ public class QSBRaft : LinkedWorldObject<RaftController, RaftTransformSync>
|
||||
|
||||
public override void OnRemoval()
|
||||
{
|
||||
if (QSBCore.IsHost)
|
||||
{
|
||||
NetworkServer.Destroy(NetworkBehaviour.gameObject);
|
||||
}
|
||||
base.OnRemoval();
|
||||
|
||||
foreach (var lightSensor in _lightSensors)
|
||||
{
|
||||
|
@ -1,4 +1,5 @@
|
||||
using Mirror;
|
||||
using QSB.AuthoritySync;
|
||||
using QSB.Utility.LinkedWorldObject;
|
||||
using QSB.Utility.VariableSync;
|
||||
using QSB.WorldSync;
|
||||
@ -10,6 +11,26 @@ namespace QSB.EchoesOfTheEye;
|
||||
internal abstract class RotatingElementsVariableSyncer<TWorldObject> : BaseVariableSyncer<Quaternion[]>, ILinkedNetworkBehaviour
|
||||
where TWorldObject : IWorldObject
|
||||
{
|
||||
public override void OnStartClient()
|
||||
{
|
||||
if (QSBCore.IsHost)
|
||||
{
|
||||
netIdentity.RegisterAuthQueue();
|
||||
}
|
||||
|
||||
base.OnStartClient();
|
||||
}
|
||||
|
||||
public override void OnStopClient()
|
||||
{
|
||||
if (QSBCore.IsHost)
|
||||
{
|
||||
netIdentity.UnregisterAuthQueue();
|
||||
}
|
||||
|
||||
base.OnStopClient();
|
||||
}
|
||||
|
||||
protected abstract Transform[] RotatingElements { get; }
|
||||
|
||||
protected override bool HasChanged()
|
||||
|
Loading…
x
Reference in New Issue
Block a user