mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-03-13 07:14:19 +00:00
Merge pull request #303 from ShoosGun/master
Cleaning and moving stuff to Utility
This commit is contained in:
commit
3607af96ed
@ -1,4 +1,5 @@
|
||||
using QSB.WorldSync;
|
||||
using QSB.Utility;
|
||||
using QSB.WorldSync;
|
||||
using UnityEngine;
|
||||
|
||||
namespace QSB.Animation.NPC.WorldObjects
|
||||
@ -15,10 +16,10 @@ namespace QSB.Animation.NPC.WorldObjects
|
||||
public abstract CharacterDialogueTree GetDialogueTree();
|
||||
|
||||
public virtual void StartConversation()
|
||||
=> QSBWorldSync.RaiseEvent(GetDialogueTree(), "OnStartConversation");
|
||||
=> GetDialogueTree().RaiseEvent("OnStartConversation");
|
||||
|
||||
public virtual void EndConversation()
|
||||
=> QSBWorldSync.RaiseEvent(GetDialogueTree(), "OnEndConversation");
|
||||
=> GetDialogueTree().RaiseEvent("OnEndConversation");
|
||||
|
||||
public abstract bool InConversation();
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
using QSB.Events;
|
||||
using QSB.Patches;
|
||||
using QSB.Player;
|
||||
using QSB.WorldSync;
|
||||
using QSB.Utility;
|
||||
using UnityEngine;
|
||||
|
||||
namespace QSB.Animation.Patches
|
||||
@ -91,24 +91,24 @@ namespace QSB.Animation.Patches
|
||||
if (!____leftFootGrounded && leftFootLift < 0.333f)
|
||||
{
|
||||
____leftFootGrounded = true;
|
||||
QSBWorldSync.RaiseEvent(__instance, "OnLeftFootGrounded");
|
||||
__instance.RaiseEvent("OnLeftFootGrounded");
|
||||
}
|
||||
else if (____leftFootGrounded && leftFootLift > 0.666f)
|
||||
{
|
||||
____leftFootGrounded = false;
|
||||
QSBWorldSync.RaiseEvent(__instance, "OnLeftFootLift");
|
||||
__instance.RaiseEvent("OnLeftFootLift");
|
||||
}
|
||||
|
||||
var rightFootLift = ____animator.GetFloat("RightFootLift");
|
||||
if (!____rightFootGrounded && rightFootLift < 0.333f)
|
||||
{
|
||||
____rightFootGrounded = true;
|
||||
QSBWorldSync.RaiseEvent(__instance, "OnRightFootGrounded");
|
||||
__instance.RaiseEvent("OnRightFootGrounded");
|
||||
}
|
||||
else if (____rightFootGrounded && rightFootLift > 0.666f)
|
||||
{
|
||||
____rightFootGrounded = false;
|
||||
QSBWorldSync.RaiseEvent(__instance, "OnRightFootLift");
|
||||
__instance.RaiseEvent("OnRightFootLift");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
using QSB.Events;
|
||||
using QSB.Patches;
|
||||
using QSB.Utility;
|
||||
using QSB.WorldSync;
|
||||
using UnityEngine;
|
||||
|
||||
@ -34,7 +35,7 @@ namespace QSB.OrbSync.Patches
|
||||
if (Time.timeSinceLevelLoad > 1f)
|
||||
{
|
||||
QSBWorldSync.HandleSlotStateChange(__instance, orb, true);
|
||||
QSBWorldSync.RaiseEvent(__instance, "OnSlotActivated", __instance);
|
||||
__instance.RaiseEvent("OnSlotActivated", __instance);
|
||||
}
|
||||
|
||||
__result = true;
|
||||
@ -51,7 +52,7 @@ namespace QSB.OrbSync.Patches
|
||||
{
|
||||
QSBWorldSync.HandleSlotStateChange(__instance, orb, false);
|
||||
____occupyingOrb = null;
|
||||
QSBWorldSync.RaiseEvent(__instance, "OnSlotDeactivated", __instance);
|
||||
__instance.RaiseEvent("OnSlotDeactivated", __instance);
|
||||
__result = false;
|
||||
return false;
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
using OWML.Utils;
|
||||
using QSB.Events;
|
||||
using QSB.Utility;
|
||||
using QSB.WorldSync;
|
||||
|
||||
namespace QSB.OrbSync.WorldObjects
|
||||
@ -37,7 +38,7 @@ namespace QSB.OrbSync.WorldObjects
|
||||
var occOrb = state ? QSBWorldSync.OldOrbList[orbId] : null;
|
||||
AttachedObject.SetValue("_occupyingOrb", occOrb);
|
||||
var ev = state ? "OnSlotActivated" : "OnSlotDeactivated";
|
||||
QSBWorldSync.RaiseEvent(AttachedObject, ev, AttachedObject);
|
||||
AttachedObject.RaiseEvent(ev, AttachedObject);
|
||||
Activated = state;
|
||||
}
|
||||
}
|
||||
|
@ -36,40 +36,28 @@ namespace QSB.Player.Events
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO : CLEAN. THIS. SHIT.
|
||||
QSBWorldSync.DialogueConditions.ForEach(condition
|
||||
=> QSBEventManager.FireEvent(EventNames.DialogueCondition, condition.Key, condition.Value));
|
||||
|
||||
foreach (var condition in QSBWorldSync.DialogueConditions)
|
||||
{
|
||||
QSBEventManager.FireEvent(EventNames.DialogueCondition, condition.Key, condition.Value);
|
||||
}
|
||||
|
||||
foreach (var fact in QSBWorldSync.ShipLogFacts)
|
||||
{
|
||||
QSBEventManager.FireEvent(EventNames.QSBRevealFact, fact.Id, fact.SaveGame, false);
|
||||
}
|
||||
QSBWorldSync.ShipLogFacts.ForEach(fact
|
||||
=> QSBEventManager.FireEvent(EventNames.QSBRevealFact, fact.Id, fact.SaveGame, false));
|
||||
|
||||
foreach (var wallText in QSBWorldSync.GetWorldObjects<QSBWallText>().Where(x => x.AttachedObject.GetValue<bool>("_initialized") && x.AttachedObject.GetNumTextBlocks() > 0))
|
||||
{
|
||||
foreach (var id in wallText.GetTranslatedIds())
|
||||
{
|
||||
QSBEventManager.FireEvent(EventNames.QSBTextTranslated, NomaiTextType.WallText, wallText.ObjectId, id);
|
||||
}
|
||||
wallText.GetTranslatedIds().ForEach(id
|
||||
=> QSBEventManager.FireEvent(EventNames.QSBTextTranslated, NomaiTextType.WallText, wallText.ObjectId, id));
|
||||
}
|
||||
|
||||
foreach (var computer in QSBWorldSync.GetWorldObjects<QSBComputer>().Where(x => x.AttachedObject.GetValue<bool>("_initialized") && x.AttachedObject.GetNumTextBlocks() > 0))
|
||||
{
|
||||
foreach (var id in computer.GetTranslatedIds())
|
||||
{
|
||||
QSBEventManager.FireEvent(EventNames.QSBTextTranslated, NomaiTextType.Computer, computer.ObjectId, id);
|
||||
}
|
||||
computer.GetTranslatedIds().ForEach(id
|
||||
=> QSBEventManager.FireEvent(EventNames.QSBTextTranslated, NomaiTextType.Computer, computer.ObjectId, id));
|
||||
}
|
||||
|
||||
foreach (var vesselComputer in QSBWorldSync.GetWorldObjects<QSBVesselComputer>().Where(x => x.AttachedObject.GetValue<bool>("_initialized") && x.AttachedObject.GetNumTextBlocks() > 0))
|
||||
{
|
||||
foreach (var id in vesselComputer.GetTranslatedIds())
|
||||
{
|
||||
QSBEventManager.FireEvent(EventNames.QSBTextTranslated, NomaiTextType.VesselComputer, vesselComputer.ObjectId, id);
|
||||
}
|
||||
vesselComputer.GetTranslatedIds().ForEach(id
|
||||
=> QSBEventManager.FireEvent(EventNames.QSBTextTranslated, NomaiTextType.VesselComputer, vesselComputer.ObjectId, id));
|
||||
}
|
||||
|
||||
var list = QSBWorldSync.GetWorldObjects<IQSBQuantumObject>().ToList();
|
||||
@ -78,10 +66,8 @@ namespace QSB.Player.Events
|
||||
QSBEventManager.FireEvent(EventNames.QSBQuantumAuthority, i, list[i].ControllingPlayer);
|
||||
}
|
||||
|
||||
foreach (var campfire in QSBWorldSync.GetWorldObjects<QSBCampfire>())
|
||||
{
|
||||
QSBEventManager.FireEvent(EventNames.QSBCampfireState, campfire.ObjectId, campfire.GetState());
|
||||
}
|
||||
QSBWorldSync.GetWorldObjects<QSBCampfire>().ForEach(campfire
|
||||
=> QSBEventManager.FireEvent(EventNames.QSBCampfireState, campfire.ObjectId, campfire.GetState()));
|
||||
}
|
||||
}
|
||||
}
|
@ -8,10 +8,10 @@ namespace QSB.ProbeSync.Events
|
||||
{
|
||||
public override EventType Type => EventType.ProbeEvent;
|
||||
|
||||
public override void SetupListener()
|
||||
public override void SetupListener()
|
||||
=> GlobalMessenger<ProbeEvent>.AddListener(EventNames.QSBProbeEvent, Handler);
|
||||
|
||||
public override void CloseListener()
|
||||
public override void CloseListener()
|
||||
=> GlobalMessenger<ProbeEvent>.RemoveListener(EventNames.QSBProbeEvent, Handler);
|
||||
|
||||
private void Handler(ProbeEvent probeEvent) => SendEvent(CreateMessage(probeEvent));
|
||||
|
@ -8,10 +8,10 @@ namespace QSB.ProbeSync.Events
|
||||
{
|
||||
public override EventType Type => EventType.ProbeStartRetrieve;
|
||||
|
||||
public override void SetupListener()
|
||||
public override void SetupListener()
|
||||
=> GlobalMessenger<float>.AddListener(EventNames.QSBProbeStartRetrieve, Handler);
|
||||
|
||||
public override void CloseListener()
|
||||
public override void CloseListener()
|
||||
=> GlobalMessenger<float>.RemoveListener(EventNames.QSBProbeStartRetrieve, Handler);
|
||||
|
||||
private void Handler(float duration) => SendEvent(CreateMessage(duration));
|
||||
|
@ -59,10 +59,10 @@ namespace QSB.ProbeSync
|
||||
Deactivate();
|
||||
}
|
||||
|
||||
public bool IsRetrieving()
|
||||
public bool IsRetrieving()
|
||||
=> IsLaunched() && _isRetrieving;
|
||||
|
||||
public bool IsLaunched()
|
||||
public bool IsLaunched()
|
||||
=> gameObject.activeSelf;
|
||||
|
||||
public void HandleEvent(ProbeEvent probeEvent)
|
||||
|
@ -60,7 +60,6 @@ namespace QSB
|
||||
playerPrefab.AddComponent<JetpackAccelerationSync>();
|
||||
playerPrefab.AddComponent<InstrumentsManager>();
|
||||
|
||||
|
||||
ShipPrefab = _assetBundle.LoadAsset<GameObject>("assets/networkship.prefab");
|
||||
SetupNetworkId(ShipPrefab);
|
||||
SetupNetworkTransform(ShipPrefab);
|
||||
|
@ -1,6 +1,6 @@
|
||||
using QSB.Patches;
|
||||
using QSB.Player;
|
||||
using QSB.WorldSync;
|
||||
using QSB.Utility;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
@ -22,10 +22,10 @@ namespace QSB.QuantumSync.Patches
|
||||
}
|
||||
|
||||
public static void Shape_OnEnable(Shape __instance)
|
||||
=> QSBWorldSync.RaiseEvent(__instance, "OnShapeActivated", __instance);
|
||||
=> __instance.RaiseEvent("OnShapeActivated", __instance);
|
||||
|
||||
public static void Shape_OnDisable(Shape __instance)
|
||||
=> QSBWorldSync.RaiseEvent(__instance, "OnShapeDeactivated", __instance);
|
||||
=> __instance.RaiseEvent("OnShapeDeactivated", __instance);
|
||||
|
||||
// ShapeVisibilityTracker patches
|
||||
|
||||
|
@ -2,7 +2,6 @@
|
||||
using QSB.Events;
|
||||
using QSB.Patches;
|
||||
using QSB.Utility;
|
||||
using QSB.WorldSync;
|
||||
using UnityEngine;
|
||||
|
||||
namespace QSB.ShipSync.Patches
|
||||
@ -116,7 +115,7 @@ namespace QSB.ShipSync.Patches
|
||||
____damaged = true;
|
||||
____repairFraction = 0f;
|
||||
__instance.GetType().GetAnyMethod("OnComponentDamaged").Invoke(__instance, null);
|
||||
QSBWorldSync.RaiseEvent(__instance, "OnDamaged", __instance);
|
||||
__instance.RaiseEvent("OnDamaged", __instance);
|
||||
QSBEventManager.FireEvent(EventNames.QSBComponentDamaged, __instance);
|
||||
}
|
||||
else
|
||||
@ -124,7 +123,7 @@ namespace QSB.ShipSync.Patches
|
||||
____damaged = false;
|
||||
____repairFraction = 1f;
|
||||
__instance.GetType().GetAnyMethod("OnComponentRepaired").Invoke(__instance, null);
|
||||
QSBWorldSync.RaiseEvent(__instance, "OnRepaired", __instance);
|
||||
__instance.RaiseEvent("OnRepaired", __instance);
|
||||
QSBEventManager.FireEvent(EventNames.QSBComponentRepaired, __instance);
|
||||
}
|
||||
|
||||
@ -154,7 +153,7 @@ namespace QSB.ShipSync.Patches
|
||||
if (!____damaged)
|
||||
{
|
||||
____damaged = true;
|
||||
QSBWorldSync.RaiseEvent(__instance, "OnDamaged", __instance);
|
||||
__instance.RaiseEvent("OnDamaged", __instance);
|
||||
QSBEventManager.FireEvent(EventNames.QSBHullDamaged, __instance);
|
||||
}
|
||||
|
||||
@ -177,7 +176,7 @@ namespace QSB.ShipSync.Patches
|
||||
}
|
||||
}
|
||||
|
||||
QSBWorldSync.RaiseEvent(__instance, "OnImpact", ____dominantImpact, damage);
|
||||
__instance.RaiseEvent("OnImpact", ____dominantImpact, damage);
|
||||
QSBEventManager.FireEvent(EventNames.QSBHullImpact, __instance, ____dominantImpact, damage);
|
||||
|
||||
____dominantImpact = null;
|
||||
@ -209,7 +208,7 @@ namespace QSB.ShipSync.Patches
|
||||
if (____integrity >= 1f)
|
||||
{
|
||||
____damaged = false;
|
||||
QSBWorldSync.RaiseEvent(__instance, "OnRepaired", __instance);
|
||||
__instance.RaiseEvent("OnRepaired", __instance);
|
||||
QSBEventManager.FireEvent(EventNames.QSBHullRepaired, __instance);
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,7 @@ namespace QSB.ShipSync.WorldObjects
|
||||
AttachedObject.SetValue("_damaged", true);
|
||||
AttachedObject.SetValue("_repairFraction", 0f);
|
||||
AttachedObject.GetType().GetAnyMethod("OnComponentDamaged").Invoke(AttachedObject, null);
|
||||
QSBWorldSync.RaiseEvent(AttachedObject, "OnDamaged", AttachedObject);
|
||||
AttachedObject.RaiseEvent("OnDamaged", AttachedObject);
|
||||
AttachedObject.GetType().GetAnyMethod("UpdateColliderState").Invoke(AttachedObject, null);
|
||||
var damageEffect = AttachedObject.GetValue<DamageEffect>("_damageEffect");
|
||||
damageEffect.SetEffectBlend(1f);
|
||||
@ -30,7 +30,7 @@ namespace QSB.ShipSync.WorldObjects
|
||||
AttachedObject.SetValue("_damaged", false);
|
||||
AttachedObject.SetValue("_repairFraction", 1f);
|
||||
AttachedObject.GetType().GetAnyMethod("OnComponentRepaired").Invoke(AttachedObject, null);
|
||||
QSBWorldSync.RaiseEvent(AttachedObject, "OnRepaired", AttachedObject);
|
||||
AttachedObject.RaiseEvent("OnRepaired", AttachedObject);
|
||||
AttachedObject.GetType().GetAnyMethod("UpdateColliderState").Invoke(AttachedObject, null);
|
||||
var damageEffect = AttachedObject.GetValue<DamageEffect>("_damageEffect");
|
||||
damageEffect.SetEffectBlend(0f);
|
||||
|
@ -16,14 +16,14 @@ namespace QSB.ShipSync.WorldObjects
|
||||
{
|
||||
DebugLog.DebugWrite($"[HULL] {AttachedObject} Set damaged.");
|
||||
AttachedObject.SetValue("_damaged", true);
|
||||
QSBWorldSync.RaiseEvent(AttachedObject, "OnDamaged", AttachedObject);
|
||||
AttachedObject.RaiseEvent("OnDamaged", AttachedObject);
|
||||
}
|
||||
|
||||
public void SetRepaired()
|
||||
{
|
||||
DebugLog.DebugWrite($"[HULL] {AttachedObject} Set repaired.");
|
||||
AttachedObject.SetValue("_damaged", false);
|
||||
QSBWorldSync.RaiseEvent(AttachedObject, "OnRepaired", AttachedObject);
|
||||
AttachedObject.RaiseEvent("OnRepaired", AttachedObject);
|
||||
var damageEffect = AttachedObject.GetValue<DamageEffect>("_damageEffect");
|
||||
damageEffect.SetEffectBlend(0f);
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ namespace QSB.Syncs.TransformSync
|
||||
private readonly static Dictionary<PlayerInfo, Dictionary<Type, BaseTransformSync>> _storedTransformSyncs = new Dictionary<PlayerInfo, Dictionary<Type, BaseTransformSync>>();
|
||||
|
||||
public static T GetPlayers<T>(PlayerInfo player)
|
||||
where T : BaseTransformSync
|
||||
where T : BaseTransformSync
|
||||
{
|
||||
var dictOfOwnedSyncs = _storedTransformSyncs[player];
|
||||
var wantedSync = dictOfOwnedSyncs[typeof(T)];
|
||||
|
@ -1,10 +1,8 @@
|
||||
using OWML.Utils;
|
||||
using QSB.SectorSync;
|
||||
using QSB.SectorSync;
|
||||
using QSB.SectorSync.WorldObjects;
|
||||
using QSB.Utility;
|
||||
using QSB.WorldSync;
|
||||
using QuantumUNET.Transport;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
namespace QSB.Syncs.TransformSync
|
||||
@ -96,6 +94,7 @@ namespace QSB.Syncs.TransformSync
|
||||
base.DeserializeTransform(reader);
|
||||
return;
|
||||
}
|
||||
|
||||
DebugLog.DebugWrite($"DESERAILIZE new sector ({(ReferenceSector == null ? "NULL" : ReferenceSector.Name)} to {sector.Name})");
|
||||
SetReferenceSector(sector);
|
||||
}
|
||||
|
@ -1,12 +1,7 @@
|
||||
using QSB.Player;
|
||||
using QSB.Player.TransformSync;
|
||||
using QSB.ProbeSync.TransformSync;
|
||||
using QSB.QuantumSync;
|
||||
using QSB.ShipSync;
|
||||
using QSB.ShipSync.TransformSync;
|
||||
using QSB.Syncs.TransformSync;
|
||||
using QSB.TimeSync;
|
||||
using QSB.WorldSync;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
|
@ -3,6 +3,7 @@ using OWML.Utils;
|
||||
using QSB.Player.TransformSync;
|
||||
using QuantumUNET;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
|
||||
@ -90,6 +91,32 @@ namespace QSB.Utility
|
||||
public static float Map(this float value, float inputFrom, float inputTo, float outputFrom, float outputTo)
|
||||
=> ((value - inputFrom) / (inputTo - inputFrom) * (outputTo - outputFrom)) + outputFrom;
|
||||
|
||||
public static void ForEach<T>(this System.Collections.Generic.IEnumerable<T> enumerable, Action<T> action)
|
||||
{
|
||||
foreach (var item in enumerable)
|
||||
{
|
||||
action(item);
|
||||
}
|
||||
}
|
||||
|
||||
private const BindingFlags Flags = BindingFlags.Instance
|
||||
| BindingFlags.Static
|
||||
| BindingFlags.Public
|
||||
| BindingFlags.NonPublic
|
||||
| BindingFlags.DeclaredOnly;
|
||||
|
||||
public static void RaiseEvent<T>(this T instance, string eventName, params object[] args)
|
||||
{
|
||||
if (!(typeof(T)
|
||||
.GetField(eventName, Flags)?
|
||||
.GetValue(instance) is MulticastDelegate multiDelegate))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
multiDelegate.GetInvocationList().ToList().ForEach(dl => dl.DynamicInvoke(args));
|
||||
}
|
||||
|
||||
public static void CallBase<ThisType, BaseType>(this ThisType obj, string methodName)
|
||||
where ThisType : BaseType
|
||||
{
|
||||
|
@ -6,7 +6,6 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
|
||||
namespace QSB.WorldSync
|
||||
@ -19,11 +18,6 @@ namespace QSB.WorldSync
|
||||
public static List<FactReveal> ShipLogFacts { get; } = new List<FactReveal>();
|
||||
|
||||
private static readonly List<IWorldObject> WorldObjects = new List<IWorldObject>();
|
||||
private const BindingFlags Flags = BindingFlags.Instance
|
||||
| BindingFlags.Static
|
||||
| BindingFlags.Public
|
||||
| BindingFlags.NonPublic
|
||||
| BindingFlags.DeclaredOnly;
|
||||
private static readonly Dictionary<MonoBehaviour, IWorldObject> WorldObjectsToUnityObjects = new Dictionary<MonoBehaviour, IWorldObject>();
|
||||
|
||||
public static IEnumerable<TWorldObject> GetWorldObjects<TWorldObject>()
|
||||
@ -125,22 +119,6 @@ namespace QSB.WorldSync
|
||||
return worldObject;
|
||||
}
|
||||
|
||||
public static void RaiseEvent<T>(T instance, string eventName, params object[] args) // TODO : move this to qsb.utility
|
||||
{
|
||||
if (!(typeof(T)
|
||||
.GetField(eventName, Flags)?
|
||||
.GetValue(instance) is MulticastDelegate multiDelegate))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var delegateList = multiDelegate.GetInvocationList().ToList();
|
||||
foreach (var del in delegateList)
|
||||
{
|
||||
del.DynamicInvoke(args);
|
||||
}
|
||||
}
|
||||
|
||||
public static void HandleSlotStateChange(NomaiInterfaceSlot slot, NomaiInterfaceOrb affectingOrb, bool state)
|
||||
{
|
||||
var slotList = GetWorldObjects<QSBOrbSlot>().ToList();
|
||||
|
@ -215,7 +215,7 @@ namespace QuantumUNET.Components
|
||||
_targetSyncPosition = reader.ReadVector3();
|
||||
_targetSyncRotation3D = QNetworkTransform.DeserializeRotation(reader);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool HasMoved()
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user