diff --git a/MonkeyLoader.Resonite.Integration/MonkeyLoader.Resonite.Integration.csproj b/MonkeyLoader.Resonite.Integration/MonkeyLoader.Resonite.Integration.csproj index e7ee23a..b58947e 100644 --- a/MonkeyLoader.Resonite.Integration/MonkeyLoader.Resonite.Integration.csproj +++ b/MonkeyLoader.Resonite.Integration/MonkeyLoader.Resonite.Integration.csproj @@ -49,6 +49,10 @@ + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + all diff --git a/MonkeyLoader.Resonite.Integration/UI/BuildSyncMemberEditorEvents.cs b/MonkeyLoader.Resonite.Integration/UI/BuildSyncMemberEditorEvents.cs deleted file mode 100644 index 7517869..0000000 --- a/MonkeyLoader.Resonite.Integration/UI/BuildSyncMemberEditorEvents.cs +++ /dev/null @@ -1,75 +0,0 @@ -using FrooxEngine.UIX; -using FrooxEngine; -using System; -using MonkeyLoader.Resonite.Events; -using System.Reflection; -using Elements.Assets; -using MonkeyLoader.Events; -using System.Collections.Generic; -using MonkeyLoader.Patching; -using System.Linq; - -namespace MonkeyLoader.Resonite.UI -{ - /// - /// Represents the base class for the events fired during construction of a - /// - [DispatchableBaseEvent] - public abstract class BuildSyncMemberEditorEvent : CancelableBuildUIEvent - { - public ISyncMember Member { get; } - - public string Name { get; } - - public FieldInfo FieldInfo { get; } - - public float? LabelSize { get; } - - protected BuildSyncMemberEditorEvent(ISyncMember member, string name, FieldInfo fieldInfo, UIBuilder ui, float? labelSize) - : base(ui) - { - Member = member; - Name = name; - FieldInfo = fieldInfo; - LabelSize = labelSize; - } - } - - public sealed class BuildSyncArrayEditorEvent : BuildSyncMemberEditorEvent - { - public new ISyncArray Member { get; } - internal BuildSyncArrayEditorEvent(ISyncArray array, string name, FieldInfo fieldInfo, UIBuilder ui, float labelSize) - : base(array, name, fieldInfo, ui, labelSize) - { - Member = array; - } - } - - class TestThing : ResoniteCancelableEventHandlerMonkey - { - public override int Priority => HarmonyLib.Priority.First; - - public override bool SkipCanceled => true; - - protected override bool AppliesTo(BuildSyncArrayEditorEvent eventData) => true; - protected override IEnumerable GetFeaturePatches() => Enumerable.Empty(); - protected override void Handle(BuildSyncArrayEditorEvent eventData) - { - Logger.Info(() => "Array build event"); - } - } - - class TestThing2 : ResoniteCancelableEventHandlerMonkey - { - public override int Priority => HarmonyLib.Priority.First; - - public override bool SkipCanceled => true; - - protected override bool AppliesTo(BuildSyncMemberEditorEvent eventData) => true; - protected override IEnumerable GetFeaturePatches() => Enumerable.Empty(); - protected override void Handle(BuildSyncMemberEditorEvent eventData) - { - Logger.Info(() => "Member editor build event"); - } - } -} \ No newline at end of file diff --git a/MonkeyLoader.Resonite.Integration/UI/DefaultSyncMemberEditorBuilderHandlers.cs b/MonkeyLoader.Resonite.Integration/UI/DefaultSyncMemberEditorBuilderHandlers.cs deleted file mode 100644 index 9334a69..0000000 --- a/MonkeyLoader.Resonite.Integration/UI/DefaultSyncMemberEditorBuilderHandlers.cs +++ /dev/null @@ -1,43 +0,0 @@ -using Elements.Core; -using FrooxEngine; -using FrooxEngine.UIX; -using MonkeyLoader.Patching; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; -using System.Text; -using System.Threading.Tasks; -using System.Xml.Linq; - -namespace MonkeyLoader.Resonite.UI -{ - internal sealed class DefaultBuildSyncArrayEditorHandler - : ResoniteCancelableEventHandlerMonkey - { - public override int Priority => HarmonyLib.Priority.Normal; - - public override bool SkipCanceled => true; - - protected override bool AppliesTo(BuildSyncArrayEditorEvent eventData) => true; - - protected override IEnumerable GetFeaturePatches() => []; - - protected override void Handle(BuildSyncArrayEditorEvent eventData) - { - var ui = eventData.UI; - var array = eventData.Member; - var name = eventData.Name; - var labelSize = eventData.LabelSize!.Value; - - ui.Panel().Slot.GetComponent(); - ui.Style.MinHeight = 24f; - - Slot slot = SyncMemberEditorBuilder.GenerateMemberField(array, name, ui, labelSize); - ui.ForceNext = slot.AttachComponent(); - LocaleString text = "(arrays currently not supported)"; - ui.Text(in text); - ui.NestOut(); - } - } -} \ No newline at end of file diff --git a/MonkeyLoader.Resonite.Integration/UI/Inspectors/BuildConcreteEditorEvents.cs b/MonkeyLoader.Resonite.Integration/UI/Inspectors/BuildConcreteEditorEvents.cs new file mode 100644 index 0000000..744c2f1 --- /dev/null +++ b/MonkeyLoader.Resonite.Integration/UI/Inspectors/BuildConcreteEditorEvents.cs @@ -0,0 +1,111 @@ +using FrooxEngine.UIX; +using FrooxEngine; +using System; +using System.Reflection; +using System.Collections.Generic; +using System.Linq; + +namespace MonkeyLoader.Resonite.UI.Inspectors +{ + /// + /// Represents the event fired during construction of a for an . + /// + public sealed class BuildArrayEditorEvent : BuildMemberEditorEvent + { + /// + /// Gets the sync array that a is being constructed for. + /// + public new ISyncArray Member { get; } + + internal BuildArrayEditorEvent(ISyncArray member, string name, FieldInfo fieldInfo, UIBuilder ui, float labelSize) + : base(member, name, fieldInfo, ui, labelSize) + { + Member = member; + } + } + + /// + /// Represents the event fired during construction of a for an . + /// + public sealed class BuildBagEditorEvent : BuildMemberEditorEvent + { + /// + /// Gets the sync bag that a is being constructed for. + /// + public new ISyncBag Member { get; } + + internal BuildBagEditorEvent(ISyncBag member, string name, FieldInfo fieldInfo, UIBuilder ui) + : base(member, name, fieldInfo, ui) + { + Member = member; + } + } + + /// + /// Represents the event fired during construction of a for an . + /// + public sealed class BuildFieldEditorEvent : BuildMemberEditorEvent + { + /// + /// Gets the field that a is being constructed for. + /// + public new IField Member { get; } + + internal BuildFieldEditorEvent(IField member, string name, FieldInfo fieldInfo, UIBuilder ui, float labelSize) + : base(member, name, fieldInfo, ui, labelSize) + { + Member = member; + } + } + + /// + /// Represents the event fired during construction of a for an . + /// + public sealed class BuildListEditorEvent : BuildMemberEditorEvent + { + /// + /// Gets the sync list that a is being constructed for. + /// + public new ISyncList Member { get; } + + internal BuildListEditorEvent(ISyncList member, string name, FieldInfo fieldInfo, UIBuilder ui) + : base(member, name, fieldInfo, ui) + { + Member = member; + } + } + + /// + /// Represents the event fired during construction of a for an . + /// + public sealed class BuildObjectEditorEvent : BuildMemberEditorEvent + { + /// + /// Gets the sync object that a is being constructed for. + /// + public new SyncObject Member { get; } + + internal BuildObjectEditorEvent(SyncObject member, string name, FieldInfo fieldInfo, UIBuilder ui, float labelSize) + : base(member, name, fieldInfo, ui, labelSize) + { + Member = member; + } + } + + /// + /// Represents the event fired during construction of a for an . + /// + public sealed class BuildPlaybackEditorEvent : BuildMemberEditorEvent + { + /// + /// Gets the sync playback that a is being constructed for. + /// + public new SyncPlayback Member { get; } + + internal BuildPlaybackEditorEvent(SyncPlayback member, string name, FieldInfo fieldInfo, UIBuilder ui, float labelSize) + : base(member, name, fieldInfo, ui, labelSize) + { + Member = member; + } + } +} \ No newline at end of file diff --git a/MonkeyLoader.Resonite.Integration/UI/Inspectors/BuildMemberEditorEvent.cs b/MonkeyLoader.Resonite.Integration/UI/Inspectors/BuildMemberEditorEvent.cs new file mode 100644 index 0000000..c53e3a7 --- /dev/null +++ b/MonkeyLoader.Resonite.Integration/UI/Inspectors/BuildMemberEditorEvent.cs @@ -0,0 +1,47 @@ +using FrooxEngine.UIX; +using FrooxEngine; +using MonkeyLoader.Resonite.Events; +using System.Reflection; +using MonkeyLoader.Events; + +namespace MonkeyLoader.Resonite.UI.Inspectors +{ + /// + /// Represents the base class for the events fired during construction of a + /// + [DispatchableBaseEvent] + public abstract class BuildMemberEditorEvent : CancelableBuildUIEvent + { + /// + /// Gets the reflection data for the field that stores the Member + /// that a is being constructed for. + /// + public FieldInfo FieldInfo { get; } + + /// + /// Gets the size for the Name label + /// that should be displayed for the .
+ /// Not all member editors get passed a label size. + ///
+ public float? LabelSize { get; } + + /// + /// Gets the sync member that a is being constructed for. + /// + public ISyncMember Member { get; } + + /// + /// Gets the name that should be used for the label. + /// + public string Name { get; } + + internal BuildMemberEditorEvent(ISyncMember member, string name, FieldInfo fieldInfo, UIBuilder ui, float? labelSize = null) + : base(ui) + { + Member = member; + Name = name; + FieldInfo = fieldInfo; + LabelSize = labelSize; + } + } +} \ No newline at end of file diff --git a/MonkeyLoader.Resonite.Integration/UI/Inspectors/DefaultBuildMemberEditorHandlers.cs b/MonkeyLoader.Resonite.Integration/UI/Inspectors/DefaultBuildMemberEditorHandlers.cs new file mode 100644 index 0000000..a8246d6 --- /dev/null +++ b/MonkeyLoader.Resonite.Integration/UI/Inspectors/DefaultBuildMemberEditorHandlers.cs @@ -0,0 +1,112 @@ +using FrooxEngine; +using FrooxEngine.UIX; +using HarmonyLib; +using MonkeyLoader.Events; +using MonkeyLoader.Patching; +using System; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace MonkeyLoader.Resonite.UI.Inspectors +{ + [HarmonyPatch(typeof(SyncMemberEditorBuilder))] + [HarmonyPatchCategory(nameof(DefaultBuildMemberEditorHandlers))] + internal sealed class DefaultBuildMemberEditorHandlers : ResoniteMonkey, + ICancelableEventHandler, ICancelableEventHandler, + ICancelableEventHandler, ICancelableEventHandler, + ICancelableEventHandler, ICancelableEventHandler + { + public int Priority => HarmonyLib.Priority.Normal; + + public bool SkipCanceled => true; + + void ICancelableEventHandler.Handle(BuildArrayEditorEvent eventData) => throw new NotImplementedException(); + + public void Handle(BuildBagEditorEvent eventData) + { + BuildBag(eventData.Member, eventData.Name, eventData.FieldInfo, eventData.UI); + + eventData.Canceled = true; + } + + public void Handle(BuildListEditorEvent eventData) + { + BuildList(eventData.Member, eventData.Name, eventData.FieldInfo, eventData.UI); + + eventData.Canceled = true; + } + + public void Handle(BuildPlaybackEditorEvent eventData) + { + BuildPlayback(eventData.Member, eventData.Name, eventData.FieldInfo, eventData.UI, eventData.LabelSize!.Value); + + eventData.Canceled = true; + } + + public void Handle(BuildFieldEditorEvent eventData) + { + BuildField(eventData.Member, eventData.Name, eventData.FieldInfo, eventData.UI, eventData.LabelSize!.Value); + + eventData.Canceled = true; + } + + public void Handle(BuildObjectEditorEvent eventData) + { + BuildSyncObject(eventData.Member, eventData.Name, eventData.FieldInfo, eventData.UI, eventData.LabelSize!.Value); + + eventData.Canceled = true; + } + + protected override IEnumerable GetFeaturePatches() => []; + + protected override bool OnEngineReady() + { + Mod.RegisterEventHandler(this); + Mod.RegisterEventHandler(this); + Mod.RegisterEventHandler(this); + Mod.RegisterEventHandler(this); + Mod.RegisterEventHandler(this); + Mod.RegisterEventHandler(this); + + return base.OnEngineReady(); + } + + [HarmonyReversePatch] + [HarmonyPatch(nameof(SyncMemberEditorBuilder.BuildArray))] + private static void BuildArray(ISyncArray array, string name, FieldInfo fieldInfo, UIBuilder ui, float labelSize) + => ThrowNotImplemented(); + + [HarmonyReversePatch] + [HarmonyPatch(nameof(SyncMemberEditorBuilder.BuildBag))] + private static void BuildBag(ISyncBag bag, string name, FieldInfo fieldInfo, UIBuilder ui) + => ThrowNotImplemented(); + + [HarmonyReversePatch] + [HarmonyPatch(nameof(SyncMemberEditorBuilder.BuildField), [typeof(IField), typeof(string), typeof(FieldInfo), typeof(UIBuilder), typeof(float)])] + private static void BuildField(IField field, string name, FieldInfo fieldInfo, UIBuilder ui, float labelSize) + => ThrowNotImplemented(); + + [HarmonyReversePatch] + [HarmonyPatch(nameof(SyncMemberEditorBuilder.BuildList))] + private static void BuildList(ISyncList list, string name, FieldInfo fieldInfo, UIBuilder ui) + => ThrowNotImplemented(); + + [HarmonyReversePatch] + [HarmonyPatch(nameof(SyncMemberEditorBuilder.BuildPlayback))] + private static void BuildPlayback(SyncPlayback playback, string name, FieldInfo fieldInfo, UIBuilder ui, float labelSize) + => ThrowNotImplemented(); + + [HarmonyReversePatch] + [HarmonyPatch(nameof(SyncMemberEditorBuilder.BuildSyncObject))] + private static void BuildSyncObject(SyncObject syncObject, string name, FieldInfo fieldInfo, UIBuilder ui, float labelSize) + => ThrowNotImplemented(); + + [DoesNotReturn] + private static void ThrowNotImplemented() + => throw new NotImplementedException(); + } +} \ No newline at end of file diff --git a/MonkeyLoader.Resonite.Integration/UI/Inspectors/SyncMemberEditorBuilderInjector.cs b/MonkeyLoader.Resonite.Integration/UI/Inspectors/SyncMemberEditorBuilderInjector.cs new file mode 100644 index 0000000..76fd07a --- /dev/null +++ b/MonkeyLoader.Resonite.Integration/UI/Inspectors/SyncMemberEditorBuilderInjector.cs @@ -0,0 +1,166 @@ +using FrooxEngine; +using FrooxEngine.UIX; +using HarmonyLib; +using MonkeyLoader.Events; +using MonkeyLoader.Patching; +using System; +using System.Collections; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Reflection; + +namespace MonkeyLoader.Resonite.UI.Inspectors +{ + [HarmonyPatch(typeof(SyncMemberEditorBuilder))] + [HarmonyPatchCategory(nameof(SyncMemberEditorBuilderInjector))] + internal sealed class SyncMemberEditorBuilderInjector : ResoniteMonkey, + ICancelableEventSource, ICancelableEventSource, + ICancelableEventSource, ICancelableEventSource, + ICancelableEventSource, ICancelableEventSource + { + private static CancelableEventDispatching? _buildArrayEditor; + private static CancelableEventDispatching? _buildBagEditor; + private static CancelableEventDispatching? _buildFieldEditor; + private static CancelableEventDispatching? _buildListEditor; + private static CancelableEventDispatching? _buildObjectEditor; + private static CancelableEventDispatching? _buildPlaybackEditor; + + public override bool CanBeDisabled => true; + + /// + protected override IEnumerable GetFeaturePatches() => []; + + protected override bool OnEngineReady() + { + Mod.RegisterEventSource(this); + Mod.RegisterEventSource(this); + Mod.RegisterEventSource(this); + Mod.RegisterEventSource(this); + Mod.RegisterEventSource(this); + Mod.RegisterEventSource(this); + + return base.OnEngineReady(); + } + + [HarmonyPrefix] + [HarmonyPatch(nameof(SyncMemberEditorBuilder.BuildArray))] + private static bool BuildArrayPrefix(ISyncArray array, string name, FieldInfo fieldInfo, UIBuilder ui, float labelSize) + { + if (!Enabled) + return true; + + var eventData = new BuildArrayEditorEvent(array, name, fieldInfo, ui, labelSize); + + _buildArrayEditor?.Invoke(eventData); + + return false; + } + + [HarmonyPrefix] + [HarmonyPatch(nameof(SyncMemberEditorBuilder.BuildBag))] + private static bool BuildBagPrefix(ISyncBag bag, string name, FieldInfo fieldInfo, UIBuilder ui) + { + if (!Enabled) + return true; + + var eventData = new BuildBagEditorEvent(bag, name, fieldInfo, ui); + + _buildBagEditor?.Invoke(eventData); + + return false; + } + + [HarmonyPrefix] + [HarmonyPatch(nameof(SyncMemberEditorBuilder.BuildField), [typeof(IField), typeof(string), typeof(FieldInfo), typeof(UIBuilder), typeof(float)])] + private static bool BuildFieldPrefix(IField field, string name, FieldInfo fieldInfo, UIBuilder ui, float labelSize) + { + if (!Enabled) + return true; + + var eventData = new BuildFieldEditorEvent(field, name, fieldInfo, ui, labelSize); + + _buildFieldEditor?.Invoke(eventData); + + return false; + } + + [HarmonyPrefix] + [HarmonyPatch(nameof(SyncMemberEditorBuilder.BuildList))] + private static bool BuildListPrefix(ISyncList list, string name, FieldInfo fieldInfo, UIBuilder ui) + { + if (!Enabled) + return true; + + var eventData = new BuildListEditorEvent(list, name, fieldInfo, ui); + + _buildListEditor?.Invoke(eventData); + + return false; + } + + [HarmonyPrefix] + [HarmonyPatch(nameof(SyncMemberEditorBuilder.BuildPlayback))] + private static bool BuildPlaybackPrefix(SyncPlayback playback, string name, FieldInfo fieldInfo, UIBuilder ui, float labelSize) + { + if (!Enabled) + return true; + + var eventData = new BuildPlaybackEditorEvent(playback, name, fieldInfo, ui, labelSize); + + _buildPlaybackEditor?.Invoke(eventData); + + return false; + } + + [HarmonyPrefix] + [HarmonyPatch(nameof(SyncMemberEditorBuilder.BuildSyncObject))] + private static bool BuildSyncObjectPrefix(SyncObject syncObject, string name, FieldInfo fieldInfo, UIBuilder ui, float labelSize) + { + if (!Enabled) + return true; + + var eventData = new BuildObjectEditorEvent(syncObject, name, fieldInfo, ui, labelSize); + + _buildObjectEditor?.Invoke(eventData); + + return false; + } + + event CancelableEventDispatching? ICancelableEventSource.Dispatching + { + add => _buildArrayEditor += value; + remove => _buildArrayEditor -= value; + } + + event CancelableEventDispatching? ICancelableEventSource.Dispatching + { + add => _buildBagEditor += value; + remove => _buildBagEditor -= value; + } + + event CancelableEventDispatching? ICancelableEventSource.Dispatching + { + add => _buildPlaybackEditor += value; + remove => _buildPlaybackEditor -= value; + } + + event CancelableEventDispatching? ICancelableEventSource.Dispatching + { + add => _buildListEditor += value; + remove => _buildListEditor -= value; + } + + event CancelableEventDispatching? ICancelableEventSource.Dispatching + { + add => _buildObjectEditor += value; + remove => _buildObjectEditor -= value; + } + + event CancelableEventDispatching? ICancelableEventSource.Dispatching + { + add => _buildFieldEditor += value; + remove => _buildFieldEditor -= value; + } + } +} \ No newline at end of file diff --git a/MonkeyLoader.Resonite.Integration/UI/SyncArrayEditor.cs b/MonkeyLoader.Resonite.Integration/UI/SyncArrayEditor.cs index ee07e21..6e0f162 100644 --- a/MonkeyLoader.Resonite.Integration/UI/SyncArrayEditor.cs +++ b/MonkeyLoader.Resonite.Integration/UI/SyncArrayEditor.cs @@ -11,23 +11,54 @@ using System.Text; using System.Threading.Tasks; using EnumerableToolkit; +using MonkeyLoader.Resonite.UI.Inspectors; namespace MonkeyLoader.Resonite.UI { - [HarmonyPatchCategory(nameof(SyncArrayEditor))] - [HarmonyPatch(typeof(SyncMemberEditorBuilder), nameof(SyncMemberEditorBuilder.BuildArray))] - internal sealed class SyncArrayEditor : ResoniteMonkey + internal sealed class SyncArrayEditor : ResoniteCancelableEventHandlerMonkey { + private static readonly MethodInfo _addCurveValueProxying = AccessTools.Method(typeof(SyncArrayEditor), nameof(AddCurveValueProxying)); private static readonly MethodInfo _addLinearValueProxying = AccessTools.Method(typeof(SyncArrayEditor), nameof(AddLinearValueProxying)); private static readonly MethodInfo _addListReferenceProxying = AccessTools.Method(typeof(SyncArrayEditor), nameof(AddListReferenceProxying)); private static readonly MethodInfo _addListValueProxying = AccessTools.Method(typeof(SyncArrayEditor), nameof(AddListValueProxying)); - private static readonly MethodInfo _addCurveValueProxying = AccessTools.Method(typeof(SyncArrayEditor), nameof(AddCurveValueProxying)); private static readonly Type _iWorldElementType = typeof(IWorldElement); private static readonly Type _particleBurstType = typeof(ParticleBurst); public override bool CanBeDisabled => true; - protected override IEnumerable GetFeaturePatches() => Enumerable.Empty(); + public override int Priority => HarmonyLib.Priority.High; + public override bool SkipCanceled => true; + + protected override bool AppliesTo(BuildArrayEditorEvent eventData) => Enabled; + + protected override IEnumerable GetFeaturePatches() => []; + + protected override void Handle(BuildArrayEditorEvent eventData) + => eventData.Canceled = BuildArray(eventData.Member, eventData.Name, eventData.FieldInfo, eventData.UI, eventData.LabelSize!.Value); + + private static void AddCurveValueProxying(SyncArray> array, SyncElementList.Point> list) + where T : IEquatable + { + foreach (var key in array) + { + var point = list.Add(); + point.Position.Value = key.time; + point.Value.Value = key.value; + } + + AddUpdateProxies(array, list, list.Elements); + + list.ElementsAdded += (list, startIndex, count) => + { + var addedElements = list.Elements.Skip(startIndex).Take(count).ToArray(); + var buffer = addedElements.Select(point => new CurveKey(point.Position, point.Value)).ToArray(); + + array.Insert(buffer, startIndex); + AddUpdateProxies(array, list, addedElements); + }; + + list.ElementsRemoved += (list, startIndex, count) => array.Remove(startIndex, count); + } private static void AddLinearValueProxying(SyncArray> array, SyncElementList.Point> list) where T : IEquatable @@ -145,30 +176,6 @@ private static void AddTubePointProxying(SyncArray array, SyncElement list.ElementsRemoved += (list, startIndex, count) => array.Remove(startIndex, count); } - private static void AddCurveValueProxying(SyncArray> array, SyncElementList.Point> list) - where T : IEquatable - { - foreach (var key in array) - { - var point = list.Add(); - point.Position.Value = key.time; - point.Value.Value = key.value; - } - - AddUpdateProxies(array, list, list.Elements); - - list.ElementsAdded += (list, startIndex, count) => - { - var addedElements = list.Elements.Skip(startIndex).Take(count).ToArray(); - var buffer = addedElements.Select(point => new CurveKey(point.Position, point.Value)).ToArray(); - - array.Insert(buffer, startIndex); - AddUpdateProxies(array, list, addedElements); - }; - - list.ElementsRemoved += (list, startIndex, count) => array.Remove(startIndex, count); - } - private static void AddUpdateProxies(SyncArray> array, SyncElementList.Point> list, IEnumerable.Point> elements) where T : IEquatable @@ -250,23 +257,10 @@ private static void AddUpdateProxies(SyncArray> array, } } - private static Component GetOrAttachComponent(Slot targetSlot, Type type, out bool attachedNew) + private static bool BuildArray(ISyncArray array, string name, FieldInfo fieldInfo, UIBuilder ui, float labelSize) { - attachedNew = false; - if (targetSlot.GetComponent(type) is not Component comp) - { - comp = targetSlot.AttachComponent(type); - attachedNew = true; - } - return comp; - } - - private static bool Prefix(ISyncArray array, string name, FieldInfo fieldInfo, UIBuilder ui, float labelSize) - { - if (!Enabled) return true; - if (!TryGetGenericParameters(typeof(SyncArray<>), array.GetType(), out var genericParameters)) - return true; + return false; var isSyncLinear = TryGetGenericParameters(typeof(SyncLinear<>), array.GetType(), out var syncLinearGenericParameters); @@ -296,7 +290,7 @@ private static bool Prefix(ISyncArray array, string name, FieldInfo fieldInfo, U if (isSyncLinear && SupportsLerp(syncLinearType!)) { var gradientType = typeof(ValueGradientDriver<>).MakeGenericType(syncLinearType); - var gradient = GetOrAttachComponent(proxySlot, gradientType, out bool attachedNew); + var gradient = GetOrAttachComponent(proxySlot, gradientType, out var attachedNew); list = (ISyncList)gradient.GetSyncMember(nameof(ValueGradientDriver.Points)); listField = gradient.GetSyncMemberFieldInfo(nameof(ValueGradientDriver.Points)); @@ -306,27 +300,27 @@ private static bool Prefix(ISyncArray array, string name, FieldInfo fieldInfo, U if (isParticleBurst) AddParticleBurstListProxying((SyncArray>)array, (SyncElementList.Point>)list); else - _addLinearValueProxying.MakeGenericMethod(syncLinearType).Invoke(null, new object[] { array, list }); + _addLinearValueProxying.MakeGenericMethod(syncLinearType).Invoke(null, [array, list]); } } else if (isSyncCurve && SupportsLerp(syncCurveType!)) { var gradientType = typeof(ValueGradientDriver<>).MakeGenericType(syncCurveType); - var gradient = GetOrAttachComponent(proxySlot, gradientType, out bool attachedNew); + var gradient = GetOrAttachComponent(proxySlot, gradientType, out var attachedNew); list = (ISyncList)gradient.GetSyncMember(nameof(ValueGradientDriver.Points)); listField = gradient.GetSyncMemberFieldInfo(nameof(ValueGradientDriver.Points)); if (attachedNew) { - _addCurveValueProxying.MakeGenericMethod(syncCurveType).Invoke(null, new object[] { array, list }); + _addCurveValueProxying.MakeGenericMethod(syncCurveType).Invoke(null, [array, list]); } } else { if (arrayType == typeof(TubePoint)) { - var gradient = GetOrAttachComponent(proxySlot, typeof(ValueGradientDriver), out bool attachedNew); + var gradient = GetOrAttachComponent(proxySlot, typeof(ValueGradientDriver), out var attachedNew); list = (ISyncList)gradient.GetSyncMember(nameof(ValueGradientDriver.Points)); listField = gradient.GetSyncMemberFieldInfo(nameof(ValueGradientDriver.Points)); @@ -339,27 +333,27 @@ private static bool Prefix(ISyncArray array, string name, FieldInfo fieldInfo, U else if (Coder.IsEnginePrimitive(arrayType)) { var multiplexerType = typeof(ValueMultiplexer<>).MakeGenericType(arrayType); - var multiplexer = GetOrAttachComponent(proxySlot, multiplexerType, out bool attachedNew); + var multiplexer = GetOrAttachComponent(proxySlot, multiplexerType, out var attachedNew); list = (ISyncList)multiplexer.GetSyncMember(nameof(ValueMultiplexer.Values)); listField = multiplexer.GetSyncMemberFieldInfo(nameof(ValueMultiplexer.Values)); if (attachedNew) - _addListValueProxying.MakeGenericMethod(arrayType).Invoke(null, new object[] { array, list }); + _addListValueProxying.MakeGenericMethod(arrayType).Invoke(null, [array, list]); } else if (_iWorldElementType.IsAssignableFrom(arrayType)) { var multiplexerType = typeof(ReferenceMultiplexer<>).MakeGenericType(arrayType); - var multiplexer = GetOrAttachComponent(proxySlot, multiplexerType, out bool attachedNew); + var multiplexer = GetOrAttachComponent(proxySlot, multiplexerType, out var attachedNew); list = (ISyncList)multiplexer.GetSyncMember(nameof(ReferenceMultiplexer.References)); listField = multiplexer.GetSyncMemberFieldInfo(nameof(ReferenceMultiplexer.References)); if (attachedNew) - _addListReferenceProxying.MakeGenericMethod(arrayType).Invoke(null, new object[] { array, list }); + _addListReferenceProxying.MakeGenericMethod(arrayType).Invoke(null, [array, list]); } else { proxySlot.Destroy(); - return true; + return false; } } @@ -393,7 +387,18 @@ void ArrayChanged(IChangeable changeable) ui.Text(in text); } - return false; + return true; + } + + private static Component GetOrAttachComponent(Slot targetSlot, Type type, out bool attachedNew) + { + attachedNew = false; + if (targetSlot.GetComponent(type) is not Component comp) + { + comp = targetSlot.AttachComponent(type); + attachedNew = true; + } + return comp; } private static bool SupportsLerp(Type type) diff --git a/MonkeyLoader.Resonite.Integration/UI/SyncMemberEditorBuilderInjector.cs b/MonkeyLoader.Resonite.Integration/UI/SyncMemberEditorBuilderInjector.cs deleted file mode 100644 index ace973f..0000000 --- a/MonkeyLoader.Resonite.Integration/UI/SyncMemberEditorBuilderInjector.cs +++ /dev/null @@ -1,67 +0,0 @@ -using Elements.Core; -using FrooxEngine; -using FrooxEngine.UIX; -using HarmonyLib; -using MonkeyLoader.Events; -using MonkeyLoader.Patching; -using MonoMod.Utils; -using System; -using System.Collections; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Reflection; -using System.Xml.Linq; - -namespace MonkeyLoader.Resonite.UI -{ - [HarmonyPatchCategory(nameof(SyncMemberEditorBuilderInjector))] - [HarmonyPatch(typeof(SyncMemberEditorBuilder), nameof(SyncMemberEditorBuilder.BuildArray))] - internal sealed class SyncMemberEditorBuilderInjector : ResoniteMonkey, - ICancelableEventSource - { - private static CancelableEventDispatching? _buildArrayEditor; - - public override bool CanBeDisabled => true; - - /// - protected override IEnumerable GetFeaturePatches() => []; - - protected override bool OnLoaded() - { - Mod.RegisterEventSource(this); - - return base.OnLoaded(); - } - - [HarmonyPrefix] - private static bool BuildArrayPrefix(ISyncArray array, string name, FieldInfo fieldInfo, UIBuilder ui, float labelSize) - { - if (!Enabled) - return true; - - OnBuildArray(array, name, fieldInfo, ui, labelSize); - - - - return false; - } - - private static void OnBuildArray(ISyncArray array, string name, FieldInfo fieldInfo, UIBuilder ui, float labelSize) - { - //var root = ui.Root; - - var eventData = new BuildSyncArrayEditorEvent(array, name, fieldInfo, ui, labelSize); - - _buildArrayEditor?.Invoke(eventData); - - //ui.NestInto(root); - } - - event CancelableEventDispatching? ICancelableEventSource.Dispatching - { - add => _buildArrayEditor += value; - remove => _buildArrayEditor -= value; - } - } -} \ No newline at end of file