mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-02-13 21:40:50 +00:00
add tracker back
This commit is contained in:
parent
38a1bad9bf
commit
82e8c1fdc0
@ -210,6 +210,7 @@
|
||||
<Compile Include="Utility\DebugBoxManager.cs" />
|
||||
<Compile Include="Utility\DebugZOverride.cs" />
|
||||
<Compile Include="Utility\Extensions.cs" />
|
||||
<Compile Include="Utility\OnEnableDisableTracker.cs" />
|
||||
<Compile Include="Utility\Popcron.Gizmos\Constants.cs" />
|
||||
<Compile Include="Utility\Popcron.Gizmos\Drawers\CubeDrawer.cs" />
|
||||
<Compile Include="Utility\Popcron.Gizmos\Drawer.cs" />
|
||||
|
@ -28,8 +28,8 @@ namespace QSB.QuantumSync.Patches
|
||||
QSBCore.Helper.HarmonyHelper.AddPrefix<QuantumShrine>("OnEntry", typeof(QuantumPatches), nameof(Shrine_OnEntry));
|
||||
QSBCore.Helper.HarmonyHelper.AddPrefix<QuantumShrine>("OnExit", typeof(QuantumPatches), nameof(Shrine_OnExit));
|
||||
QSBCore.Helper.HarmonyHelper.AddPrefix<QuantumMoon>("CheckPlayerFogProximity", typeof(QuantumPatches), nameof(Moon_CheckPlayerFogProximity));
|
||||
QSBCore.Helper.HarmonyHelper.AddPostfix<Shape>("OnEnable", typeof(QuantumPatches), nameof(Shape_OnEnable));
|
||||
QSBCore.Helper.HarmonyHelper.AddPostfix<Shape>("OnDisable", typeof(QuantumPatches), nameof(Shape_OnDisable));
|
||||
//QSBCore.Helper.HarmonyHelper.AddPostfix<Shape>("OnEnable", typeof(QuantumPatches), nameof(Shape_OnEnable));
|
||||
//QSBCore.Helper.HarmonyHelper.AddPostfix<Shape>("OnDisable", typeof(QuantumPatches), nameof(Shape_OnDisable));
|
||||
}
|
||||
|
||||
public override void DoUnpatches()
|
||||
@ -44,10 +44,11 @@ namespace QSB.QuantumSync.Patches
|
||||
QSBCore.Helper.HarmonyHelper.Unpatch<QuantumShrine>("OnEntry");
|
||||
QSBCore.Helper.HarmonyHelper.Unpatch<QuantumShrine>("OnExit");
|
||||
QSBCore.Helper.HarmonyHelper.Unpatch<QuantumMoon>("CheckPlayerFogProximity");
|
||||
QSBCore.Helper.HarmonyHelper.Unpatch<Shape>("OnEnable");
|
||||
QSBCore.Helper.HarmonyHelper.Unpatch<Shape>("OnDisable");
|
||||
//QSBCore.Helper.HarmonyHelper.Unpatch<Shape>("OnEnable");
|
||||
//QSBCore.Helper.HarmonyHelper.Unpatch<Shape>("OnDisable");
|
||||
}
|
||||
|
||||
/*
|
||||
private static IQSBQuantumObject GetWorldObjectFromShape(Shape shape)
|
||||
{
|
||||
var obj = QuantumManager.Instance._shapesToTrackers.FirstOrDefault(x => x.Key.Contains(shape));
|
||||
@ -99,6 +100,7 @@ namespace QSB.QuantumSync.Patches
|
||||
}
|
||||
worldObject.Disable();
|
||||
}
|
||||
*/
|
||||
|
||||
public static bool Socketed_ChangeQuantumState(SocketedQuantumObject __instance)
|
||||
=> QSBWorldSync.GetWorldObject<QSBSocketedQuantumObject, SocketedQuantumObject>(__instance).ControllingPlayer == QSBPlayerManager.LocalPlayerId;
|
||||
|
@ -16,8 +16,8 @@ namespace QSB.QuantumSync
|
||||
{
|
||||
public static QuantumManager Instance { get; private set; }
|
||||
|
||||
public Dictionary<Shape[], VisibilityTracker> _shapesToTrackers = new Dictionary<Shape[], VisibilityTracker>();
|
||||
public Dictionary<VisibilityObject, List<VisibilityTracker>> _objectToTrackers = new Dictionary<VisibilityObject, List<VisibilityTracker>>();
|
||||
//public Dictionary<Shape[], VisibilityTracker> _shapesToTrackers = new Dictionary<Shape[], VisibilityTracker>();
|
||||
//public Dictionary<VisibilityObject, List<VisibilityTracker>> _objectToTrackers = new Dictionary<VisibilityObject, List<VisibilityTracker>>();
|
||||
public QuantumShrine Shrine;
|
||||
public bool IsReady;
|
||||
|
||||
@ -40,7 +40,7 @@ namespace QSB.QuantumSync
|
||||
{
|
||||
Shrine = Resources.FindObjectsOfTypeAll<QuantumShrine>().First();
|
||||
}
|
||||
|
||||
/*
|
||||
var visibilityObjects = Resources.FindObjectsOfTypeAll<VisibilityObject>().Where(
|
||||
x => x != null
|
||||
&& x.GetValue<VisibilityTracker[]>("_visibilityTrackers") != null
|
||||
@ -79,6 +79,7 @@ namespace QSB.QuantumSync
|
||||
});
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
IsReady = true;
|
||||
}
|
||||
|
@ -4,8 +4,5 @@
|
||||
{
|
||||
uint ControllingPlayer { get; set; }
|
||||
bool IsEnabled { get; set; }
|
||||
|
||||
void Enable();
|
||||
void Disable();
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
using QSB.Events;
|
||||
using QSB.Player;
|
||||
using QSB.Utility;
|
||||
using QSB.WorldSync;
|
||||
using UnityEngine;
|
||||
|
||||
@ -11,9 +12,25 @@ namespace QSB.QuantumSync.WorldObjects
|
||||
public uint ControllingPlayer { get; set; }
|
||||
public bool IsEnabled { get; set; }
|
||||
|
||||
public override void Init(T attachedObject, int id) => ControllingPlayer = 0u;
|
||||
private OnEnableDisableTracker _tracker;
|
||||
|
||||
public void Enable()
|
||||
public override void OnRemoval()
|
||||
{
|
||||
_tracker.OnEnableEvent -= OnEnable;
|
||||
_tracker.OnDisableEvent -= OnDisable;
|
||||
Object.Destroy(_tracker);
|
||||
}
|
||||
|
||||
public override void Init(T attachedObject, int id)
|
||||
{
|
||||
_tracker = QSBCore.GameObjectInstance.AddComponent<OnEnableDisableTracker>();
|
||||
_tracker.AttachedComponent = AttachedObject;
|
||||
_tracker.OnEnableEvent += OnEnable;
|
||||
_tracker.OnDisableEvent += OnDisable;
|
||||
ControllingPlayer = 0u;
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
IsEnabled = true;
|
||||
if (!QSBCore.HasWokenUp && !QSBCore.IsServer)
|
||||
@ -30,7 +47,7 @@ namespace QSB.QuantumSync.WorldObjects
|
||||
QSBEventManager.FireEvent(EventNames.QSBQuantumAuthority, id, QSBPlayerManager.LocalPlayerId);
|
||||
}
|
||||
|
||||
public void Disable()
|
||||
private void OnDisable()
|
||||
{
|
||||
IsEnabled = false;
|
||||
if (!QSBCore.HasWokenUp && !QSBCore.IsServer)
|
||||
|
58
QSB/Utility/OnEnableDisableTracker.cs
Normal file
58
QSB/Utility/OnEnableDisableTracker.cs
Normal file
@ -0,0 +1,58 @@
|
||||
using OWML.Utils;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
namespace QSB.Utility
|
||||
{
|
||||
public class OnEnableDisableTracker : MonoBehaviour
|
||||
{
|
||||
public event Action OnEnableEvent;
|
||||
public event Action OnDisableEvent;
|
||||
|
||||
public MonoBehaviour AttachedComponent;
|
||||
|
||||
private ComponentState _wasEnabled = ComponentState.NotChecked;
|
||||
|
||||
public OnEnableDisableTracker()
|
||||
=> QSBSceneManager.OnSceneLoaded += (OWScene scene, bool inUniverse) => Destroy(this);
|
||||
|
||||
private void OnDestroy()
|
||||
=> QSBSceneManager.OnSceneLoaded -= (OWScene scene, bool inUniverse) => Destroy(this);
|
||||
|
||||
private bool GetAnyVisibilityTrackersActive()
|
||||
{
|
||||
var visibilityTrackers = AttachedComponent.GetValue<VisibilityTracker[]>("_visibilityTrackers");
|
||||
return visibilityTrackers.All(x => x.GetValue<Shape[]>("_shapes").All(y => y.enabled));
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (AttachedComponent == null)
|
||||
{
|
||||
DebugLog.ToConsole($"Attached component is null!", OWML.Common.MessageType.Error);
|
||||
return;
|
||||
}
|
||||
var state = AttachedComponent.isActiveAndEnabled && GetAnyVisibilityTrackersActive() ? ComponentState.Enabled : ComponentState.Disabled;
|
||||
if (_wasEnabled != state)
|
||||
{
|
||||
_wasEnabled = state;
|
||||
if (state == ComponentState.Enabled)
|
||||
{
|
||||
OnEnableEvent?.SafeInvoke();
|
||||
}
|
||||
else
|
||||
{
|
||||
OnDisableEvent?.SafeInvoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal enum ComponentState
|
||||
{
|
||||
NotChecked = 0,
|
||||
Enabled = 1,
|
||||
Disabled = 2
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user