mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-03-10 07:14:27 +00:00
remove orb sync
This commit is contained in:
parent
0cfa74ef70
commit
9557d32851
@ -2,7 +2,6 @@
|
||||
using QSB.DeathSync;
|
||||
using QSB.ElevatorSync;
|
||||
using QSB.GeyserSync;
|
||||
using QSB.OrbSync;
|
||||
using QSB.TimeSync;
|
||||
using QSB.Tools;
|
||||
using QSB.TransformSync;
|
||||
@ -38,10 +37,7 @@ namespace QSB.Events
|
||||
new ElevatorEvent(),
|
||||
new GeyserEvent(),
|
||||
new ServerTimeEvent(),
|
||||
new AnimTriggerEvent(),
|
||||
new OrbSlotEvent()
|
||||
//new OrbUserEvent()
|
||||
//new OrbStatusEvent()
|
||||
new AnimTriggerEvent()
|
||||
};
|
||||
|
||||
_eventList.ForEach(ev => ev.SetupListener());
|
||||
|
@ -29,8 +29,5 @@
|
||||
public static string QSBStartLift = "QSBStartLift";
|
||||
public static string QSBGeyserState = "QSBGeyserState";
|
||||
public static string QSBAnimTrigger = "QSBAnimTrigger";
|
||||
public static string QSBOrbSlot = "QSBOrbSlot";
|
||||
public static string QSBOrbUser = "QSBOrbUser";
|
||||
public static string QSBOrbStatus = "QSBOrbStatus";
|
||||
}
|
||||
}
|
||||
|
@ -1,37 +0,0 @@
|
||||
using QSB.Events;
|
||||
using QSB.Messaging;
|
||||
using QSB.WorldSync;
|
||||
|
||||
namespace QSB.OrbSync
|
||||
{
|
||||
public class OrbSlotEvent : QSBEvent<BoolWorldObjectMessage>
|
||||
{
|
||||
public override EventType Type => EventType.OrbSlot;
|
||||
|
||||
public override void SetupListener()
|
||||
{
|
||||
GlobalMessenger<int, bool>.AddListener(EventNames.QSBOrbSlot, Handler);
|
||||
}
|
||||
|
||||
public override void CloseListener()
|
||||
{
|
||||
GlobalMessenger<int, bool>.RemoveListener(EventNames.QSBOrbSlot, Handler);
|
||||
}
|
||||
|
||||
private void Handler(int id, bool state) => SendEvent(CreateMessage(id, state));
|
||||
|
||||
private BoolWorldObjectMessage CreateMessage(int id, bool state) => new BoolWorldObjectMessage
|
||||
{
|
||||
AboutId = LocalPlayerId,
|
||||
ObjectId = id,
|
||||
State = state
|
||||
};
|
||||
|
||||
public override void OnReceiveRemote(BoolWorldObjectMessage message)
|
||||
{
|
||||
|
||||
var orbSlot = WorldRegistry.GetObject<QSBOrbSlot>(message.ObjectId);
|
||||
orbSlot?.SetState(message.State);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
using QSB.WorldSync;
|
||||
using UnityEngine;
|
||||
|
||||
namespace QSB.OrbSync
|
||||
{
|
||||
public class OrbSlotManager : MonoBehaviour
|
||||
{
|
||||
public static OrbSlotManager Instance { get; private set; }
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
Instance = this;
|
||||
QSBSceneManager.OnSceneLoaded += OnSceneLoaded;
|
||||
}
|
||||
|
||||
private void OnSceneLoaded(OWScene scene, bool isInUniverse)
|
||||
{
|
||||
var orbSlots = Resources.FindObjectsOfTypeAll<NomaiInterfaceSlot>();
|
||||
for (var id = 0; id < orbSlots.Length; id++)
|
||||
{
|
||||
var qsbOrbSlot = WorldRegistry.GetObject<QSBOrbSlot>(id) ?? new QSBOrbSlot();
|
||||
qsbOrbSlot.Init(orbSlots[id], id);
|
||||
WorldRegistry.AddObject(qsbOrbSlot);
|
||||
}
|
||||
}
|
||||
|
||||
public void StopChecking()
|
||||
{
|
||||
QSB.Helper.HarmonyHelper.AddPrefix<NomaiInterfaceSlot>("CheckOrbCollision", typeof(OrbSlotPatches), nameof(OrbSlotPatches.CheckOrbCollisionSkip));
|
||||
}
|
||||
}
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
namespace QSB.OrbSync
|
||||
{
|
||||
public static class OrbSlotPatches
|
||||
{
|
||||
public static bool CheckOrbCollisionSkip(NomaiInterfaceOrb orb)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
public static void StartDragCallEvent(bool __result, NomaiInterfaceOrb __instance)
|
||||
{
|
||||
if (__result)
|
||||
{
|
||||
DebugLog.DebugWrite("Sending using message for " + WorldRegistry.OldOrbList.FindIndex(x => x == __instance));
|
||||
GlobalMessenger<int>.FireEvent(EventNames.QSBOrbUser, WorldRegistry.OldOrbList.FindIndex(x => x == __instance));
|
||||
}
|
||||
GlobalMessenger<int, bool>.FireEvent(EventNames.QSBOrbStatus, WorldRegistry.OldOrbList.FindIndex(x => x == __instance), __result);
|
||||
}
|
||||
|
||||
public static void CancelDrag(NomaiInterfaceOrb __instance)
|
||||
{
|
||||
GlobalMessenger<int, bool>.FireEvent(EventNames.QSBOrbStatus, WorldRegistry.OldOrbList.FindIndex(x => x == __instance), false);
|
||||
}
|
||||
|
||||
public static void SetPosition(NomaiInterfaceOrb __instance)
|
||||
{
|
||||
GlobalMessenger<int, bool>.FireEvent(EventNames.QSBOrbStatus, WorldRegistry.OldOrbList.FindIndex(x => x == __instance), false);
|
||||
}
|
||||
|
||||
public static bool SetOrbPosition(NomaiInterfaceOrb __instance)
|
||||
{
|
||||
return WorldRegistry.IsOrbControlledLocally(__instance);
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
using OWML.ModHelper.Events;
|
||||
using QSB.Events;
|
||||
using QSB.Messaging;
|
||||
using QSB.WorldSync;
|
||||
|
||||
namespace QSB.OrbSync
|
||||
{
|
||||
public class OrbStatusEvent : QSBEvent<BoolWorldObjectMessage>
|
||||
{
|
||||
public override EventType Type => EventType.OrbStatus;
|
||||
|
||||
public override void SetupListener()
|
||||
{
|
||||
GlobalMessenger<int, bool>.AddListener(EventNames.QSBOrbStatus, Handler);
|
||||
}
|
||||
|
||||
public override void CloseListener()
|
||||
{
|
||||
GlobalMessenger<int, bool>.RemoveListener(EventNames.QSBOrbStatus, Handler);
|
||||
}
|
||||
|
||||
private void Handler(int id, bool state) => SendEvent(CreateMessage(id, state));
|
||||
|
||||
private BoolWorldObjectMessage CreateMessage(int id, bool state) => new BoolWorldObjectMessage
|
||||
{
|
||||
AboutId = LocalPlayerId,
|
||||
ObjectId = id,
|
||||
State = state
|
||||
};
|
||||
|
||||
public override void OnReceiveRemote(BoolWorldObjectMessage message)
|
||||
{
|
||||
var orb = WorldRegistry.OldOrbList[message.ObjectId];
|
||||
orb.SetValue("_isBeingDragged", true);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
using QSB.Events;
|
||||
using QSB.Messaging;
|
||||
using QSB.WorldSync;
|
||||
|
||||
namespace QSB.OrbSync
|
||||
{
|
||||
public class OrbUserEvent : QSBEvent<WorldObjectMessage>
|
||||
{
|
||||
public override EventType Type => EventType.OrbUser;
|
||||
|
||||
public override void SetupListener()
|
||||
{
|
||||
GlobalMessenger<int>.AddListener(EventNames.QSBOrbUser, Handler);
|
||||
}
|
||||
|
||||
public override void CloseListener()
|
||||
{
|
||||
GlobalMessenger<int>.RemoveListener(EventNames.QSBOrbUser, Handler);
|
||||
}
|
||||
|
||||
private void Handler(int id) => SendEvent(CreateMessage(id));
|
||||
|
||||
private WorldObjectMessage CreateMessage(int id) => new WorldObjectMessage
|
||||
{
|
||||
AboutId = LocalPlayerId,
|
||||
ObjectId = id
|
||||
};
|
||||
|
||||
public override void OnReceiveRemote(WorldObjectMessage message)
|
||||
{
|
||||
WorldRegistry.OrbUserList[WorldRegistry.OldOrbList[message.ObjectId]] = message.FromId;
|
||||
}
|
||||
|
||||
public override void OnReceiveLocal(WorldObjectMessage message) => OnReceiveRemote(message);
|
||||
}
|
||||
}
|
@ -1,55 +0,0 @@
|
||||
using QSB.Events;
|
||||
using QSB.WorldSync;
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace QSB.OrbSync
|
||||
{
|
||||
public class QSBOrbSlot : WorldObject
|
||||
{
|
||||
private NomaiInterfaceSlot _interfaceSlot;
|
||||
|
||||
public void Init(NomaiInterfaceSlot slot, int id)
|
||||
{
|
||||
ObjectId = id;
|
||||
_interfaceSlot = slot;
|
||||
|
||||
_interfaceSlot.OnSlotActivated += (slotInstance) => HandleEvent(slotInstance, true);
|
||||
_interfaceSlot.OnSlotDeactivated += (slotInstance) => HandleEvent(slotInstance, false);
|
||||
}
|
||||
|
||||
private void HandleEvent(NomaiInterfaceSlot instance, bool state)
|
||||
{
|
||||
if (NetworkServer.active)
|
||||
{
|
||||
GlobalMessenger<int, bool>.FireEvent(EventNames.QSBOrbSlot, ObjectId, state);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetState(bool state)
|
||||
{
|
||||
if (state)
|
||||
{
|
||||
RaiseEvent(_interfaceSlot, "OnSlotActivated");
|
||||
}
|
||||
else
|
||||
{
|
||||
RaiseEvent(_interfaceSlot, "OnSlotDeactivated");
|
||||
}
|
||||
}
|
||||
|
||||
private static void RaiseEvent(object instance, string eventName)
|
||||
{
|
||||
var type = instance.GetType();
|
||||
var staticFlags = BindingFlags.Instance | BindingFlags.NonPublic;
|
||||
var fieldInfo = type.GetField(eventName, staticFlags);
|
||||
var multDelegate = fieldInfo.GetValue(instance) as MulticastDelegate;
|
||||
var delegateList = multDelegate.GetInvocationList();
|
||||
foreach (var delegateMethod in delegateList)
|
||||
{
|
||||
delegateMethod.DynamicInvoke(instance);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -3,7 +3,6 @@ using OWML.ModHelper;
|
||||
using QSB.DeathSync;
|
||||
using QSB.ElevatorSync;
|
||||
using QSB.GeyserSync;
|
||||
using QSB.OrbSync;
|
||||
using QSB.Tools;
|
||||
using QSB.TransformSync;
|
||||
using QSB.Utility;
|
||||
@ -44,7 +43,6 @@ namespace QSB
|
||||
gameObject.AddComponent<DebugActions>();
|
||||
gameObject.AddComponent<ElevatorManager>();
|
||||
gameObject.AddComponent<GeyserManager>();
|
||||
gameObject.AddComponent<OrbSlotManager>();
|
||||
gameObject.AddComponent<QSBSectorManager>();
|
||||
}
|
||||
|
||||
|
@ -136,12 +136,6 @@
|
||||
<Compile Include="Events\EventNames.cs" />
|
||||
<Compile Include="DeathSync\PlayerDeathEvent.cs" />
|
||||
<Compile Include="Events\IQSBEvent.cs" />
|
||||
<Compile Include="OrbSync\OrbSlotManager.cs" />
|
||||
<Compile Include="OrbSync\OrbSlotEvent.cs" />
|
||||
<Compile Include="OrbSync\OrbSlotPatches.cs" />
|
||||
<Compile Include="OrbSync\OrbStatusEvent.cs" />
|
||||
<Compile Include="OrbSync\OrbUserEvent.cs" />
|
||||
<Compile Include="OrbSync\QSBOrbSlot.cs" />
|
||||
<Compile Include="PlayerSyncObject.cs" />
|
||||
<Compile Include="QSBNetworkLobby.cs" />
|
||||
<Compile Include="QSBSceneManager.cs" />
|
||||
@ -151,7 +145,6 @@
|
||||
<Compile Include="Events\PlayerLeaveEvent.cs" />
|
||||
<Compile Include="Tools\PlayerProbeEvent.cs" />
|
||||
<Compile Include="Events\PlayerReadyEvent.cs" />
|
||||
<Compile Include="TransformSync\NomaiOrbTransformSync.cs" />
|
||||
<Compile Include="TransformSync\PlayerSectorEvent.cs" />
|
||||
<Compile Include="Events\PlayerStatesRequestEvent.cs" />
|
||||
<Compile Include="Animation\PlayerSuitEvent.cs" />
|
||||
|
@ -3,7 +3,6 @@ using QSB.Animation;
|
||||
using QSB.DeathSync;
|
||||
using QSB.Events;
|
||||
using QSB.GeyserSync;
|
||||
using QSB.OrbSync;
|
||||
using QSB.TimeSync;
|
||||
using QSB.TransformSync;
|
||||
using QSB.Utility;
|
||||
@ -29,7 +28,6 @@ namespace QSB
|
||||
private GameObject _shipPrefab;
|
||||
private GameObject _cameraPrefab;
|
||||
private GameObject _probePrefab;
|
||||
public GameObject OrbPrefab;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
@ -59,30 +57,7 @@ namespace QSB
|
||||
spawnPrefabs.Add(_probePrefab);
|
||||
DebugLog.LogState("ProbePrefab", _probePrefab);
|
||||
|
||||
OrbPrefab = _assetBundle.LoadAsset<GameObject>("assets/networkorb.prefab");
|
||||
OrbPrefab.AddComponent<NomaiOrbTransformSync>();
|
||||
spawnPrefabs.Add(OrbPrefab);
|
||||
DebugLog.LogState("OrbPrefab", OrbPrefab);
|
||||
|
||||
ConfigureNetworkManager();
|
||||
QSBSceneManager.OnSceneLoaded += OnSceneLoaded;
|
||||
}
|
||||
|
||||
private void OnSceneLoaded(OWScene scene, bool inUniverse)
|
||||
{
|
||||
WorldRegistry.OldOrbList = Resources.FindObjectsOfTypeAll<NomaiInterfaceOrb>().ToList();
|
||||
foreach (var orb in WorldRegistry.OldOrbList)
|
||||
{
|
||||
if (NetworkServer.active)
|
||||
{
|
||||
WorldRegistry.OrbUserList.Add(orb, PlayerRegistry.LocalPlayerId);
|
||||
NetworkServer.Spawn(Instantiate(OrbPrefab));
|
||||
}
|
||||
else
|
||||
{
|
||||
WorldRegistry.OrbUserList.Add(orb, NetworkInstanceId.Invalid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ConfigureNetworkManager()
|
||||
@ -122,22 +97,14 @@ namespace QSB
|
||||
{
|
||||
gameObject.AddComponent<Events.PlayerState>();
|
||||
GeyserManager.Instance.EmptyUpdate();
|
||||
OrbSlotManager.Instance.StopChecking();
|
||||
WakeUpPatches.AddPatches();
|
||||
}
|
||||
|
||||
//QSB.Helper.HarmonyHelper.AddPostfix<NomaiInterfaceOrb>("StartDragFromPosition", typeof(OrbSlotPatches), nameof(OrbSlotPatches.StartDragCallEvent));
|
||||
//QSB.Helper.HarmonyHelper.AddPostfix<NomaiInterfaceOrb>("CancelDrag", typeof(OrbSlotPatches), nameof(OrbSlotPatches.CancelDrag));
|
||||
//QSB.Helper.HarmonyHelper.AddPostfix<NomaiInterfaceOrb>("SetOrbPosition", typeof(OrbSlotPatches), nameof(OrbSlotPatches.SetPosition));
|
||||
//QSB.Helper.HarmonyHelper.AddPrefix<NomaiInterfaceOrb>("SetOrbPosition", typeof(OrbSlotPatches), nameof(OrbSlotPatches.SetOrbPosition));
|
||||
|
||||
_lobby.CanEditName = false;
|
||||
|
||||
OnNetworkManagerReady?.Invoke();
|
||||
IsReady = true;
|
||||
|
||||
//NetworkServer.RegisterHandler((short)Messaging.EventType.QSBPositionMessage + MsgType.Highest + 1, new NetworkMessageDelegate(QSBTransformSync.HandleTransform));
|
||||
|
||||
QSB.Helper.Events.Unity.RunWhen(() => PlayerTransformSync.LocalInstance != null, EventList.Init);
|
||||
|
||||
QSB.Helper.Events.Unity.RunWhen(() => EventList.Ready,
|
||||
|
@ -1,81 +0,0 @@
|
||||
using QSB.WorldSync;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace QSB.TransformSync
|
||||
{
|
||||
public class NomaiOrbTransformSync : NetworkBehaviour
|
||||
{
|
||||
private NomaiInterfaceOrb _attachedOrb;
|
||||
private int Index => WorldRegistry.OrbList.FindIndex(x => x == this);
|
||||
|
||||
public Transform SyncedTransform { get; private set; }
|
||||
private bool _isInitialized;
|
||||
private bool _isReady;
|
||||
private Transform ReferenceTransform;
|
||||
private Vector3 _positionSmoothVelocity;
|
||||
private const float SmoothTime = 0.1f;
|
||||
|
||||
public override void OnStartClient()
|
||||
{
|
||||
WorldRegistry.OrbList.Add(this);
|
||||
|
||||
QSB.Helper.Events.Unity.RunWhen(() => WorldRegistry.OldOrbList.Count != 0, OnReady);
|
||||
}
|
||||
|
||||
private void OnReady()
|
||||
{
|
||||
_attachedOrb = WorldRegistry.OldOrbList[Index];
|
||||
_isReady = true;
|
||||
}
|
||||
|
||||
void Awake()
|
||||
{
|
||||
DontDestroyOnLoad(this);
|
||||
QSBSceneManager.OnSceneLoaded += OnSceneLoaded;
|
||||
}
|
||||
|
||||
private void OnSceneLoaded(OWScene scene, bool isInUniverse)
|
||||
{
|
||||
_isInitialized = false;
|
||||
}
|
||||
|
||||
protected void Init()
|
||||
{
|
||||
SyncedTransform = _attachedOrb.transform;
|
||||
ReferenceTransform = _attachedOrb.GetAttachedOWRigidbody().GetOrigParent();
|
||||
_isInitialized = true;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (!_isInitialized && _isReady)
|
||||
{
|
||||
Init();
|
||||
}
|
||||
else if (_isInitialized && !_isReady)
|
||||
{
|
||||
_isInitialized = false;
|
||||
}
|
||||
|
||||
if (SyncedTransform == null || !_isInitialized)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
UpdateTransform();
|
||||
}
|
||||
|
||||
protected virtual void UpdateTransform()
|
||||
{
|
||||
if (isServer)
|
||||
{
|
||||
transform.position = ReferenceTransform.InverseTransformPoint(SyncedTransform.position);
|
||||
transform.rotation = ReferenceTransform.InverseTransformRotation(SyncedTransform.rotation);
|
||||
return;
|
||||
}
|
||||
SyncedTransform.position = Vector3.SmoothDamp(SyncedTransform.position, ReferenceTransform.TransformPoint(transform.position), ref _positionSmoothVelocity, SmoothTime);
|
||||
SyncedTransform.rotation = ReferenceTransform.rotation;
|
||||
}
|
||||
}
|
||||
}
|
@ -8,9 +8,6 @@ namespace QSB.WorldSync
|
||||
public static class WorldRegistry
|
||||
{
|
||||
private static readonly List<WorldObject> _worldObjects = new List<WorldObject>();
|
||||
public static List<NomaiOrbTransformSync> OrbList = new List<NomaiOrbTransformSync>();
|
||||
public static List<NomaiInterfaceOrb> OldOrbList = new List<NomaiInterfaceOrb>();
|
||||
public static Dictionary<NomaiInterfaceOrb, NetworkInstanceId> OrbUserList = new Dictionary<NomaiInterfaceOrb, NetworkInstanceId>();
|
||||
|
||||
public static void AddObject(WorldObject worldObject)
|
||||
{
|
||||
@ -30,10 +27,5 @@ namespace QSB.WorldSync
|
||||
{
|
||||
return GetObjects<T>().FirstOrDefault(x => x.ObjectId == id);
|
||||
}
|
||||
|
||||
public static bool IsOrbControlledLocally(NomaiInterfaceOrb orb)
|
||||
{
|
||||
return OrbUserList[orb] == PlayerRegistry.LocalPlayerId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user