From 624def8491e45cfb2ba94441f10ee24945191a2a Mon Sep 17 00:00:00 2001 From: KivalEvan <5645391+KivalEvan@users.noreply.github.com> Date: Fri, 23 Sep 2022 18:55:51 -0700 Subject: [PATCH 01/26] Updated packages. --- Checks/ExternalJS.cs | 10 +- ErrorChecker.csproj | 201 +++++++++++++++++++++++++++++++------ FodyWeavers.xsd | 141 ++++++++++++++++++++++++++ Properties/AssemblyInfo.cs | 4 +- app.config | 15 +++ packages.config | 66 ++++++++++-- 6 files changed, 393 insertions(+), 44 deletions(-) create mode 100644 FodyWeavers.xsd create mode 100644 app.config diff --git a/Checks/ExternalJS.cs b/Checks/ExternalJS.cs index dd01aae..ddd0270 100644 --- a/Checks/ExternalJS.cs +++ b/Checks/ExternalJS.cs @@ -18,7 +18,7 @@ class ExternalJS : Check { private Engine engine; - private readonly IConstraint timeConstraint = new TimeConstraint2(TimeSpan.FromSeconds(30L)); + private readonly Constraint timeConstraint = new TimeConstraint2(TimeSpan.FromSeconds(30L)); private readonly string fileName; private bool valid; @@ -30,21 +30,21 @@ private static void TimeLog(string msg) { Debug.Log($"[{time}.{time.Millisecond}] [CM-JS] {msg}"); } - private class TimeConstraint2 : IConstraint + private class TimeConstraint2 : Constraint { private readonly TimeSpan _timeout; private CancellationTokenSource cts; public TimeConstraint2(TimeSpan timeout) => _timeout = timeout; - public void Check() + public override void Check() { if (!cts.IsCancellationRequested) return; throw new TimeoutException(); } - public void Reset() + public override void Reset() { cts?.Dispose(); cts = new CancellationTokenSource(this._timeout); @@ -107,8 +107,6 @@ private JsValue require(string folder, string file) { catch (JavaScriptException jse) { Debug.Log(jse); - Debug.Log("LINE: " + jse.LineNumber); - Debug.Log("COLUMN: " + jse.Column); } return null; } diff --git a/ErrorChecker.csproj b/ErrorChecker.csproj index 996f9e7..cd7b8d1 100644 --- a/ErrorChecker.csproj +++ b/ErrorChecker.csproj @@ -1,11 +1,12 @@  - - - - + + + + + F:\Programs\CM v3 Debug AnyCPU {600D3953-D125-4C0F-A5CF-0E3906D6B6F6} @@ -41,22 +42,24 @@ 4 - - packages\Costura.Fody.4.1.0\lib\net40\Costura.dll - True + + packages\Costura.Fody.5.8.0-alpha0098\lib\netstandard1.0\Costura.dll - - packages\Esprima.2.0.3\lib\net461\Esprima.dll - True + + packages\Esprima.3.0.0-beta-7\lib\net462\Esprima.dll - - packages\Jint.3.0.0-beta-2034\lib\net461\Jint.dll - True + + packages\Jint.3.0.0-beta-2041\lib\net462\Jint.dll $(ChromapperDir)\ChroMapper_Data\Managed\Main.dll False + + packages\Microsoft.Win32.Primitives.4.3.0\lib\net46\Microsoft.Win32.Primitives.dll + True + True + $(ChromapperDir)\ChroMapper_Data\Managed\Plugins.dll False @@ -66,13 +69,150 @@ False + + packages\System.AppContext.4.3.0\lib\net463\System.AppContext.dll + True + True + + + packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll + + + + packages\System.Console.4.3.1\lib\net46\System.Console.dll + True + True + + + packages\System.Diagnostics.DiagnosticSource.7.0.0-rc.1.22426.10\lib\net462\System.Diagnostics.DiagnosticSource.dll + + + packages\System.Diagnostics.Tracing.4.3.0\lib\net462\System.Diagnostics.Tracing.dll + True + True + + + packages\System.Globalization.Calendars.4.3.0\lib\net46\System.Globalization.Calendars.dll + True + True + + + packages\System.IO.4.3.0\lib\net462\System.IO.dll + True + True + + + packages\System.IO.Compression.4.3.0\lib\net46\System.IO.Compression.dll + True + True + + + + packages\System.IO.Compression.ZipFile.4.3.0\lib\net46\System.IO.Compression.ZipFile.dll + True + True + + + packages\System.IO.FileSystem.4.3.0\lib\net46\System.IO.FileSystem.dll + True + True + + + packages\System.IO.FileSystem.Primitives.4.3.0\lib\net46\System.IO.FileSystem.Primitives.dll + True + True + + + packages\System.Linq.4.3.0\lib\net463\System.Linq.dll + True + True + + + packages\System.Linq.Expressions.4.3.0\lib\net463\System.Linq.Expressions.dll + True + True + + + packages\System.Memory.4.5.5\lib\net461\System.Memory.dll + + + packages\System.Net.Http.4.3.4\lib\net46\System.Net.Http.dll + True + True + + + packages\System.Net.Sockets.4.3.0\lib\net46\System.Net.Sockets.dll + True + True + + + + packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll + + + packages\System.Reflection.4.3.0\lib\net462\System.Reflection.dll + True + True + + + packages\System.Runtime.4.3.1\lib\net462\System.Runtime.dll + True + True + + + packages\System.Runtime.CompilerServices.Unsafe.7.0.0-preview.2.22152.2\lib\net462\System.Runtime.CompilerServices.Unsafe.dll + + + packages\System.Runtime.Extensions.4.3.1\lib\net462\System.Runtime.Extensions.dll + True + True + + + packages\System.Runtime.InteropServices.4.3.0\lib\net463\System.Runtime.InteropServices.dll + True + True + + + packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll + True + True + + + packages\System.Security.Cryptography.Algorithms.4.3.1\lib\net463\System.Security.Cryptography.Algorithms.dll + True + True + + + packages\System.Security.Cryptography.Encoding.4.3.0\lib\net46\System.Security.Cryptography.Encoding.dll + True + True + + + packages\System.Security.Cryptography.Primitives.4.3.0\lib\net46\System.Security.Cryptography.Primitives.dll + True + True + + + packages\System.Security.Cryptography.X509Certificates.4.3.2\lib\net461\System.Security.Cryptography.X509Certificates.dll + True + True + + + packages\System.Text.RegularExpressions.4.3.1\lib\net463\System.Text.RegularExpressions.dll + True + True + - + + packages\System.Xml.ReaderWriter.4.3.1\lib\net46\System.Xml.ReaderWriter.dll + True + True + $(ChromapperDir)\ChroMapper_Data\Managed\Unity.TextMeshPro.dll @@ -125,10 +265,11 @@ + + CodeSigning.pfx - @@ -139,22 +280,26 @@ This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - - - - - - + + + + + + + + + + - - - "C:\Program Files (x86)\Windows Kits\10\bin\10.0.18362.0\x64\SignTool" sign /t http://timestamp.digicert.com /fd sha256 /sha1 494ABC44B6FB828C0F185DB80A88C043C4DE77C4 CM-JS.dll del "$(ChromapperDir)\Plugins\CM-JS\CM-JS.dll" copy CM-JS.dll "$(ChromapperDir)\Plugins\CM-JS\" - - + + + + + + + \ No newline at end of file diff --git a/FodyWeavers.xsd b/FodyWeavers.xsd new file mode 100644 index 0000000..05e92c1 --- /dev/null +++ b/FodyWeavers.xsd @@ -0,0 +1,141 @@ + + + + + + + + + + + + A list of assembly names to exclude from the default action of "embed all Copy Local references", delimited with line breaks + + + + + A list of assembly names to include from the default action of "embed all Copy Local references", delimited with line breaks. + + + + + A list of runtime assembly names to exclude from the default action of "embed all Copy Local references", delimited with line breaks + + + + + A list of runtime assembly names to include from the default action of "embed all Copy Local references", delimited with line breaks. + + + + + A list of unmanaged 32 bit assembly names to include, delimited with line breaks. + + + + + A list of unmanaged 64 bit assembly names to include, delimited with line breaks. + + + + + The order of preloaded assemblies, delimited with line breaks. + + + + + + This will copy embedded files to disk before loading them into memory. This is helpful for some scenarios that expected an assembly to be loaded from a physical file. + + + + + Controls if .pdbs for reference assemblies are also embedded. + + + + + Controls if runtime assemblies are also embedded. + + + + + Controls whether the runtime assemblies are embedded with their full path or only with their assembly name. + + + + + Embedded assemblies are compressed by default, and uncompressed when they are loaded. You can turn compression off with this option. + + + + + As part of Costura, embedded assemblies are no longer included as part of the build. This cleanup can be turned off. + + + + + Costura by default will load as part of the module initialization. This flag disables that behavior. Make sure you call CosturaUtility.Initialize() somewhere in your code. + + + + + Costura will by default use assemblies with a name like 'resources.dll' as a satellite resource and prepend the output path. This flag disables that behavior. + + + + + A list of assembly names to exclude from the default action of "embed all Copy Local references", delimited with | + + + + + A list of assembly names to include from the default action of "embed all Copy Local references", delimited with |. + + + + + A list of runtime assembly names to exclude from the default action of "embed all Copy Local references", delimited with | + + + + + A list of runtime assembly names to include from the default action of "embed all Copy Local references", delimited with |. + + + + + A list of unmanaged 32 bit assembly names to include, delimited with |. + + + + + A list of unmanaged 64 bit assembly names to include, delimited with |. + + + + + The order of preloaded assemblies, delimited with |. + + + + + + + + 'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed. + + + + + A comma-separated list of error codes that can be safely ignored in assembly verification. + + + + + 'false' to turn off automatic generation of the XML Schema file. + + + + + \ No newline at end of file diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index dc181cb..2c5949f 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.2.3.0")] -[assembly: AssemblyFileVersion("1.2.3.0")] +[assembly: AssemblyVersion("1.3.0.0")] +[assembly: AssemblyFileVersion("1.3.0.0")] diff --git a/app.config b/app.config new file mode 100644 index 0000000..1e70fd6 --- /dev/null +++ b/app.config @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages.config b/packages.config index 0b42177..2fa5c4c 100644 --- a/packages.config +++ b/packages.config @@ -1,10 +1,60 @@  - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From 72ae81191f07cd7230fbb39fe80fb8fdf5510fc6 Mon Sep 17 00:00:00 2001 From: KivalEvan <5645391+KivalEvan@users.noreply.github.com> Date: Fri, 23 Sep 2022 19:08:13 -0700 Subject: [PATCH 02/26] Add optional float value to event. --- Wrappers/Event.cs | 3 ++- Wrappers/Wrapper.cs | 12 +++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Wrappers/Event.cs b/Wrappers/Event.cs index 6222252..75d1997 100644 --- a/Wrappers/Event.cs +++ b/Wrappers/Event.cs @@ -40,7 +40,8 @@ public Event(Engine engine, MapEvent mapEvent) : base(engine, mapEvent) (float) GetJsValue(o, "_time"), (int) GetJsValue(o, "_type"), (int) GetJsValue(o, "_value"), - GetCustomData(o) + GetCustomData(o), + (float) GetJsValueOptional(o, "_floatValue") ), false, GetJsBool(o, "selected")) { spawned = false; diff --git a/Wrappers/Wrapper.cs b/Wrappers/Wrapper.cs index 81082be..1d0ed94 100644 --- a/Wrappers/Wrapper.cs +++ b/Wrappers/Wrapper.cs @@ -32,6 +32,16 @@ protected static double GetJsValue(ObjectInstance o, string key) return (double)value.ToObject(); } + protected static double? GetJsValueOptional(ObjectInstance o, string key) + { + if (o.TryGetValue(key, out var value)) + { + return (double)value.ToObject(); + } + + return null; + } + protected static string GetJsString(ObjectInstance o, string key) { o.TryGetValue(key, out var value); @@ -42,7 +52,7 @@ protected static string GetJsString(ObjectInstance o, string key) { if (o.TryGetValue(key, out var value)) { - return (bool) value.ToObject(); + return (bool)value.ToObject(); } return null; From d79a33ee8f23c77eb5f67cbc64c2e176ddaca06f Mon Sep 17 00:00:00 2001 From: KivalEvan <5645391+KivalEvan@users.noreply.github.com> Date: Fri, 23 Sep 2022 19:11:59 -0700 Subject: [PATCH 03/26] Add getter/setter for float value. --- Wrappers/Event.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Wrappers/Event.cs b/Wrappers/Event.cs index 75d1997..1bfdce0 100644 --- a/Wrappers/Event.cs +++ b/Wrappers/Event.cs @@ -31,6 +31,16 @@ public int _value } } + public float _floatValue + { + get => wrapped.FloatValue; + set + { + DeleteObject(); + wrapped.FloatValue = value; + } + } + public Event(Engine engine, MapEvent mapEvent) : base(engine, mapEvent) { spawned = true; From f68a59ba8efdeb315f7ec718ad866283b4afea05 Mon Sep 17 00:00:00 2001 From: KivalEvan <5645391+KivalEvan@users.noreply.github.com> Date: Fri, 23 Sep 2022 20:24:56 -0700 Subject: [PATCH 04/26] Add placeholder v3 beatmap object. --- Checks/ExternalJS.cs | 20 ++--- ErrorChecker.csproj | 19 ++-- Wrappers/BpmChange.cs | 87 ------------------ Wrappers/CustomEvent.cs | 89 ------------------- Wrappers/Event.cs | 87 ------------------ Wrappers/Note.cs | 93 -------------------- Wrappers/V2/BpmChange.cs | 93 ++++++++++++++++++++ Wrappers/V2/CustomEvent.cs | 94 ++++++++++++++++++++ Wrappers/V2/Event.cs | 92 +++++++++++++++++++ Wrappers/V2/Note.cs | 98 +++++++++++++++++++++ Wrappers/V2/Wall.cs | 98 +++++++++++++++++++++ Wrappers/V3/Arc.cs | 176 +++++++++++++++++++++++++++++++++++++ Wrappers/V3/BombNote.cs | 76 ++++++++++++++++ Wrappers/V3/BpmChange.cs | 93 ++++++++++++++++++++ Wrappers/V3/Chain.cs | 155 ++++++++++++++++++++++++++++++++ Wrappers/V3/ColorNote.cs | 109 +++++++++++++++++++++++ Wrappers/V3/CustomEvent.cs | 94 ++++++++++++++++++++ Wrappers/V3/Event.cs | 89 +++++++++++++++++++ Wrappers/V3/Wall.cs | 109 +++++++++++++++++++++++ Wrappers/Wall.cs | 93 -------------------- 20 files changed, 1400 insertions(+), 464 deletions(-) delete mode 100644 Wrappers/BpmChange.cs delete mode 100644 Wrappers/CustomEvent.cs delete mode 100644 Wrappers/Event.cs delete mode 100644 Wrappers/Note.cs create mode 100644 Wrappers/V2/BpmChange.cs create mode 100644 Wrappers/V2/CustomEvent.cs create mode 100644 Wrappers/V2/Event.cs create mode 100644 Wrappers/V2/Note.cs create mode 100644 Wrappers/V2/Wall.cs create mode 100644 Wrappers/V3/Arc.cs create mode 100644 Wrappers/V3/BombNote.cs create mode 100644 Wrappers/V3/BpmChange.cs create mode 100644 Wrappers/V3/Chain.cs create mode 100644 Wrappers/V3/ColorNote.cs create mode 100644 Wrappers/V3/CustomEvent.cs create mode 100644 Wrappers/V3/Event.cs create mode 100644 Wrappers/V3/Wall.cs delete mode 100644 Wrappers/Wall.cs diff --git a/Checks/ExternalJS.cs b/Checks/ExternalJS.cs index ddd0270..b5e255c 100644 --- a/Checks/ExternalJS.cs +++ b/Checks/ExternalJS.cs @@ -249,11 +249,11 @@ public override CheckResult PerformCheck(List notes, List var lastBPMChange = collection.FindLastBpm(atsc.CurrentBeat); var currentBPM = lastBPMChange?.Bpm ?? atsc.Song.BeatsPerMinute; - var originalNotes = notes.Select(it => new Note(engine, it)).ToArray(); - var originalWalls = walls.Select(it => new Wall(engine, it)).ToArray(); - var originalEvents = events.Select(it => new Event(engine, it)).ToArray(); - var originalCustomEvents = customEvents.Select(it => new CustomEvent(engine, it)).ToArray(); - var originalBpmChanges = bpmChanges.Select(it => new BpmChange(engine, it)).ToArray(); + var originalNotes = notes.Select(it => new V2.Note(engine, it)).ToArray(); + var originalWalls = walls.Select(it => new V2.Wall(engine, it)).ToArray(); + var originalEvents = events.Select(it => new V2.Event(engine, it)).ToArray(); + var originalCustomEvents = customEvents.Select(it => new V2.CustomEvent(engine, it)).ToArray(); + var originalBpmChanges = bpmChanges.Select(it => new V2.BpmChange(engine, it)).ToArray(); try { @@ -325,11 +325,11 @@ public override CheckResult PerformCheck(List notes, List SelectionController.DeselectAll(); var actions = new List(); - actions.AddRange(Reconcile(originalNotes, engine.GetValue("notes").AsArray(), notes, i => new Note(engine, i), BeatmapObject.ObjectType.Note)); - actions.AddRange(Reconcile(originalWalls, engine.GetValue("walls").AsArray(), walls, i => new Wall(engine, i), BeatmapObject.ObjectType.Obstacle)); - actions.AddRange(Reconcile(originalEvents, engine.GetValue("events").AsArray(), events, i => new Event(engine, i), BeatmapObject.ObjectType.Event)); - actions.AddRange(Reconcile(originalCustomEvents, engine.GetValue("customEvents").AsArray(), customEvents, i => new CustomEvent(engine, i), BeatmapObject.ObjectType.CustomEvent)); - actions.AddRange(Reconcile(originalBpmChanges, engine.GetValue("bpmChanges").AsArray(), bpmChanges, i => new BpmChange(engine, i), BeatmapObject.ObjectType.BpmChange)); + actions.AddRange(Reconcile(originalNotes, engine.GetValue("notes").AsArray(), notes, i => new V2.Note(engine, i), BeatmapObject.ObjectType.Note)); + actions.AddRange(Reconcile(originalWalls, engine.GetValue("walls").AsArray(), walls, i => new V2.Wall(engine, i), BeatmapObject.ObjectType.Obstacle)); + actions.AddRange(Reconcile(originalEvents, engine.GetValue("events").AsArray(), events, i => new V2.Event(engine, i), BeatmapObject.ObjectType.Event)); + actions.AddRange(Reconcile(originalCustomEvents, engine.GetValue("customEvents").AsArray(), customEvents, i => new V2.CustomEvent(engine, i), BeatmapObject.ObjectType.CustomEvent)); + actions.AddRange(Reconcile(originalBpmChanges, engine.GetValue("bpmChanges").AsArray(), bpmChanges, i => new V2.BpmChange(engine, i), BeatmapObject.ObjectType.BpmChange)); SelectionController.SelectionChangedEvent?.Invoke(); diff --git a/ErrorChecker.csproj b/ErrorChecker.csproj index cd7b8d1..dea0058 100644 --- a/ErrorChecker.csproj +++ b/ErrorChecker.csproj @@ -255,13 +255,21 @@ - - - + + + + + + + + + + + - - + + @@ -275,6 +283,7 @@ + diff --git a/Wrappers/BpmChange.cs b/Wrappers/BpmChange.cs deleted file mode 100644 index ee14f90..0000000 --- a/Wrappers/BpmChange.cs +++ /dev/null @@ -1,87 +0,0 @@ -using Jint; -using Jint.Native.Object; - -class BpmChange : Wrapper -{ - public float _time { - get => wrapped.Time; - set { - DeleteObject(); - wrapped.Time = value; - } - } - - public float _BPM - { - get => wrapped.Bpm; - set - { - DeleteObject(); - wrapped.Bpm = value; - } - } - - public float _beatsPerBar - { - get => wrapped.BeatsPerBar; - set - { - DeleteObject(); - wrapped.BeatsPerBar = value; - } - } - - public float _metronomeOffset - { - get => wrapped.MetronomeOffset; - set - { - DeleteObject(); - wrapped.MetronomeOffset = value; - } - } - - public BpmChange(Engine engine, BeatmapBPMChange bpmChange) : base(engine, bpmChange) - { - spawned = true; - } - - public BpmChange(Engine engine, ObjectInstance o) : base(engine, new BeatmapBPMChange( - (float) GetJsValue(o, "_BPM"), - (float) GetJsValue(o, "_time") - ) { - BeatsPerBar = (float) GetJsValue(o, "_beatsPerBar"), - MetronomeOffset = (float) GetJsValue(o, "_metronomeOffset") - }, false, GetJsBool(o, "selected")) - { - spawned = false; - - DeleteObject(); - } - - public override bool SpawnObject(BeatmapObjectContainerCollection collection) - { - if (spawned) return false; - - collection.SpawnObject(wrapped, false, false); - - spawned = true; - return true; - } - - internal override bool DeleteObject() - { - if (!spawned) return false; - - var collection = BeatmapObjectContainerCollection.GetCollectionForType(BeatmapObject.ObjectType.BpmChange); - collection.DeleteObject(wrapped, false); - - spawned = false; - return true; - } - - internal override void Reconcile() - { - // Nothing :) - } -} diff --git a/Wrappers/CustomEvent.cs b/Wrappers/CustomEvent.cs deleted file mode 100644 index 023ed93..0000000 --- a/Wrappers/CustomEvent.cs +++ /dev/null @@ -1,89 +0,0 @@ -using System; -using Jint; -using Jint.Native.Object; - -class CustomEvent : Wrapper -{ - public float _time { - get => wrapped.Time; - set { - DeleteObject(); - wrapped.Time = value; - } - } - - public string _type - { - get => wrapped.Type; - set - { - DeleteObject(); - wrapped.Type = value; - } - } - - private Lazy customData; - private Action reconcile; - public object _data - { - get => wrapped.CustomData == null ? null : customData.Value; - set - { - DeleteObject(); - wrapped.CustomData = JSONWraper.castObjToJSON(value); - InitWrapper(); - } - } - - public CustomEvent(Engine engine, BeatmapCustomEvent customEvent) : base(engine, customEvent) - { - spawned = true; - InitWrapper(); - } - - public CustomEvent(Engine engine, ObjectInstance o) : base(engine, new BeatmapCustomEvent( - (float) GetJsValue(o, "_time"), - GetJsString(o, "_type"), - GetCustomData(o, "_data") - ), false, GetJsBool(o, "selected")) - { - spawned = false; - - DeleteObject(); - InitWrapper(); - } - - public override bool SpawnObject(BeatmapObjectContainerCollection collection) - { - if (spawned) return false; - - collection.SpawnObject(wrapped, false, false); - - spawned = true; - return true; - } - - internal override bool DeleteObject() - { - if (!spawned) return false; - - var collection = BeatmapObjectContainerCollection.GetCollectionForType(BeatmapObject.ObjectType.Event); - collection.DeleteObject(wrapped, false); - - spawned = false; - return true; - } - - private void InitWrapper() - { - reconcile = null; - customData = new Lazy(() => - new JSONWraper(engine, ref reconcile, wrapped.CustomData, DeleteObject) - ); - } - - internal override void Reconcile() - { - reconcile?.Invoke(); - } -} diff --git a/Wrappers/Event.cs b/Wrappers/Event.cs deleted file mode 100644 index 1bfdce0..0000000 --- a/Wrappers/Event.cs +++ /dev/null @@ -1,87 +0,0 @@ -using Jint; -using Jint.Native.Object; - -class Event : VanillaWrapper -{ - public float _time { - get => wrapped.Time; - set { - DeleteObject(); - wrapped.Time = value; - } - } - - public int _type - { - get => wrapped.Type; - set - { - DeleteObject(); - wrapped.Type = value; - } - } - - public int _value - { - get => wrapped.Value; - set - { - DeleteObject(); - wrapped.Value = value; - } - } - - public float _floatValue - { - get => wrapped.FloatValue; - set - { - DeleteObject(); - wrapped.FloatValue = value; - } - } - - public Event(Engine engine, MapEvent mapEvent) : base(engine, mapEvent) - { - spawned = true; - } - - public Event(Engine engine, ObjectInstance o) : base(engine, new MapEvent( - (float) GetJsValue(o, "_time"), - (int) GetJsValue(o, "_type"), - (int) GetJsValue(o, "_value"), - GetCustomData(o), - (float) GetJsValueOptional(o, "_floatValue") - ), false, GetJsBool(o, "selected")) - { - spawned = false; - - DeleteObject(); - } - - public override bool SpawnObject(BeatmapObjectContainerCollection collection) - { - if (spawned) return false; - - if (wrapped.CustomData != null && wrapped.CustomData["_lightGradient"] != null) - { - wrapped.LightGradient = new MapEvent.ChromaGradient(wrapped.CustomData["_lightGradient"]); - } - - collection.SpawnObject(wrapped, false, false); - - spawned = true; - return true; - } - - internal override bool DeleteObject() - { - if (!spawned) return false; - - var collection = BeatmapObjectContainerCollection.GetCollectionForType(BeatmapObject.ObjectType.Event); - collection.DeleteObject(wrapped, false); - - spawned = false; - return true; - } -} diff --git a/Wrappers/Note.cs b/Wrappers/Note.cs deleted file mode 100644 index e2f8e2e..0000000 --- a/Wrappers/Note.cs +++ /dev/null @@ -1,93 +0,0 @@ -using Jint; -using Jint.Native.Object; - -class Note : VanillaWrapper -{ - public float _time { - get => wrapped.Time; - set { - DeleteObject(); - wrapped.Time = value; - } - } - - public int _lineIndex - { - get => wrapped.LineIndex; - set - { - DeleteObject(); - wrapped.LineIndex = value; - } - } - - public int _lineLayer - { - get => wrapped.LineLayer; - set - { - DeleteObject(); - wrapped.LineLayer = value; - } - } - - public int _cutDirection - { - get => wrapped.CutDirection; - set - { - DeleteObject(); - wrapped.CutDirection = value; - } - } - - public int _type - { - get => wrapped.Type; - set - { - DeleteObject(); - wrapped.Type = value; - } - } - - public Note(Engine engine, BeatmapNote note) : base(engine, note) - { - spawned = true; - } - - public Note(Engine engine, ObjectInstance o) : base(engine, new BeatmapNote( - (float) GetJsValue(o, "_time"), - (int) GetJsValue(o, "_lineIndex"), - (int) GetJsValue(o, "_lineLayer"), - (int) GetJsValue(o, "_type"), - (int) GetJsValue(o, "_cutDirection"), - GetCustomData(o) - ), false, GetJsBool(o, "selected")) - { - spawned = false; - - DeleteObject(); - } - - public override bool SpawnObject(BeatmapObjectContainerCollection collection) - { - if (spawned) return false; - - collection.SpawnObject(wrapped, false, false); - - spawned = true; - return true; - } - - internal override bool DeleteObject() - { - if (!spawned) return false; - - var collection = BeatmapObjectContainerCollection.GetCollectionForType(BeatmapObject.ObjectType.Note); - collection.DeleteObject(wrapped, false); - - spawned = false; - return true; - } -} diff --git a/Wrappers/V2/BpmChange.cs b/Wrappers/V2/BpmChange.cs new file mode 100644 index 0000000..2940221 --- /dev/null +++ b/Wrappers/V2/BpmChange.cs @@ -0,0 +1,93 @@ +using Jint; +using Jint.Native.Object; + +namespace V2 +{ + class BpmChange : Wrapper + { + public float _time + { + get => wrapped.Time; + set + { + DeleteObject(); + wrapped.Time = value; + } + } + + public float _BPM + { + get => wrapped.Bpm; + set + { + DeleteObject(); + wrapped.Bpm = value; + } + } + + public float _beatsPerBar + { + get => wrapped.BeatsPerBar; + set + { + DeleteObject(); + wrapped.BeatsPerBar = value; + } + } + + public float _metronomeOffset + { + get => wrapped.MetronomeOffset; + set + { + DeleteObject(); + wrapped.MetronomeOffset = value; + } + } + + public BpmChange(Engine engine, BeatmapBPMChange bpmChange) : base(engine, bpmChange) + { + spawned = true; + } + + public BpmChange(Engine engine, ObjectInstance o) : base(engine, new BeatmapBPMChange( + (float)GetJsValue(o, "_BPM"), + (float)GetJsValue(o, "_time") + ) + { + BeatsPerBar = (float)GetJsValue(o, "_beatsPerBar"), + MetronomeOffset = (float)GetJsValue(o, "_metronomeOffset") + }, false, GetJsBool(o, "selected")) + { + spawned = false; + + DeleteObject(); + } + + public override bool SpawnObject(BeatmapObjectContainerCollection collection) + { + if (spawned) return false; + + collection.SpawnObject(wrapped, false, false); + + spawned = true; + return true; + } + + internal override bool DeleteObject() + { + if (!spawned) return false; + + var collection = BeatmapObjectContainerCollection.GetCollectionForType(BeatmapObject.ObjectType.BpmChange); + collection.DeleteObject(wrapped, false); + + spawned = false; + return true; + } + + internal override void Reconcile() + { + // Nothing :) + } + } +} diff --git a/Wrappers/V2/CustomEvent.cs b/Wrappers/V2/CustomEvent.cs new file mode 100644 index 0000000..80a5c88 --- /dev/null +++ b/Wrappers/V2/CustomEvent.cs @@ -0,0 +1,94 @@ +using System; +using Jint; +using Jint.Native.Object; + +namespace V2 +{ + class CustomEvent : Wrapper + { + public float _time + { + get => wrapped.Time; + set + { + DeleteObject(); + wrapped.Time = value; + } + } + + public string _type + { + get => wrapped.Type; + set + { + DeleteObject(); + wrapped.Type = value; + } + } + + private Lazy customData; + private Action reconcile; + public object _data + { + get => wrapped.CustomData == null ? null : customData.Value; + set + { + DeleteObject(); + wrapped.CustomData = JSONWraper.castObjToJSON(value); + InitWrapper(); + } + } + + public CustomEvent(Engine engine, BeatmapCustomEvent customEvent) : base(engine, customEvent) + { + spawned = true; + InitWrapper(); + } + + public CustomEvent(Engine engine, ObjectInstance o) : base(engine, new BeatmapCustomEvent( + (float)GetJsValue(o, "_time"), + GetJsString(o, "_type"), + GetCustomData(o, "_data") + ), false, GetJsBool(o, "selected")) + { + spawned = false; + + DeleteObject(); + InitWrapper(); + } + + public override bool SpawnObject(BeatmapObjectContainerCollection collection) + { + if (spawned) return false; + + collection.SpawnObject(wrapped, false, false); + + spawned = true; + return true; + } + + internal override bool DeleteObject() + { + if (!spawned) return false; + + var collection = BeatmapObjectContainerCollection.GetCollectionForType(BeatmapObject.ObjectType.Event); + collection.DeleteObject(wrapped, false); + + spawned = false; + return true; + } + + private void InitWrapper() + { + reconcile = null; + customData = new Lazy(() => + new JSONWraper(engine, ref reconcile, wrapped.CustomData, DeleteObject) + ); + } + + internal override void Reconcile() + { + reconcile?.Invoke(); + } + } +} diff --git a/Wrappers/V2/Event.cs b/Wrappers/V2/Event.cs new file mode 100644 index 0000000..4d6cfc4 --- /dev/null +++ b/Wrappers/V2/Event.cs @@ -0,0 +1,92 @@ +using Jint; +using Jint.Native.Object; + +namespace V2 +{ + class Event : VanillaWrapper + { + public float _time + { + get => wrapped.Time; + set + { + DeleteObject(); + wrapped.Time = value; + } + } + + public int _type + { + get => wrapped.Type; + set + { + DeleteObject(); + wrapped.Type = value; + } + } + + public int _value + { + get => wrapped.Value; + set + { + DeleteObject(); + wrapped.Value = value; + } + } + + public float _floatValue + { + get => wrapped.FloatValue; + set + { + DeleteObject(); + wrapped.FloatValue = value; + } + } + + public Event(Engine engine, MapEvent mapEvent) : base(engine, mapEvent) + { + spawned = true; + } + + public Event(Engine engine, ObjectInstance o) : base(engine, new MapEvent( + (float)GetJsValue(o, "_time"), + (int)GetJsValue(o, "_type"), + (int)GetJsValue(o, "_value"), + GetCustomData(o), + (float)GetJsValueOptional(o, "_floatValue") + ), false, GetJsBool(o, "selected")) + { + spawned = false; + + DeleteObject(); + } + + public override bool SpawnObject(BeatmapObjectContainerCollection collection) + { + if (spawned) return false; + + if (wrapped.CustomData != null && wrapped.CustomData["_lightGradient"] != null) + { + wrapped.LightGradient = new MapEvent.ChromaGradient(wrapped.CustomData["_lightGradient"]); + } + + collection.SpawnObject(wrapped, false, false); + + spawned = true; + return true; + } + + internal override bool DeleteObject() + { + if (!spawned) return false; + + var collection = BeatmapObjectContainerCollection.GetCollectionForType(BeatmapObject.ObjectType.Event); + collection.DeleteObject(wrapped, false); + + spawned = false; + return true; + } + } +} diff --git a/Wrappers/V2/Note.cs b/Wrappers/V2/Note.cs new file mode 100644 index 0000000..6baf6c5 --- /dev/null +++ b/Wrappers/V2/Note.cs @@ -0,0 +1,98 @@ +using Jint; +using Jint.Native.Object; + +namespace V2 +{ + class Note : VanillaWrapper + { + public float _time + { + get => wrapped.Time; + set + { + DeleteObject(); + wrapped.Time = value; + } + } + + public int _lineIndex + { + get => wrapped.LineIndex; + set + { + DeleteObject(); + wrapped.LineIndex = value; + } + } + + public int _lineLayer + { + get => wrapped.LineLayer; + set + { + DeleteObject(); + wrapped.LineLayer = value; + } + } + + public int _cutDirection + { + get => wrapped.CutDirection; + set + { + DeleteObject(); + wrapped.CutDirection = value; + } + } + + public int _type + { + get => wrapped.Type; + set + { + DeleteObject(); + wrapped.Type = value; + } + } + + public Note(Engine engine, BeatmapNote note) : base(engine, note) + { + spawned = true; + } + + public Note(Engine engine, ObjectInstance o) : base(engine, new BeatmapNote( + (float)GetJsValue(o, "_time"), + (int)GetJsValue(o, "_lineIndex"), + (int)GetJsValue(o, "_lineLayer"), + (int)GetJsValue(o, "_type"), + (int)GetJsValue(o, "_cutDirection"), + GetCustomData(o) + ), false, GetJsBool(o, "selected")) + { + spawned = false; + + DeleteObject(); + } + + public override bool SpawnObject(BeatmapObjectContainerCollection collection) + { + if (spawned) return false; + + collection.SpawnObject(wrapped, false, false); + + spawned = true; + return true; + } + + internal override bool DeleteObject() + { + if (!spawned) return false; + + var collection = BeatmapObjectContainerCollection.GetCollectionForType(BeatmapObject.ObjectType.Note); + collection.DeleteObject(wrapped, false); + + spawned = false; + return true; + } + } +} diff --git a/Wrappers/V2/Wall.cs b/Wrappers/V2/Wall.cs new file mode 100644 index 0000000..51ffac5 --- /dev/null +++ b/Wrappers/V2/Wall.cs @@ -0,0 +1,98 @@ +using Jint; +using Jint.Native.Object; + +namespace V2 +{ + class Wall : VanillaWrapper + { + public float _time + { + get => wrapped.Time; + set + { + DeleteObject(); + wrapped.Time = value; + } + } + + public int _lineIndex + { + get => wrapped.LineIndex; + set + { + DeleteObject(); + wrapped.LineIndex = value; + } + } + + public int _type + { + get => wrapped.Type; + set + { + DeleteObject(); + wrapped.Type = value; + } + } + + public float _duration + { + get => wrapped.Duration; + set + { + DeleteObject(); + wrapped.Duration = value; + } + } + + public int _width + { + get => wrapped.Width; + set + { + DeleteObject(); + wrapped.Width = value; + } + } + + public Wall(Engine engine, BeatmapObstacle wall) : base(engine, wall) + { + spawned = true; + } + + public Wall(Engine engine, ObjectInstance o) : base(engine, new BeatmapObstacle( + (float)GetJsValue(o, "_time"), + (int)GetJsValue(o, "_lineIndex"), + (int)GetJsValue(o, "_type"), + (float)GetJsValue(o, "_duration"), + (int)GetJsValue(o, "_width"), + GetCustomData(o) + ), false, GetJsBool(o, "selected")) + { + spawned = false; + + DeleteObject(); + } + + public override bool SpawnObject(BeatmapObjectContainerCollection collection) + { + if (spawned) return false; + + collection.SpawnObject(wrapped, false, false); + + spawned = true; + return true; + } + + internal override bool DeleteObject() + { + if (!spawned) return false; + + var collection = BeatmapObjectContainerCollection.GetCollectionForType(BeatmapObject.ObjectType.Obstacle); + collection.DeleteObject(wrapped, false); + + spawned = false; + return true; + } + } +} diff --git a/Wrappers/V3/Arc.cs b/Wrappers/V3/Arc.cs new file mode 100644 index 0000000..eda8c20 --- /dev/null +++ b/Wrappers/V3/Arc.cs @@ -0,0 +1,176 @@ +using Jint; +using Jint.Native.Object; + +namespace V3 +{ + class Arc : VanillaWrapper + { + public float b + { + get => wrapped.Time; + set + { + DeleteObject(); + wrapped.Time = value; + } + } + + public int c + { + get => wrapped.Color; + set + { + DeleteObject(); + wrapped.Color = value; + } + } + + public int x + { + get => wrapped.X; + set + { + DeleteObject(); + wrapped.X = value; + } + } + + public int y + { + get => wrapped.Y; + set + { + DeleteObject(); + wrapped.Y = value; + } + } + + public int d + { + get => wrapped.Direction; + set + { + DeleteObject(); + wrapped.Direction = value; + } + } + + public float mu + { + get => wrapped.HeadControlPointLengthMultiplier; + set + { + DeleteObject(); + wrapped.HeadControlPointLengthMultiplier = value; + } + } + + public float tb + { + get => wrapped.TailTime; + set + { + DeleteObject(); + wrapped.TailTime = value; + } + } + + public int tx + { + get => wrapped.TailX; + set + { + DeleteObject(); + wrapped.TailX = value; + } + } + + public int ty + { + get => wrapped.TailX; + set + { + DeleteObject(); + wrapped.TailX = value; + } + } + + public int tc + { + get => wrapped.TailCutDirection; + set + { + DeleteObject(); + wrapped.TailCutDirection = value; + } + } + + public float tmu + { + get => wrapped.TailControlPointLengthMultiplier; + set + { + DeleteObject(); + wrapped.TailControlPointLengthMultiplier = value; + } + } + + public int m + { + get => wrapped.ArcMidAnchorMode; + set + { + DeleteObject(); + wrapped.ArcMidAnchorMode = value; + } + } + + public Arc(Engine engine, BeatmapArc arc) : base(engine, arc) + { + spawned = true; + } + + public Arc(Engine engine, ObjectInstance o) : base(engine, new BeatmapArc(JSONWraper.castObjToJSON(new + { + b = (float)GetJsValue(o, "b"), + c = (int)GetJsValue(o, "c"), + x = (int)GetJsValue(o, "x"), + y = (int)GetJsValue(o, "y"), + d = (int)GetJsValue(o, "d"), + mu = (float)GetJsValue(o, "mu"), + tb = (float)GetJsValue(o, "tb"), + tx = (int)GetJsValue(o, "tx"), + ty = (int)GetJsValue(o, "ty"), + tc = (int)GetJsValue(o, "tc"), + tmu = (float)GetJsValue(o, "tmu"), + m = (int)GetJsValue(o, "m"), + customData = GetCustomData(o, "customData") + })), false, GetJsBool(o, "selected")) + { + spawned = false; + + DeleteObject(); + } + + public override bool SpawnObject(BeatmapObjectContainerCollection collection) + { + if (spawned) return false; + + collection.SpawnObject(wrapped, false, false); + + spawned = true; + return true; + } + + internal override bool DeleteObject() + { + if (!spawned) return false; + + var collection = BeatmapObjectContainerCollection.GetCollectionForType(BeatmapObject.ObjectType.Note); + collection.DeleteObject(wrapped, false); + + spawned = false; + return true; + } + } +} diff --git a/Wrappers/V3/BombNote.cs b/Wrappers/V3/BombNote.cs new file mode 100644 index 0000000..bdc4418 --- /dev/null +++ b/Wrappers/V3/BombNote.cs @@ -0,0 +1,76 @@ +using Jint; +using Jint.Native.Object; + +namespace V3 +{ + class BombNote : VanillaWrapper + { + public float b + { + get => wrapped.Time; + set + { + DeleteObject(); + wrapped.Time = value; + } + } + + public int x + { + get => wrapped.LineIndex; + set + { + DeleteObject(); + wrapped.LineIndex = value; + } + } + + public int y + { + get => wrapped.LineLayer; + set + { + DeleteObject(); + wrapped.LineLayer = value; + } + } + + public BombNote(Engine engine, BeatmapBombNote bomb) : base(engine, bomb) + { + spawned = true; + } + + public BombNote(Engine engine, ObjectInstance o) : base(engine, new BeatmapBombNote( + (float)GetJsValue(o, "b"), + (int)GetJsValue(o, "x"), + (int)GetJsValue(o, "y"), + GetCustomData(o, "customData") + ), false, GetJsBool(o, "selected")) + { + spawned = false; + + DeleteObject(); + } + + public override bool SpawnObject(BeatmapObjectContainerCollection collection) + { + if (spawned) return false; + + collection.SpawnObject(wrapped, false, false); + + spawned = true; + return true; + } + + internal override bool DeleteObject() + { + if (!spawned) return false; + + var collection = BeatmapObjectContainerCollection.GetCollectionForType(BeatmapObject.ObjectType.Note); + collection.DeleteObject(wrapped, false); + + spawned = false; + return true; + } + } +} diff --git a/Wrappers/V3/BpmChange.cs b/Wrappers/V3/BpmChange.cs new file mode 100644 index 0000000..cf6b854 --- /dev/null +++ b/Wrappers/V3/BpmChange.cs @@ -0,0 +1,93 @@ +using Jint; +using Jint.Native.Object; + +namespace V3 +{ + class BpmChange : Wrapper + { + public float _time + { + get => wrapped.Time; + set + { + DeleteObject(); + wrapped.Time = value; + } + } + + public float _BPM + { + get => wrapped.Bpm; + set + { + DeleteObject(); + wrapped.Bpm = value; + } + } + + public float _beatsPerBar + { + get => wrapped.BeatsPerBar; + set + { + DeleteObject(); + wrapped.BeatsPerBar = value; + } + } + + public float _metronomeOffset + { + get => wrapped.MetronomeOffset; + set + { + DeleteObject(); + wrapped.MetronomeOffset = value; + } + } + + public BpmChange(Engine engine, BeatmapBPMChange bpmChange) : base(engine, bpmChange) + { + spawned = true; + } + + public BpmChange(Engine engine, ObjectInstance o) : base(engine, new BeatmapBPMChange( + (float)GetJsValue(o, "_BPM"), + (float)GetJsValue(o, "_time") + ) + { + BeatsPerBar = (float)GetJsValue(o, "_beatsPerBar"), + MetronomeOffset = (float)GetJsValue(o, "_metronomeOffset") + }, false, GetJsBool(o, "selected")) + { + spawned = false; + + DeleteObject(); + } + + public override bool SpawnObject(BeatmapObjectContainerCollection collection) + { + if (spawned) return false; + + collection.SpawnObject(wrapped, false, false); + + spawned = true; + return true; + } + + internal override bool DeleteObject() + { + if (!spawned) return false; + + var collection = BeatmapObjectContainerCollection.GetCollectionForType(BeatmapObject.ObjectType.BpmChange); + collection.DeleteObject(wrapped, false); + + spawned = false; + return true; + } + + internal override void Reconcile() + { + // Nothing :) + } + } +} diff --git a/Wrappers/V3/Chain.cs b/Wrappers/V3/Chain.cs new file mode 100644 index 0000000..58b397e --- /dev/null +++ b/Wrappers/V3/Chain.cs @@ -0,0 +1,155 @@ +using Jint; +using Jint.Native.Object; + +namespace V3 +{ + class Chain : VanillaWrapper + { + public float b + { + get => wrapped.Time; + set + { + DeleteObject(); + wrapped.Time = value; + } + } + + public int c + { + get => wrapped.Color; + set + { + DeleteObject(); + wrapped.Color = value; + } + } + + public int x + { + get => wrapped.X; + set + { + DeleteObject(); + wrapped.X = value; + } + } + + public int y + { + get => wrapped.Y; + set + { + DeleteObject(); + wrapped.Y = value; + } + } + + public int d + { + get => wrapped.Direction; + set + { + DeleteObject(); + wrapped.Direction = value; + } + } + + public float tb + { + get => wrapped.TailTime; + set + { + DeleteObject(); + wrapped.TailTime = value; + } + } + + public int tx + { + get => wrapped.TailX; + set + { + DeleteObject(); + wrapped.TailX = value; + } + } + + public int ty + { + get => wrapped.TailX; + set + { + DeleteObject(); + wrapped.TailX = value; + } + } + + public int sc + { + get => wrapped.SliceCount; + set + { + DeleteObject(); + wrapped.SliceCount = value; + } + } + + public float s + { + get => wrapped.SquishAmount; + set + { + DeleteObject(); + wrapped.SquishAmount = value; + } + } + + public Chain(Engine engine, BeatmapChain chain) : base(engine, chain) + { + spawned = true; + } + + public Chain(Engine engine, ObjectInstance o) : base(engine, new BeatmapChain(JSONWraper.castObjToJSON(new + { + b = (float)GetJsValue(o, "b"), + c = (int)GetJsValue(o, "c"), + x = (int)GetJsValue(o, "x"), + y = (int)GetJsValue(o, "y"), + d = (int)GetJsValue(o, "d"), + tb = (float)GetJsValue(o, "tb"), + tx = (int)GetJsValue(o, "tx"), + ty = (int)GetJsValue(o, "ty"), + tc = (int)GetJsValue(o, "tc"), + sc = (int)GetJsValue(o, "sc"), + s = (float)GetJsValue(o, "s"), + customData = GetCustomData(o, "customData") + })), false, GetJsBool(o, "selected")) + { + spawned = false; + + DeleteObject(); + } + + public override bool SpawnObject(BeatmapObjectContainerCollection collection) + { + if (spawned) return false; + + collection.SpawnObject(wrapped, false, false); + + spawned = true; + return true; + } + + internal override bool DeleteObject() + { + if (!spawned) return false; + + var collection = BeatmapObjectContainerCollection.GetCollectionForType(BeatmapObject.ObjectType.Note); + collection.DeleteObject(wrapped, false); + + spawned = false; + return true; + } + } +} diff --git a/Wrappers/V3/ColorNote.cs b/Wrappers/V3/ColorNote.cs new file mode 100644 index 0000000..265528a --- /dev/null +++ b/Wrappers/V3/ColorNote.cs @@ -0,0 +1,109 @@ +using Jint; +using Jint.Native.Object; + +namespace V3 +{ + class ColorNote : VanillaWrapper + { + public float b + { + get => wrapped.Time; + set + { + DeleteObject(); + wrapped.Time = value; + } + } + + public int x + { + get => wrapped.LineIndex; + set + { + DeleteObject(); + wrapped.LineIndex = value; + } + } + + public int y + { + get => wrapped.LineLayer; + set + { + DeleteObject(); + wrapped.LineLayer = value; + } + } + + public int a + { + get => wrapped.AngleOffset; + set + { + DeleteObject(); + wrapped.AngleOffset = value; + } + } + + public int c + { + get => wrapped.Color; + set + { + DeleteObject(); + wrapped.Color = value; + } + } + + public int d + { + get => wrapped.CutDirection; + set + { + DeleteObject(); + wrapped.CutDirection = value; + } + } + + public ColorNote(Engine engine, BeatmapColorNote note) : base(engine, note) + { + spawned = true; + } + + public ColorNote(Engine engine, ObjectInstance o) : base(engine, new BeatmapColorNote( + (float)GetJsValue(o, "b"), + (int)GetJsValue(o, "x"), + (int)GetJsValue(o, "y"), + (int)GetJsValue(o, "c"), + (int)GetJsValue(o, "d"), + (int)GetJsValue(o, "a"), + GetCustomData(o, "customData") + ), false, GetJsBool(o, "selected")) + { + spawned = false; + + DeleteObject(); + } + + public override bool SpawnObject(BeatmapObjectContainerCollection collection) + { + if (spawned) return false; + + collection.SpawnObject(wrapped, false, false); + + spawned = true; + return true; + } + + internal override bool DeleteObject() + { + if (!spawned) return false; + + var collection = BeatmapObjectContainerCollection.GetCollectionForType(BeatmapObject.ObjectType.Note); + collection.DeleteObject(wrapped, false); + + spawned = false; + return true; + } + } +} diff --git a/Wrappers/V3/CustomEvent.cs b/Wrappers/V3/CustomEvent.cs new file mode 100644 index 0000000..3024282 --- /dev/null +++ b/Wrappers/V3/CustomEvent.cs @@ -0,0 +1,94 @@ +using System; +using Jint; +using Jint.Native.Object; + +namespace V3 +{ + class CustomEvent : Wrapper + { + public float _time + { + get => wrapped.Time; + set + { + DeleteObject(); + wrapped.Time = value; + } + } + + public string _type + { + get => wrapped.Type; + set + { + DeleteObject(); + wrapped.Type = value; + } + } + + private Lazy customData; + private Action reconcile; + public object _data + { + get => wrapped.CustomData == null ? null : customData.Value; + set + { + DeleteObject(); + wrapped.CustomData = JSONWraper.castObjToJSON(value); + InitWrapper(); + } + } + + public CustomEvent(Engine engine, BeatmapCustomEvent customEvent) : base(engine, customEvent) + { + spawned = true; + InitWrapper(); + } + + public CustomEvent(Engine engine, ObjectInstance o) : base(engine, new BeatmapCustomEvent( + (float)GetJsValue(o, "_time"), + GetJsString(o, "_type"), + GetCustomData(o, "_data") + ), false, GetJsBool(o, "selected")) + { + spawned = false; + + DeleteObject(); + InitWrapper(); + } + + public override bool SpawnObject(BeatmapObjectContainerCollection collection) + { + if (spawned) return false; + + collection.SpawnObject(wrapped, false, false); + + spawned = true; + return true; + } + + internal override bool DeleteObject() + { + if (!spawned) return false; + + var collection = BeatmapObjectContainerCollection.GetCollectionForType(BeatmapObject.ObjectType.Event); + collection.DeleteObject(wrapped, false); + + spawned = false; + return true; + } + + private void InitWrapper() + { + reconcile = null; + customData = new Lazy(() => + new JSONWraper(engine, ref reconcile, wrapped.CustomData, DeleteObject) + ); + } + + internal override void Reconcile() + { + reconcile?.Invoke(); + } + } +} diff --git a/Wrappers/V3/Event.cs b/Wrappers/V3/Event.cs new file mode 100644 index 0000000..7967c50 --- /dev/null +++ b/Wrappers/V3/Event.cs @@ -0,0 +1,89 @@ +using Jint; +using Jint.Native.Object; + +namespace V3 +{ + class Event : VanillaWrapper + { + public float b + { + get => wrapped.Time; + set + { + DeleteObject(); + wrapped.Time = value; + } + } + + public int et + { + get => wrapped.Type; + set + { + DeleteObject(); + wrapped.Type = value; + } + } + + public int i + { + get => wrapped.Value; + set + { + DeleteObject(); + wrapped.Value = value; + } + } + + public float f + { + get => wrapped.FloatValue; + set + { + DeleteObject(); + wrapped.FloatValue = value; + } + } + + public Event(Engine engine, MapEventV3 mapEvent) : base(engine, mapEvent) + { + spawned = true; + } + + public Event(Engine engine, ObjectInstance o) : base(engine, new MapEventV3(JSONWraper.castObjToJSON(new + { + b = (float)GetJsValue(o, "b"), + et = (int)GetJsValue(o, "et"), + i = (int)GetJsValue(o, "i"), + f = (float)GetJsValue(o, "f"), + customData = GetCustomData(o, "customData") + }) + ), false, GetJsBool(o, "selected")) + { + spawned = false; + + DeleteObject(); + } + + public override bool SpawnObject(BeatmapObjectContainerCollection collection) + { + if (spawned) return false; + + collection.SpawnObject(wrapped, false, false); + + spawned = true; + return true; + } + + internal override bool DeleteObject() + { + if (!spawned) return false; + + var collection = BeatmapObjectContainerCollection.GetCollectionForType(BeatmapObject.ObjectType.Event); + collection.DeleteObject(wrapped, false); + + spawned = false; + return true; + } + } +} diff --git a/Wrappers/V3/Wall.cs b/Wrappers/V3/Wall.cs new file mode 100644 index 0000000..7a2f60d --- /dev/null +++ b/Wrappers/V3/Wall.cs @@ -0,0 +1,109 @@ +using Jint; +using Jint.Native.Object; + +namespace V3 +{ + class Wall : VanillaWrapper + { + public float b + { + get => wrapped.Time; + set + { + DeleteObject(); + wrapped.Time = value; + } + } + + public int x + { + get => wrapped.LineIndex; + set + { + DeleteObject(); + wrapped.LineIndex = value; + } + } + + public int y + { + get => wrapped.LineLayer; + set + { + DeleteObject(); + wrapped.LineLayer = value; + } + } + + public float d + { + get => wrapped.Duration; + set + { + DeleteObject(); + wrapped.Duration = value; + } + } + + public int w + { + get => wrapped.Width; + set + { + DeleteObject(); + wrapped.Width = value; + } + } + + public int h + { + get => wrapped.Height; + set + { + DeleteObject(); + wrapped.Height = value; + } + } + + public Wall(Engine engine, BeatmapObstacleV3 wall) : base(engine, wall) + { + spawned = true; + } + + public Wall(Engine engine, ObjectInstance o) : base(engine, new BeatmapObstacleV3(JSONWraper.castObjToJSON(new { + b = (float)GetJsValue(o, "b"), + x = (int)GetJsValue(o, "x"), + y = (int)GetJsValue(o, "y"), + d = (float)GetJsValue(o, "d"), + w = (int)GetJsValue(o, "w"), + h = (int)GetJsValue(o, "h"), + customData = GetCustomData(o, "customData") + })), false, GetJsBool(o, "selected")) + { + spawned = false; + + DeleteObject(); + } + + public override bool SpawnObject(BeatmapObjectContainerCollection collection) + { + if (spawned) return false; + + collection.SpawnObject(wrapped, false, false); + + spawned = true; + return true; + } + + internal override bool DeleteObject() + { + if (!spawned) return false; + + var collection = BeatmapObjectContainerCollection.GetCollectionForType(BeatmapObject.ObjectType.Obstacle); + collection.DeleteObject(wrapped, false); + + spawned = false; + return true; + } + } +} diff --git a/Wrappers/Wall.cs b/Wrappers/Wall.cs deleted file mode 100644 index 1a0a876..0000000 --- a/Wrappers/Wall.cs +++ /dev/null @@ -1,93 +0,0 @@ -using Jint; -using Jint.Native.Object; - -class Wall : VanillaWrapper -{ - public float _time { - get => wrapped.Time; - set { - DeleteObject(); - wrapped.Time = value; - } - } - - public int _lineIndex - { - get => wrapped.LineIndex; - set - { - DeleteObject(); - wrapped.LineIndex = value; - } - } - - public int _type - { - get => wrapped.Type; - set - { - DeleteObject(); - wrapped.Type = value; - } - } - - public float _duration - { - get => wrapped.Duration; - set - { - DeleteObject(); - wrapped.Duration = value; - } - } - - public int _width - { - get => wrapped.Width; - set - { - DeleteObject(); - wrapped.Width = value; - } - } - - public Wall(Engine engine, BeatmapObstacle wall) : base(engine, wall) - { - spawned = true; - } - - public Wall(Engine engine, ObjectInstance o) : base(engine, new BeatmapObstacle( - (float)GetJsValue(o, "_time"), - (int)GetJsValue(o, "_lineIndex"), - (int)GetJsValue(o, "_type"), - (float)GetJsValue(o, "_duration"), - (int)GetJsValue(o, "_width"), - GetCustomData(o) - ), false, GetJsBool(o, "selected")) - { - spawned = false; - - DeleteObject(); - } - - public override bool SpawnObject(BeatmapObjectContainerCollection collection) - { - if (spawned) return false; - - collection.SpawnObject(wrapped, false, false); - - spawned = true; - return true; - } - - internal override bool DeleteObject() - { - if (!spawned) return false; - - var collection = BeatmapObjectContainerCollection.GetCollectionForType(BeatmapObject.ObjectType.Obstacle); - collection.DeleteObject(wrapped, false); - - spawned = false; - return true; - } -} From 70b81a6c3e09d10feee9e395c06ad90a97d4416e Mon Sep 17 00:00:00 2001 From: KivalEvan <5645391+KivalEvan@users.noreply.github.com> Date: Fri, 23 Sep 2022 20:26:06 -0700 Subject: [PATCH 05/26] Fix typo. --- Checks/ExternalJS.cs | 2 +- JintPatch.cs | 4 ++-- Wrappers/JSONWrapper.cs | 12 ++++++------ Wrappers/V2/CustomEvent.cs | 8 ++++---- Wrappers/V3/Arc.cs | 2 +- Wrappers/V3/Chain.cs | 2 +- Wrappers/V3/CustomEvent.cs | 8 ++++---- Wrappers/V3/Event.cs | 2 +- Wrappers/V3/Wall.cs | 2 +- Wrappers/VanillaWrapper.cs | 8 ++++---- 10 files changed, 25 insertions(+), 25 deletions(-) diff --git a/Checks/ExternalJS.cs b/Checks/ExternalJS.cs index b5e255c..028053c 100644 --- a/Checks/ExternalJS.cs +++ b/Checks/ExternalJS.cs @@ -60,7 +60,7 @@ private static void LogIt(object o) { if (o is ExpandoObject ex) { - Debug.Log(JSONWraper.dictToJSON(ex)); + Debug.Log(JSONWrapper.dictToJSON(ex)); } else { diff --git a/JintPatch.cs b/JintPatch.cs index 42fc839..fd672c3 100644 --- a/JintPatch.cs +++ b/JintPatch.cs @@ -22,7 +22,7 @@ public static bool Prefix(ObjectInstance __instance, JsValue property, ref bool { if (__instance is ObjectWrapper wrapper) { - if (wrapper.Target is JSONWraper jsonWraper) + if (wrapper.Target is JSONWrapper jsonWraper) { jsonWraper.DeleteProperty(property); __result = true; @@ -42,7 +42,7 @@ public static bool Prefix(ObjectInstance __instance, ref List __result) { if (__instance is ObjectWrapper wrapper) { - if (wrapper.Target is JSONWraper jsonWraper) + if (wrapper.Target is JSONWrapper jsonWraper) { __result = new List(); foreach (var wrappedKey in jsonWraper.wrapped.Keys) diff --git a/Wrappers/JSONWrapper.cs b/Wrappers/JSONWrapper.cs index e2b3d5b..559ae96 100644 --- a/Wrappers/JSONWrapper.cs +++ b/Wrappers/JSONWrapper.cs @@ -8,18 +8,18 @@ using SimpleJSON; using UnityEngine; -class JSONWraper +class JSONWrapper { private readonly Engine engine; internal readonly JSONNode wrapped; private readonly Func deleteObj; private readonly Dictionary observe = new Dictionary(); - private readonly Dictionary children = new Dictionary(); + private readonly Dictionary children = new Dictionary(); private Action checkObserved; private bool cleanObserved = true; - public JSONWraper(Engine engine, ref Action parent, JSONNode wrapped, Func deleteObj) + public JSONWrapper(Engine engine, ref Action parent, JSONNode wrapped, Func deleteObj) { this.engine = engine; this.wrapped = wrapped; @@ -103,7 +103,7 @@ public static JSONNode castObjToJSON(object o) { switch (o) { - case JSONWraper w: + case JSONWrapper w: return w.wrapped; case JsValue v: return castJSToJSON(v); @@ -178,10 +178,10 @@ public void DeleteProperty(JsValue key) } } - private JSONWraper GetChild(string key) + private JSONWrapper GetChild(string key) { if (!children.ContainsKey(key)) - children.Add(key, new JSONWraper(engine, ref checkObserved, wrapped[key], deleteObj)); + children.Add(key, new JSONWrapper(engine, ref checkObserved, wrapped[key], deleteObj)); return children[key]; } diff --git a/Wrappers/V2/CustomEvent.cs b/Wrappers/V2/CustomEvent.cs index 80a5c88..b2484ce 100644 --- a/Wrappers/V2/CustomEvent.cs +++ b/Wrappers/V2/CustomEvent.cs @@ -26,7 +26,7 @@ public string _type } } - private Lazy customData; + private Lazy customData; private Action reconcile; public object _data { @@ -34,7 +34,7 @@ public object _data set { DeleteObject(); - wrapped.CustomData = JSONWraper.castObjToJSON(value); + wrapped.CustomData = JSONWrapper.castObjToJSON(value); InitWrapper(); } } @@ -81,8 +81,8 @@ internal override bool DeleteObject() private void InitWrapper() { reconcile = null; - customData = new Lazy(() => - new JSONWraper(engine, ref reconcile, wrapped.CustomData, DeleteObject) + customData = new Lazy(() => + new JSONWrapper(engine, ref reconcile, wrapped.CustomData, DeleteObject) ); } diff --git a/Wrappers/V3/Arc.cs b/Wrappers/V3/Arc.cs index eda8c20..7829721 100644 --- a/Wrappers/V3/Arc.cs +++ b/Wrappers/V3/Arc.cs @@ -130,7 +130,7 @@ public Arc(Engine engine, BeatmapArc arc) : base(engine, arc) spawned = true; } - public Arc(Engine engine, ObjectInstance o) : base(engine, new BeatmapArc(JSONWraper.castObjToJSON(new + public Arc(Engine engine, ObjectInstance o) : base(engine, new BeatmapArc(JSONWrapper.castObjToJSON(new { b = (float)GetJsValue(o, "b"), c = (int)GetJsValue(o, "c"), diff --git a/Wrappers/V3/Chain.cs b/Wrappers/V3/Chain.cs index 58b397e..845e419 100644 --- a/Wrappers/V3/Chain.cs +++ b/Wrappers/V3/Chain.cs @@ -110,7 +110,7 @@ public Chain(Engine engine, BeatmapChain chain) : base(engine, chain) spawned = true; } - public Chain(Engine engine, ObjectInstance o) : base(engine, new BeatmapChain(JSONWraper.castObjToJSON(new + public Chain(Engine engine, ObjectInstance o) : base(engine, new BeatmapChain(JSONWrapper.castObjToJSON(new { b = (float)GetJsValue(o, "b"), c = (int)GetJsValue(o, "c"), diff --git a/Wrappers/V3/CustomEvent.cs b/Wrappers/V3/CustomEvent.cs index 3024282..49ff5ab 100644 --- a/Wrappers/V3/CustomEvent.cs +++ b/Wrappers/V3/CustomEvent.cs @@ -26,7 +26,7 @@ public string _type } } - private Lazy customData; + private Lazy customData; private Action reconcile; public object _data { @@ -34,7 +34,7 @@ public object _data set { DeleteObject(); - wrapped.CustomData = JSONWraper.castObjToJSON(value); + wrapped.CustomData = JSONWrapper.castObjToJSON(value); InitWrapper(); } } @@ -81,8 +81,8 @@ internal override bool DeleteObject() private void InitWrapper() { reconcile = null; - customData = new Lazy(() => - new JSONWraper(engine, ref reconcile, wrapped.CustomData, DeleteObject) + customData = new Lazy(() => + new JSONWrapper(engine, ref reconcile, wrapped.CustomData, DeleteObject) ); } diff --git a/Wrappers/V3/Event.cs b/Wrappers/V3/Event.cs index 7967c50..ea0cca0 100644 --- a/Wrappers/V3/Event.cs +++ b/Wrappers/V3/Event.cs @@ -50,7 +50,7 @@ public Event(Engine engine, MapEventV3 mapEvent) : base(engine, mapEvent) spawned = true; } - public Event(Engine engine, ObjectInstance o) : base(engine, new MapEventV3(JSONWraper.castObjToJSON(new + public Event(Engine engine, ObjectInstance o) : base(engine, new MapEventV3(JSONWrapper.castObjToJSON(new { b = (float)GetJsValue(o, "b"), et = (int)GetJsValue(o, "et"), diff --git a/Wrappers/V3/Wall.cs b/Wrappers/V3/Wall.cs index 7a2f60d..795933b 100644 --- a/Wrappers/V3/Wall.cs +++ b/Wrappers/V3/Wall.cs @@ -70,7 +70,7 @@ public Wall(Engine engine, BeatmapObstacleV3 wall) : base(engine, wall) spawned = true; } - public Wall(Engine engine, ObjectInstance o) : base(engine, new BeatmapObstacleV3(JSONWraper.castObjToJSON(new { + public Wall(Engine engine, ObjectInstance o) : base(engine, new BeatmapObstacleV3(JSONWrapper.castObjToJSON(new { b = (float)GetJsValue(o, "b"), x = (int)GetJsValue(o, "x"), y = (int)GetJsValue(o, "y"), diff --git a/Wrappers/VanillaWrapper.cs b/Wrappers/VanillaWrapper.cs index f9c1de5..aa28e65 100644 --- a/Wrappers/VanillaWrapper.cs +++ b/Wrappers/VanillaWrapper.cs @@ -3,7 +3,7 @@ abstract class VanillaWrapper : Wrapper where T : BeatmapObject { - private Lazy customData; + private Lazy customData; private Action reconcile; public object _customData @@ -12,7 +12,7 @@ public object _customData set { DeleteObject(); - wrapped.CustomData = JSONWraper.castObjToJSON(value); + wrapped.CustomData = JSONWrapper.castObjToJSON(value); InitWrapper(); } } @@ -25,8 +25,8 @@ protected VanillaWrapper(Engine engine, T wrapped, bool hasOriginal = true, bool private void InitWrapper() { reconcile = null; - customData = new Lazy(() => - new JSONWraper(engine, ref reconcile, wrapped.CustomData, DeleteObject) + customData = new Lazy(() => + new JSONWrapper(engine, ref reconcile, wrapped.CustomData, DeleteObject) ); } From 521db61501839c3b169e5b38841e8776c34d3420 Mon Sep 17 00:00:00 2001 From: KivalEvan <5645391+KivalEvan@users.noreply.github.com> Date: Fri, 23 Sep 2022 20:54:18 -0700 Subject: [PATCH 06/26] Add more map data. --- Checks/ExternalJS.cs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Checks/ExternalJS.cs b/Checks/ExternalJS.cs index 028053c..86142f5 100644 --- a/Checks/ExternalJS.cs +++ b/Checks/ExternalJS.cs @@ -228,13 +228,19 @@ class MapData { public float songBPM { get; private set; } public float NJS { get; private set; } public float offset { get; private set; } + public string characteristic { get; private set; } + public string difficulty { get; private set; } + public string environment { get; private set; } - public MapData(float currentBPM, float songBPM, float NJS, float offset) + public MapData(float currentBPM, float songBPM, float NJS, float offset, string characteristic, string difficulty, string environment) { this.currentBPM = currentBPM; this.songBPM = songBPM; this.NJS = NJS; this.offset = offset; + this.characteristic = characteristic; + this.difficulty = difficulty; + this.environment = environment; } } @@ -286,7 +292,11 @@ public override CheckResult PerformCheck(List notes, List currentBPM, atsc.Song.BeatsPerMinute, BeatSaberSongContainer.Instance.DifficultyData.NoteJumpMovementSpeed, - BeatSaberSongContainer.Instance.DifficultyData.NoteJumpStartBeatOffset + BeatSaberSongContainer.Instance.DifficultyData.NoteJumpStartBeatOffset, + BeatSaberSongContainer.Instance.DifficultyData.ParentBeatmapSet.BeatmapCharacteristicName, + BeatSaberSongContainer.Instance.DifficultyData.Difficulty, + (BeatSaberSongContainer.Instance.DifficultyData.ParentBeatmapSet.BeatmapCharacteristicName == "360Degree" || BeatSaberSongContainer.Instance.DifficultyData.ParentBeatmapSet.BeatmapCharacteristicName == "90Degree") ? BeatSaberSongContainer.Instance.Song.AllDirectionsEnvironmentName : BeatSaberSongContainer.Instance.Song.EnvironmentName + )) .SetValue("cursor", currentBeat) .SetValue("minTime", 0.24f) From e25369f36c518e2fc1d2de27cd8e102537bc1cc8 Mon Sep 17 00:00:00 2001 From: KivalEvan <5645391+KivalEvan@users.noreply.github.com> Date: Fri, 23 Sep 2022 23:39:01 -0700 Subject: [PATCH 07/26] Somewhat working v3 map script. --- CMJS.cs | 37 +++++++++-- Checks/Check.cs | 14 ++++ Checks/ExternalJS.cs | 142 ++++++++++++++++++++++++++++++++++++++++ Wrappers/JSONWrapper.cs | 12 ++++ Wrappers/V3/Arc.cs | 32 ++++----- Wrappers/V3/Chain.cs | 27 ++++---- Wrappers/V3/Event.cs | 13 ++-- Wrappers/V3/Wall.cs | 18 ++--- 8 files changed, 247 insertions(+), 48 deletions(-) diff --git a/CMJS.cs b/CMJS.cs index d0bd93e..eff67f2 100644 --- a/CMJS.cs +++ b/CMJS.cs @@ -12,6 +12,9 @@ public class CMJS { private NotesContainer notesContainer; + private NotesContainer bombsContainer; + private ChainsContainer chainsContainer; + private ArcsContainer arcsContainer; private ObstaclesContainer wallsContainer; private EventsContainer eventsContainer; private CustomEventsContainer customEventsContainer; @@ -57,6 +60,9 @@ private void SceneLoaded(Scene arg0, LoadSceneMode arg1) if (arg0.buildIndex == 3) // Mapper scene { notesContainer = UnityEngine.Object.FindObjectOfType(); + bombsContainer = UnityEngine.Object.FindObjectOfType(); + arcsContainer = UnityEngine.Object.FindObjectOfType(); + chainsContainer = UnityEngine.Object.FindObjectOfType(); wallsContainer = UnityEngine.Object.FindObjectOfType(); eventsContainer = UnityEngine.Object.FindObjectOfType(); customEventsContainer = UnityEngine.Object.FindObjectOfType(); @@ -72,11 +78,7 @@ private void SceneLoaded(Scene arg0, LoadSceneMode arg1) public void CheckErrors(Check check) { - var allNotes = notesContainer.LoadedObjects.Cast().OrderBy(it => it.Time).ToList(); - var allWalls = wallsContainer.LoadedObjects.Cast().OrderBy(it => it.Time).ToList(); - var allEvents = eventsContainer.LoadedObjects.Cast().OrderBy(it => it.Time).ToList(); - var allCustomEvents = customEventsContainer.LoadedObjects.Cast().OrderBy(it => it.Time).ToList(); - var allBpmChanges = bpmChangesContainer.LoadedObjects.Cast().OrderBy(it => it.Time).ToList(); + bool isV3 = BeatSaberSongContainer.Instance.Map.Version.StartsWith("3"); if (errors != null) { @@ -107,7 +109,30 @@ public void CheckErrors(Check check) return new ParamValue(null); // IDK } }).ToArray(); - errors = check.PerformCheck(allNotes, allEvents, allWalls, allCustomEvents, allBpmChanges, vals).Commit(); + + if (isV3) + { + var allNotes = notesContainer.LoadedObjects.Cast().Where(it => it.Type != 3).OrderBy(it => it.Time).ToList(); + // var allBombs = notesContainer.LoadedObjects.Cast().Where(it => it.Type == 3).OrderBy(it => it.Time).ToList(); + var allBombs = new List {}; + var allArcs = arcsContainer.LoadedObjects.Cast().OrderBy(it => it.Time).ToList(); + var allChains = chainsContainer.LoadedObjects.Cast().OrderBy(it => it.Time).ToList(); + //var allWalls = wallsContainer.LoadedObjects.Cast().OrderBy(it => it.Time).ToList + var allWalls = new List { }; + // var allEvents = eventsContainer.LoadedObjects.Cast().OrderBy(it => it.Time).ToList(); + var allEvents = new List { }; + var allCustomEvents = customEventsContainer.LoadedObjects.Cast().OrderBy(it => it.Time).ToList(); + var allBpmChanges = bpmChangesContainer.LoadedObjects.Cast().OrderBy(it => it.Time).ToList(); + errors = check.PerformCheck(allNotes, allBombs, allArcs, allChains, allEvents, allWalls, allCustomEvents, allBpmChanges, vals).Commit(); + } else + { + var allNotes = notesContainer.LoadedObjects.Cast().OrderBy(it => it.Time).ToList(); + var allWalls = wallsContainer.LoadedObjects.Cast().OrderBy(it => it.Time).ToList(); + var allEvents = eventsContainer.LoadedObjects.Cast().OrderBy(it => it.Time).ToList(); + var allCustomEvents = customEventsContainer.LoadedObjects.Cast().OrderBy(it => it.Time).ToList(); + var allBpmChanges = bpmChangesContainer.LoadedObjects.Cast().OrderBy(it => it.Time).ToList(); + errors = check.PerformCheck(allNotes, allEvents, allWalls, allCustomEvents, allBpmChanges, vals).Commit(); + } // Highlight blocks in loaded containers in case we don't scrub far enough with MoveToTimeInBeats to load them foreach (var block in errors.errors) diff --git a/Checks/Check.cs b/Checks/Check.cs index afb423c..b0a9c9b 100644 --- a/Checks/Check.cs +++ b/Checks/Check.cs @@ -32,6 +32,20 @@ public virtual CheckResult PerformCheck(List notes, List throw new ArgumentException("Wrong number of parameters"); } + protected virtual CheckResult PerformCheck(List notes, List bombs, List arcs, List chains, List events, List walls, List customEvents, List bpmChanges) + { + throw new ArgumentException("Wrong number of parameters"); + } + + public virtual CheckResult PerformCheck(List notes, List bombs, List arcs, List chains, List events, List walls, List customEvents, List bpmChanges, params IParamValue[] vals) + { + if (vals.Length == 0 && Params.Count == 0) + { + return PerformCheck(notes, bombs, arcs, chains, events, walls, customEvents, bpmChanges); + } + throw new ArgumentException("Wrong number of parameters"); + } + public virtual void OnSelected() { diff --git a/Checks/ExternalJS.cs b/Checks/ExternalJS.cs index 86142f5..77dd862 100644 --- a/Checks/ExternalJS.cs +++ b/Checks/ExternalJS.cs @@ -222,6 +222,25 @@ private BeatmapNote FromDynamic(dynamic note, List notes) _cutDirection == it.CutDirection; }); } + private BeatmapColorNote FromDynamic(dynamic note, List notes) + { + float b = Convert.ChangeType(note.b, typeof(float)); + int x = Convert.ChangeType(note.x, typeof(int)); + int y = Convert.ChangeType(note.y, typeof(int)); + int c = Convert.ChangeType(note.c, typeof(int)); + int d = Convert.ChangeType(note.d, typeof(int)); + int a = Convert.ChangeType(note.a, typeof(int)); + + return notes.Find(it => + { + return Mathf.Approximately(b, it.Time) && + x == it.LineIndex && + y == it.LineLayer && + c == it.Type && + d == it.CutDirection && + a == it.AngleOffset; + }); + } class MapData { public float currentBPM { get; private set; } @@ -355,6 +374,129 @@ public override CheckResult PerformCheck(List notes, List return result; } + public override CheckResult PerformCheck(List notes, List bombs, List arcs, List chains, List events, List walls, List customEvents, List bpmChanges, params IParamValue[] vals) + { + result.Clear(); + + var atsc = BeatmapObjectContainerCollection.GetCollectionForType(BeatmapObject.ObjectType.Note).AudioTimeSyncController; + var currentBeat = atsc.CurrentBeat; + + var collection = BeatmapObjectContainerCollection.GetCollectionForType(BeatmapObject.ObjectType.BpmChange); + var lastBPMChange = collection.FindLastBpm(atsc.CurrentBeat); + var currentBPM = lastBPMChange?.Bpm ?? atsc.Song.BeatsPerMinute; + + var originalNotes = notes.Select(it => new V3.ColorNote(engine, it)).ToArray(); + var originalBombs = bombs.Select(it => new V3.BombNote(engine, it)).ToArray(); + var originalArcs = arcs.Select(it => new V3.Arc(engine, it)).ToArray(); + var originalChains = chains.Select(it => new V3.Chain(engine, it)).ToArray(); + var originalWalls = walls.Select(it => new V3.Wall(engine, it)).ToArray(); + var originalEvents = events.Select(it => new V3.Event(engine, it)).ToArray(); + var originalCustomEvents = customEvents.Select(it => new V3.CustomEvent(engine, it)).ToArray(); + var originalBpmChanges = bpmChanges.Select(it => new V3.BpmChange(engine, it)).ToArray(); + + try + { + var valsToString = vals.Select(paramValue => + { + switch (paramValue) + { + case ParamValue pvf: + return pvf.value.ToString(); + case ParamValue pvs: + return $"\"{pvs.value}\""; + case ParamValue pvb: + return pvb.value ? "true" : "false"; + default: + return "null"; + } + }); + + var valsCombined = string.Join(",", valsToString); + + TimeLog("Init"); + + var tmp = engine + .SetValue("notes", originalNotes) + .SetValue("bombs", originalBombs) + .SetValue("arcs", originalArcs) + .SetValue("chains", originalChains) + .SetValue("walls", originalWalls) + .SetValue("events", originalEvents) + .SetValue("customEvents", originalCustomEvents) + .SetValue("bpmChanges", originalBpmChanges) + .SetValue("data", new MapData( + currentBPM, + atsc.Song.BeatsPerMinute, + BeatSaberSongContainer.Instance.DifficultyData.NoteJumpMovementSpeed, + BeatSaberSongContainer.Instance.DifficultyData.NoteJumpStartBeatOffset, + BeatSaberSongContainer.Instance.DifficultyData.ParentBeatmapSet.BeatmapCharacteristicName, + BeatSaberSongContainer.Instance.DifficultyData.Difficulty, + (BeatSaberSongContainer.Instance.DifficultyData.ParentBeatmapSet.BeatmapCharacteristicName == "360Degree" || BeatSaberSongContainer.Instance.DifficultyData.ParentBeatmapSet.BeatmapCharacteristicName == "90Degree") ? BeatSaberSongContainer.Instance.Song.AllDirectionsEnvironmentName : BeatSaberSongContainer.Instance.Song.EnvironmentName + + )) + .SetValue("cursor", currentBeat) + .SetValue("minTime", 0.24f) + .SetValue("maxTime", 0.75f) + .SetValue("addError", new Action((dynamic note, string str) => + { + var obj = FromDynamic(note, notes); + + if (obj != null) + result.Add(obj, str ?? ""); + })) + .SetValue("addWarning", new Action((dynamic note, string str) => + { + var obj = FromDynamic(note, notes); + + if (obj != null) + result.AddWarning(obj, str ?? ""); + })); + + TimeLog("Run"); + + tmp.Execute("global.params = [" + valsCombined + "];" + + "var output = module.exports.run ? module.exports.run(cursor, notes, bombs, arcs, chains, events, walls, {}, global, data, customEvents, bpmChanges) : module.exports.performCheck({notes: notes}" + (vals.Length > 0 ? ", " + valsCombined : "") + ");" + + "if (output && output.notes) { notes = output.notes; };" + + "if (output && output.bombs) { bombs = output.bombs; };" + + "if (output && output.arcs) { arcs = output.arcs; };" + + "if (output && output.chains) { chains = output.chains; };" + + "if (output && output.events) { events = output.events; };" + + "if (output && output.customEvents) { customEvents = output.customEvents; };" + + "if (output && output.bpmChanges) { bpmChanges = output.bpmChanges; };" + + "if (output && output.walls) { walls = output.walls; };"); + } + catch (JavaScriptException jse) + { + Debug.LogWarning($"Error running {fileName}\n{jse.Message}"); + } + + TimeLog("Reconcile"); + + SelectionController.DeselectAll(); + var actions = new List(); + actions.AddRange(Reconcile(originalNotes, engine.GetValue("notes").AsArray(), notes, i => new V3.ColorNote(engine, i), BeatmapObject.ObjectType.Note)); + //actions.AddRange(Reconcile(originalBombs, engine.GetValue("bombs").AsArray(), bombs, i => new V3.BombNote(engine, i), BeatmapObject.ObjectType.Note)); + actions.AddRange(Reconcile(originalArcs, engine.GetValue("arcs").AsArray(), arcs, i => new V3.Arc(engine, i), BeatmapObject.ObjectType.Arc)); + actions.AddRange(Reconcile(originalChains, engine.GetValue("chains").AsArray(), chains, i => new V3.Chain(engine, i), BeatmapObject.ObjectType.Chain)); + //actions.AddRange(Reconcile(originalWalls, engine.GetValue("walls").AsArray(), walls, i => new V3.Wall(engine, i), BeatmapObject.ObjectType.Obstacle)); + //actions.AddRange(Reconcile(originalEvents, engine.GetValue("events").AsArray(), events, i => new V3.Event(engine, i), BeatmapObject.ObjectType.Event)); + actions.AddRange(Reconcile(originalCustomEvents, engine.GetValue("customEvents").AsArray(), customEvents, i => new V3.CustomEvent(engine, i), BeatmapObject.ObjectType.CustomEvent)); + actions.AddRange(Reconcile(originalBpmChanges, engine.GetValue("bpmChanges").AsArray(), bpmChanges, i => new V3.BpmChange(engine, i), BeatmapObject.ObjectType.BpmChange)); + + SelectionController.SelectionChangedEvent?.Invoke(); + + TimeLog("Registering undo actions"); + + if (actions.Count > 0) + { + var allAction = new ActionCollectionAction(actions, true, true, "External Script"); + BeatmapActionContainer.AddAction(allAction); + } + + TimeLog("Fin"); + + return result; + } private List Reconcile(IEnumerable original, ArrayInstance noteArr, List notes, Func inst, BeatmapObject.ObjectType type) where U : Wrapper where T : BeatmapObject { diff --git a/Wrappers/JSONWrapper.cs b/Wrappers/JSONWrapper.cs index 559ae96..dfbb96c 100644 --- a/Wrappers/JSONWrapper.cs +++ b/Wrappers/JSONWrapper.cs @@ -139,6 +139,18 @@ public static JSONNode dictToJSON(ExpandoObject o) return node; } + public static JSONNode dictToJSON(Dictionary dict) + { + var node = new JSONObject(); + + foreach (var x in dict) + { + node[x.Key] = castObjToJSON(x.Value); + } + + return node; + } + public object this[string aKey] { get diff --git a/Wrappers/V3/Arc.cs b/Wrappers/V3/Arc.cs index 7829721..198ad7d 100644 --- a/Wrappers/V3/Arc.cs +++ b/Wrappers/V3/Arc.cs @@ -1,5 +1,7 @@ using Jint; using Jint.Native.Object; +using SimpleJSON; +using System.Collections.Generic; namespace V3 { @@ -130,21 +132,21 @@ public Arc(Engine engine, BeatmapArc arc) : base(engine, arc) spawned = true; } - public Arc(Engine engine, ObjectInstance o) : base(engine, new BeatmapArc(JSONWrapper.castObjToJSON(new - { - b = (float)GetJsValue(o, "b"), - c = (int)GetJsValue(o, "c"), - x = (int)GetJsValue(o, "x"), - y = (int)GetJsValue(o, "y"), - d = (int)GetJsValue(o, "d"), - mu = (float)GetJsValue(o, "mu"), - tb = (float)GetJsValue(o, "tb"), - tx = (int)GetJsValue(o, "tx"), - ty = (int)GetJsValue(o, "ty"), - tc = (int)GetJsValue(o, "tc"), - tmu = (float)GetJsValue(o, "tmu"), - m = (int)GetJsValue(o, "m"), - customData = GetCustomData(o, "customData") + public Arc(Engine engine, ObjectInstance o) : base(engine, new BeatmapArc(JSONWrapper.dictToJSON(new Dictionary() + { + { "b", (float)GetJsValue(o, "b") }, + { "c", (int)GetJsValue(o, "c")}, + { "x", (int) GetJsValue(o, "x")}, + { "y", (int)GetJsValue(o, "y")}, + { "d", (int)GetJsValue(o, "d")}, + { "mu", (float)GetJsValue(o, "mu")}, + { "tb", (float)GetJsValue(o, "tb")}, + { "tx", (int)GetJsValue(o, "tx")}, + { "ty", (int)GetJsValue(o, "ty")}, + { "tc", (int)GetJsValue(o, "tc")}, + { "tmu", (float)GetJsValue(o, "tmu")}, + { "m", (int)GetJsValue(o, "m")}, + { "customData", GetCustomData(o, "customData")} })), false, GetJsBool(o, "selected")) { spawned = false; diff --git a/Wrappers/V3/Chain.cs b/Wrappers/V3/Chain.cs index 845e419..94cf5e5 100644 --- a/Wrappers/V3/Chain.cs +++ b/Wrappers/V3/Chain.cs @@ -1,5 +1,6 @@ using Jint; using Jint.Native.Object; +using System.Collections.Generic; namespace V3 { @@ -110,20 +111,20 @@ public Chain(Engine engine, BeatmapChain chain) : base(engine, chain) spawned = true; } - public Chain(Engine engine, ObjectInstance o) : base(engine, new BeatmapChain(JSONWrapper.castObjToJSON(new + public Chain(Engine engine, ObjectInstance o) : base(engine, new BeatmapChain(JSONWrapper.dictToJSON(new Dictionary() { - b = (float)GetJsValue(o, "b"), - c = (int)GetJsValue(o, "c"), - x = (int)GetJsValue(o, "x"), - y = (int)GetJsValue(o, "y"), - d = (int)GetJsValue(o, "d"), - tb = (float)GetJsValue(o, "tb"), - tx = (int)GetJsValue(o, "tx"), - ty = (int)GetJsValue(o, "ty"), - tc = (int)GetJsValue(o, "tc"), - sc = (int)GetJsValue(o, "sc"), - s = (float)GetJsValue(o, "s"), - customData = GetCustomData(o, "customData") + { "b", (float)GetJsValue(o, "b") }, + { "c", (int)GetJsValue(o, "c") }, + { "x", (int) GetJsValue(o, "x") }, + { "y", (int)GetJsValue(o, "y") }, + { "d", (int)GetJsValue(o, "d") }, + { "tb", (float)GetJsValue(o, "tb") }, + { "tx", (int)GetJsValue(o, "tx") }, + { "ty", (int)GetJsValue(o, "ty") }, + { "tc", (int)GetJsValue(o, "tc") }, + { "sc", (int)GetJsValue(o, "sc") }, + { "s", (float)GetJsValue(o, "s") }, + { "customData", GetCustomData(o, "customData") } })), false, GetJsBool(o, "selected")) { spawned = false; diff --git a/Wrappers/V3/Event.cs b/Wrappers/V3/Event.cs index ea0cca0..321050c 100644 --- a/Wrappers/V3/Event.cs +++ b/Wrappers/V3/Event.cs @@ -1,5 +1,6 @@ using Jint; using Jint.Native.Object; +using System.Collections.Generic; namespace V3 { @@ -50,13 +51,13 @@ public Event(Engine engine, MapEventV3 mapEvent) : base(engine, mapEvent) spawned = true; } - public Event(Engine engine, ObjectInstance o) : base(engine, new MapEventV3(JSONWrapper.castObjToJSON(new + public Event(Engine engine, ObjectInstance o) : base(engine, new MapEventV3(JSONWrapper.dictToJSON(new Dictionary() { - b = (float)GetJsValue(o, "b"), - et = (int)GetJsValue(o, "et"), - i = (int)GetJsValue(o, "i"), - f = (float)GetJsValue(o, "f"), - customData = GetCustomData(o, "customData") + { "b", (float)GetJsValue(o, "b") }, + { "et", (int)GetJsValue(o, "et") }, + { "i", (int)GetJsValue(o, "i") }, + { "f", (float)GetJsValue(o, "f") }, + { "customData", GetCustomData(o, "customData") } }) ), false, GetJsBool(o, "selected")) { diff --git a/Wrappers/V3/Wall.cs b/Wrappers/V3/Wall.cs index 795933b..bcd598a 100644 --- a/Wrappers/V3/Wall.cs +++ b/Wrappers/V3/Wall.cs @@ -1,5 +1,6 @@ using Jint; using Jint.Native.Object; +using System.Collections.Generic; namespace V3 { @@ -70,14 +71,15 @@ public Wall(Engine engine, BeatmapObstacleV3 wall) : base(engine, wall) spawned = true; } - public Wall(Engine engine, ObjectInstance o) : base(engine, new BeatmapObstacleV3(JSONWrapper.castObjToJSON(new { - b = (float)GetJsValue(o, "b"), - x = (int)GetJsValue(o, "x"), - y = (int)GetJsValue(o, "y"), - d = (float)GetJsValue(o, "d"), - w = (int)GetJsValue(o, "w"), - h = (int)GetJsValue(o, "h"), - customData = GetCustomData(o, "customData") + public Wall(Engine engine, ObjectInstance o) : base(engine, new BeatmapObstacleV3(JSONWrapper.castObjToJSON(new Dictionary() + { + { "b", (float)GetJsValue(o, "b") }, + { "x", (int)GetJsValue(o, "x") }, + { "y", (int)GetJsValue(o, "y") }, + { "d", (float)GetJsValue(o, "d") }, + { "w", (int)GetJsValue(o, "w") }, + { "h", (int)GetJsValue(o, "h") }, + { "customData", GetCustomData(o, "customData") } })), false, GetJsBool(o, "selected")) { spawned = false; From e615c2984ee835f86afc9e9f4ef731567e8354f2 Mon Sep 17 00:00:00 2001 From: KivalEvan <5645391+KivalEvan@users.noreply.github.com> Date: Sat, 24 Sep 2022 03:34:53 -0700 Subject: [PATCH 08/26] Add v3 and v2 compatibility. --- CMJS.cs | 13 +++----- Checks/Check.cs | 2 +- Checks/ExternalJS.cs | 28 ++++++++-------- Wrappers/V2/Event.cs | 50 +++++++++++++++++++++++++--- Wrappers/V2/Note.cs | 70 ++++++++++++++++++++++++++++++++++++---- Wrappers/V2/Wall.cs | 68 ++++++++++++++++++++++++++++++++++---- Wrappers/V3/Arc.cs | 24 +++++++------- Wrappers/V3/Chain.cs | 1 - Wrappers/V3/ColorNote.cs | 64 ++++++++++++++++++++++++++++++++---- Wrappers/V3/Event.cs | 56 ++++++++++++++++++++++++++------ Wrappers/V3/Wall.cs | 66 ++++++++++++++++++++++++++++++++----- Wrappers/Wrapper.cs | 39 ++++++++++++++++++++++ 12 files changed, 404 insertions(+), 77 deletions(-) diff --git a/CMJS.cs b/CMJS.cs index eff67f2..26eae32 100644 --- a/CMJS.cs +++ b/CMJS.cs @@ -12,7 +12,6 @@ public class CMJS { private NotesContainer notesContainer; - private NotesContainer bombsContainer; private ChainsContainer chainsContainer; private ArcsContainer arcsContainer; private ObstaclesContainer wallsContainer; @@ -60,7 +59,6 @@ private void SceneLoaded(Scene arg0, LoadSceneMode arg1) if (arg0.buildIndex == 3) // Mapper scene { notesContainer = UnityEngine.Object.FindObjectOfType(); - bombsContainer = UnityEngine.Object.FindObjectOfType(); arcsContainer = UnityEngine.Object.FindObjectOfType(); chainsContainer = UnityEngine.Object.FindObjectOfType(); wallsContainer = UnityEngine.Object.FindObjectOfType(); @@ -112,15 +110,12 @@ public void CheckErrors(Check check) if (isV3) { - var allNotes = notesContainer.LoadedObjects.Cast().Where(it => it.Type != 3).OrderBy(it => it.Time).ToList(); - // var allBombs = notesContainer.LoadedObjects.Cast().Where(it => it.Type == 3).OrderBy(it => it.Time).ToList(); - var allBombs = new List {}; + var allNotes = notesContainer.LoadedObjects.Where(it => it is BeatmapColorNote).Cast().OrderBy(it => it.Time).ToList(); + var allBombs = notesContainer.LoadedObjects.Where(it => it is BeatmapBombNote).Cast().OrderBy(it => it.Time).ToList(); var allArcs = arcsContainer.LoadedObjects.Cast().OrderBy(it => it.Time).ToList(); var allChains = chainsContainer.LoadedObjects.Cast().OrderBy(it => it.Time).ToList(); - //var allWalls = wallsContainer.LoadedObjects.Cast().OrderBy(it => it.Time).ToList - var allWalls = new List { }; - // var allEvents = eventsContainer.LoadedObjects.Cast().OrderBy(it => it.Time).ToList(); - var allEvents = new List { }; + var allWalls = wallsContainer.LoadedObjects.Where(it => it is BeatmapObstacleV3).Cast().OrderBy(it => it.Time).ToList(); + var allEvents = eventsContainer.LoadedObjects.Where(it => it is MapEventV3).Cast().OrderBy(it => it.Time).ToList(); var allCustomEvents = customEventsContainer.LoadedObjects.Cast().OrderBy(it => it.Time).ToList(); var allBpmChanges = bpmChangesContainer.LoadedObjects.Cast().OrderBy(it => it.Time).ToList(); errors = check.PerformCheck(allNotes, allBombs, allArcs, allChains, allEvents, allWalls, allCustomEvents, allBpmChanges, vals).Commit(); diff --git a/Checks/Check.cs b/Checks/Check.cs index b0a9c9b..2129891 100644 --- a/Checks/Check.cs +++ b/Checks/Check.cs @@ -32,7 +32,7 @@ public virtual CheckResult PerformCheck(List notes, List throw new ArgumentException("Wrong number of parameters"); } - protected virtual CheckResult PerformCheck(List notes, List bombs, List arcs, List chains, List events, List walls, List customEvents, List bpmChanges) + protected virtual CheckResult PerformCheck(List notes, List bombs, List arcs, List chains, List events, List walls, List customEvents, List bpmChanges) { throw new ArgumentException("Wrong number of parameters"); } diff --git a/Checks/ExternalJS.cs b/Checks/ExternalJS.cs index 77dd862..b3d1a87 100644 --- a/Checks/ExternalJS.cs +++ b/Checks/ExternalJS.cs @@ -179,23 +179,23 @@ private void LoadJS() if (nameObj.IsString()) { var name = nameObj.AsString(); - Name = "ExternalJS: " + name; + Name = "extJS: " + name; } else { - Name = $"ExternalJS: {fileName}"; + Name = $"extJS: {fileName}"; } valid = true; } catch (JavaScriptException jse) { - Name = $"ExternalJS: [{fileName}]"; + Name = $"extJS: [{fileName}]"; Debug.LogWarning($"Error loading {fileName}\n{jse.Message}"); } catch (ParserException jse) { - Name = $"ExternalJS: [{fileName}]"; + Name = $"extJS: [{fileName}]"; Debug.LogWarning($"Error loading {fileName}\n{jse.Message}"); } } @@ -250,8 +250,9 @@ class MapData { public string characteristic { get; private set; } public string difficulty { get; private set; } public string environment { get; private set; } + public string version { get; private set; } - public MapData(float currentBPM, float songBPM, float NJS, float offset, string characteristic, string difficulty, string environment) + public MapData(float currentBPM, float songBPM, float NJS, float offset, string characteristic, string difficulty, string environment, string version) { this.currentBPM = currentBPM; this.songBPM = songBPM; @@ -260,6 +261,7 @@ public MapData(float currentBPM, float songBPM, float NJS, float offset, string this.characteristic = characteristic; this.difficulty = difficulty; this.environment = environment; + this.version = version; } } @@ -314,8 +316,8 @@ public override CheckResult PerformCheck(List notes, List BeatSaberSongContainer.Instance.DifficultyData.NoteJumpStartBeatOffset, BeatSaberSongContainer.Instance.DifficultyData.ParentBeatmapSet.BeatmapCharacteristicName, BeatSaberSongContainer.Instance.DifficultyData.Difficulty, - (BeatSaberSongContainer.Instance.DifficultyData.ParentBeatmapSet.BeatmapCharacteristicName == "360Degree" || BeatSaberSongContainer.Instance.DifficultyData.ParentBeatmapSet.BeatmapCharacteristicName == "90Degree") ? BeatSaberSongContainer.Instance.Song.AllDirectionsEnvironmentName : BeatSaberSongContainer.Instance.Song.EnvironmentName - + (BeatSaberSongContainer.Instance.DifficultyData.ParentBeatmapSet.BeatmapCharacteristicName == "360Degree" || BeatSaberSongContainer.Instance.DifficultyData.ParentBeatmapSet.BeatmapCharacteristicName == "90Degree") ? BeatSaberSongContainer.Instance.Song.AllDirectionsEnvironmentName : BeatSaberSongContainer.Instance.Song.EnvironmentName, + BeatSaberSongContainer.Instance.Map.Version )) .SetValue("cursor", currentBeat) .SetValue("minTime", 0.24f) @@ -431,8 +433,8 @@ public override CheckResult PerformCheck(List notes, List notes, List 0 ? ", " + valsCombined : "") + ");" + + "var output = module.exports.run ? module.exports.run(cursor, notes, events, walls, {}, global, data, customEvents, bpmChanges, bombs, arcs, chains) : module.exports.performCheck({notes: notes}" + (vals.Length > 0 ? ", " + valsCombined : "") + ");" + "if (output && output.notes) { notes = output.notes; };" + "if (output && output.bombs) { bombs = output.bombs; };" + "if (output && output.arcs) { arcs = output.arcs; };" + @@ -475,11 +477,11 @@ public override CheckResult PerformCheck(List notes, List(); actions.AddRange(Reconcile(originalNotes, engine.GetValue("notes").AsArray(), notes, i => new V3.ColorNote(engine, i), BeatmapObject.ObjectType.Note)); - //actions.AddRange(Reconcile(originalBombs, engine.GetValue("bombs").AsArray(), bombs, i => new V3.BombNote(engine, i), BeatmapObject.ObjectType.Note)); + actions.AddRange(Reconcile(originalBombs, engine.GetValue("bombs").AsArray(), bombs, i => new V3.BombNote(engine, i), BeatmapObject.ObjectType.Note)); actions.AddRange(Reconcile(originalArcs, engine.GetValue("arcs").AsArray(), arcs, i => new V3.Arc(engine, i), BeatmapObject.ObjectType.Arc)); actions.AddRange(Reconcile(originalChains, engine.GetValue("chains").AsArray(), chains, i => new V3.Chain(engine, i), BeatmapObject.ObjectType.Chain)); - //actions.AddRange(Reconcile(originalWalls, engine.GetValue("walls").AsArray(), walls, i => new V3.Wall(engine, i), BeatmapObject.ObjectType.Obstacle)); - //actions.AddRange(Reconcile(originalEvents, engine.GetValue("events").AsArray(), events, i => new V3.Event(engine, i), BeatmapObject.ObjectType.Event)); + actions.AddRange(Reconcile(originalWalls, engine.GetValue("walls").AsArray(), walls, i => new V3.Wall(engine, i), BeatmapObject.ObjectType.Obstacle)); + actions.AddRange(Reconcile(originalEvents, engine.GetValue("events").AsArray(), events, i => new V3.Event(engine, i), BeatmapObject.ObjectType.Event)); actions.AddRange(Reconcile(originalCustomEvents, engine.GetValue("customEvents").AsArray(), customEvents, i => new V3.CustomEvent(engine, i), BeatmapObject.ObjectType.CustomEvent)); actions.AddRange(Reconcile(originalBpmChanges, engine.GetValue("bpmChanges").AsArray(), bpmChanges, i => new V3.BpmChange(engine, i), BeatmapObject.ObjectType.BpmChange)); diff --git a/Wrappers/V2/Event.cs b/Wrappers/V2/Event.cs index 4d6cfc4..5609ccd 100644 --- a/Wrappers/V2/Event.cs +++ b/Wrappers/V2/Event.cs @@ -45,17 +45,57 @@ public float _floatValue } } + public float b + { + get => wrapped.Time; + set + { + DeleteObject(); + wrapped.Time = value; + } + } + + public int et + { + get => wrapped.Type; + set + { + DeleteObject(); + wrapped.Type = value; + } + } + + public int i + { + get => wrapped.Value; + set + { + DeleteObject(); + wrapped.Value = value; + } + } + + public float f + { + get => wrapped.FloatValue; + set + { + DeleteObject(); + wrapped.FloatValue = value; + } + } + public Event(Engine engine, MapEvent mapEvent) : base(engine, mapEvent) { spawned = true; } public Event(Engine engine, ObjectInstance o) : base(engine, new MapEvent( - (float)GetJsValue(o, "_time"), - (int)GetJsValue(o, "_type"), - (int)GetJsValue(o, "_value"), - GetCustomData(o), - (float)GetJsValueOptional(o, "_floatValue") + (float)GetJsValue(o, new string[] { "_time", "b" }), + (int)GetJsValue(o, new string[] { "_type", "et" }), + (int)GetJsValue(o, new string[] { "_value", "i" }), + GetCustomData(o, new string[] { "_customData", "customData" }), + (float)GetJsValue(o, new string[] { "_floatValue", "f" }) ), false, GetJsBool(o, "selected")) { spawned = false; diff --git a/Wrappers/V2/Note.cs b/Wrappers/V2/Note.cs index 6baf6c5..e57b287 100644 --- a/Wrappers/V2/Note.cs +++ b/Wrappers/V2/Note.cs @@ -55,18 +55,76 @@ public int _type } } + public float b + { + get => wrapped.Time; + set + { + DeleteObject(); + wrapped.Time = value; + } + } + + public int x + { + get => wrapped.LineIndex; + set + { + DeleteObject(); + wrapped.LineIndex = value; + } + } + + public int y + { + get => wrapped.LineLayer; + set + { + DeleteObject(); + wrapped.LineLayer = value; + } + } + + public int a + { + get => 0; + set + { + } + } + + public int c + { + get => wrapped.Type; + set + { + DeleteObject(); + wrapped.Type = value; + } + } + + public int d + { + get => wrapped.CutDirection; + set + { + DeleteObject(); + wrapped.CutDirection = value; + } + } + public Note(Engine engine, BeatmapNote note) : base(engine, note) { spawned = true; } public Note(Engine engine, ObjectInstance o) : base(engine, new BeatmapNote( - (float)GetJsValue(o, "_time"), - (int)GetJsValue(o, "_lineIndex"), - (int)GetJsValue(o, "_lineLayer"), - (int)GetJsValue(o, "_type"), - (int)GetJsValue(o, "_cutDirection"), - GetCustomData(o) + (float)GetJsValue(o, new string[] { "_time", "b" }), + (int)GetJsValue(o, new string[] { "_lineIndex", "x" }), + (int)GetJsValue(o, new string[] { "_lineLayer", "y" }), + (int)GetJsValue(o, new string[] { "_type", "c" }), + (int)GetJsValue(o, new string[] { "_cutDirection", "d" }), + GetCustomData(o, new string[] { "_customData", "customData" }) ), false, GetJsBool(o, "selected")) { spawned = false; diff --git a/Wrappers/V2/Wall.cs b/Wrappers/V2/Wall.cs index 51ffac5..29ad618 100644 --- a/Wrappers/V2/Wall.cs +++ b/Wrappers/V2/Wall.cs @@ -55,18 +55,74 @@ public int _width } } + public float b + { + get => wrapped.Time; + set + { + DeleteObject(); + wrapped.Time = value; + } + } + + public int x + { + get => wrapped.LineIndex; + set + { + DeleteObject(); + wrapped.LineIndex = value; + } + } + + public int y + { + get => 0; + set + { + } + } + + public float d + { + get => wrapped.Duration; + set + { + DeleteObject(); + wrapped.Duration = value; + } + } + + public int w + { + get => wrapped.Width; + set + { + DeleteObject(); + wrapped.Width = value; + } + } + + public int h + { + get => 0; + set + { + } + } + public Wall(Engine engine, BeatmapObstacle wall) : base(engine, wall) { spawned = true; } public Wall(Engine engine, ObjectInstance o) : base(engine, new BeatmapObstacle( - (float)GetJsValue(o, "_time"), - (int)GetJsValue(o, "_lineIndex"), - (int)GetJsValue(o, "_type"), - (float)GetJsValue(o, "_duration"), - (int)GetJsValue(o, "_width"), - GetCustomData(o) + (float)GetJsValue(o, new string[] { "_time", "b" }), + (int)GetJsValue(o, new string[] { "_lineIndex", "x" }), + (int)(GetJsValueOptional(o, "_type") ?? (GetJsValue(o, "y") < 2 ? 0 : 1)), + (float)GetJsValue(o, new string[] { "_duration", "d" }), + (int)GetJsValue(o, new string[] { "_width", "w" }), + GetCustomData(o, new string[] { "_customData", "customData" }) ), false, GetJsBool(o, "selected")) { spawned = false; diff --git a/Wrappers/V3/Arc.cs b/Wrappers/V3/Arc.cs index 198ad7d..ddba878 100644 --- a/Wrappers/V3/Arc.cs +++ b/Wrappers/V3/Arc.cs @@ -135,18 +135,18 @@ public Arc(Engine engine, BeatmapArc arc) : base(engine, arc) public Arc(Engine engine, ObjectInstance o) : base(engine, new BeatmapArc(JSONWrapper.dictToJSON(new Dictionary() { { "b", (float)GetJsValue(o, "b") }, - { "c", (int)GetJsValue(o, "c")}, - { "x", (int) GetJsValue(o, "x")}, - { "y", (int)GetJsValue(o, "y")}, - { "d", (int)GetJsValue(o, "d")}, - { "mu", (float)GetJsValue(o, "mu")}, - { "tb", (float)GetJsValue(o, "tb")}, - { "tx", (int)GetJsValue(o, "tx")}, - { "ty", (int)GetJsValue(o, "ty")}, - { "tc", (int)GetJsValue(o, "tc")}, - { "tmu", (float)GetJsValue(o, "tmu")}, - { "m", (int)GetJsValue(o, "m")}, - { "customData", GetCustomData(o, "customData")} + { "c", (int)GetJsValue(o, "c") }, + { "x", (int) GetJsValue(o, "x") }, + { "y", (int)GetJsValue(o, "y") }, + { "d", (int)GetJsValue(o, "d") }, + { "mu", (float)GetJsValue(o, "mu") }, + { "tb", (float)GetJsValue(o, "tb") }, + { "tx", (int)GetJsValue(o, "tx") }, + { "ty", (int)GetJsValue(o, "ty") }, + { "tc", (int)GetJsValue(o, "tc") }, + { "tmu", (float)GetJsValue(o, "tmu") }, + { "m", (int)GetJsValue(o, "m") }, + { "customData", GetCustomData(o, "customData") } })), false, GetJsBool(o, "selected")) { spawned = false; diff --git a/Wrappers/V3/Chain.cs b/Wrappers/V3/Chain.cs index 94cf5e5..3cfd8e7 100644 --- a/Wrappers/V3/Chain.cs +++ b/Wrappers/V3/Chain.cs @@ -121,7 +121,6 @@ public Chain(Engine engine, BeatmapChain chain) : base(engine, chain) { "tb", (float)GetJsValue(o, "tb") }, { "tx", (int)GetJsValue(o, "tx") }, { "ty", (int)GetJsValue(o, "ty") }, - { "tc", (int)GetJsValue(o, "tc") }, { "sc", (int)GetJsValue(o, "sc") }, { "s", (float)GetJsValue(o, "s") }, { "customData", GetCustomData(o, "customData") } diff --git a/Wrappers/V3/ColorNote.cs b/Wrappers/V3/ColorNote.cs index 265528a..a796a99 100644 --- a/Wrappers/V3/ColorNote.cs +++ b/Wrappers/V3/ColorNote.cs @@ -5,6 +5,56 @@ namespace V3 { class ColorNote : VanillaWrapper { + public float _time + { + get => wrapped.Time; + set + { + DeleteObject(); + wrapped.Time = value; + } + } + + public int _lineIndex + { + get => wrapped.LineIndex; + set + { + DeleteObject(); + wrapped.LineIndex = value; + } + } + + public int _lineLayer + { + get => wrapped.LineLayer; + set + { + DeleteObject(); + wrapped.LineLayer = value; + } + } + + public int _cutDirection + { + get => wrapped.CutDirection; + set + { + DeleteObject(); + wrapped.CutDirection = value; + } + } + + public int _type + { + get => wrapped.Color; + set + { + DeleteObject(); + wrapped.Color = value; + } + } + public float b { get => wrapped.Time; @@ -71,13 +121,13 @@ public ColorNote(Engine engine, BeatmapColorNote note) : base(engine, note) } public ColorNote(Engine engine, ObjectInstance o) : base(engine, new BeatmapColorNote( - (float)GetJsValue(o, "b"), - (int)GetJsValue(o, "x"), - (int)GetJsValue(o, "y"), - (int)GetJsValue(o, "c"), - (int)GetJsValue(o, "d"), - (int)GetJsValue(o, "a"), - GetCustomData(o, "customData") + (float)GetJsValue(o, new string[] { "b", "_time" }), + (int)GetJsValue(o, new string[] { "x", "_lineIndex" }), + (int)GetJsValue(o, new string[] { "y", "_lineLayer" }), + (int)GetJsValue(o, new string[] { "c", "_type" }), + (int)GetJsValue(o, new string[] { "d", "_cutDirection" }), + (int)(GetJsValueOptional(o, "a") ?? 0), + GetCustomData(o, new string[] { "customData", "_customData" }) ), false, GetJsBool(o, "selected")) { spawned = false; diff --git a/Wrappers/V3/Event.cs b/Wrappers/V3/Event.cs index 321050c..9bbc293 100644 --- a/Wrappers/V3/Event.cs +++ b/Wrappers/V3/Event.cs @@ -6,6 +6,46 @@ namespace V3 { class Event : VanillaWrapper { + public float _time + { + get => wrapped.Time; + set + { + DeleteObject(); + wrapped.Time = value; + } + } + + public int _type + { + get => wrapped.Type; + set + { + DeleteObject(); + wrapped.Type = value; + } + } + + public int _value + { + get => wrapped.Value; + set + { + DeleteObject(); + wrapped.Value = value; + } + } + + public float _floatValue + { + get => wrapped.FloatValue; + set + { + DeleteObject(); + wrapped.FloatValue = value; + } + } + public float b { get => wrapped.Time; @@ -51,15 +91,13 @@ public Event(Engine engine, MapEventV3 mapEvent) : base(engine, mapEvent) spawned = true; } - public Event(Engine engine, ObjectInstance o) : base(engine, new MapEventV3(JSONWrapper.dictToJSON(new Dictionary() - { - { "b", (float)GetJsValue(o, "b") }, - { "et", (int)GetJsValue(o, "et") }, - { "i", (int)GetJsValue(o, "i") }, - { "f", (float)GetJsValue(o, "f") }, - { "customData", GetCustomData(o, "customData") } - }) - ), false, GetJsBool(o, "selected")) + public Event(Engine engine, ObjectInstance o) : base(engine, new MapEventV3(new MapEvent( + (float)GetJsValue(o, new string[] { "b", "_time" }), + (int)GetJsValue(o, new string[] { "et", "_type" }), + (int)GetJsValue(o, new string[] { "i", "_value" }), + GetCustomData(o, new string[] { "customData", "_customData" }), + (float)GetJsValue(o, new string[] { "f", "_floatValue" }) + )), false, GetJsBool(o, "selected")) { spawned = false; diff --git a/Wrappers/V3/Wall.cs b/Wrappers/V3/Wall.cs index bcd598a..af02ce9 100644 --- a/Wrappers/V3/Wall.cs +++ b/Wrappers/V3/Wall.cs @@ -6,6 +6,56 @@ namespace V3 { class Wall : VanillaWrapper { + public float _time + { + get => wrapped.Time; + set + { + DeleteObject(); + wrapped.Time = value; + } + } + + public int _lineIndex + { + get => wrapped.LineIndex; + set + { + DeleteObject(); + wrapped.LineIndex = value; + } + } + + public int _type + { + get => wrapped.Type; + set + { + DeleteObject(); + wrapped.Type = value; + } + } + + public float _duration + { + get => wrapped.Duration; + set + { + DeleteObject(); + wrapped.Duration = value; + } + } + + public int _width + { + get => wrapped.Width; + set + { + DeleteObject(); + wrapped.Width = value; + } + } + public float b { get => wrapped.Time; @@ -71,15 +121,15 @@ public Wall(Engine engine, BeatmapObstacleV3 wall) : base(engine, wall) spawned = true; } - public Wall(Engine engine, ObjectInstance o) : base(engine, new BeatmapObstacleV3(JSONWrapper.castObjToJSON(new Dictionary() + public Wall(Engine engine, ObjectInstance o) : base(engine, new BeatmapObstacleV3(JSONWrapper.dictToJSON(new Dictionary() { - { "b", (float)GetJsValue(o, "b") }, - { "x", (int)GetJsValue(o, "x") }, - { "y", (int)GetJsValue(o, "y") }, - { "d", (float)GetJsValue(o, "d") }, - { "w", (int)GetJsValue(o, "w") }, - { "h", (int)GetJsValue(o, "h") }, - { "customData", GetCustomData(o, "customData") } + { "b", (float)GetJsValue(o, new string[] { "b", "_time" }) }, + { "x", (int)GetJsValue(o, new string[] { "x", "_lineIndex" }) }, + { "y", (int)(GetJsExist(o, "_type") ? (GetJsValue(o, "_type") == 0 ? 0 : 2) : GetJsValue(o, "y")) }, + { "d", (float)GetJsValue(o, new string[] { "d", "_duration" }) }, + { "w", (int)GetJsValue(o, new string[] { "w", "_width" }) }, + { "h", (int)(GetJsExist(o, "_type") ? (GetJsValue(o, "_type") == 0 ? 5 : 3) : GetJsValue(o, "h")) }, + { "customData", GetCustomData(o, new string[] { "customData", "_customData" }) } })), false, GetJsBool(o, "selected")) { spawned = false; diff --git a/Wrappers/Wrapper.cs b/Wrappers/Wrapper.cs index 1d0ed94..c70c234 100644 --- a/Wrappers/Wrapper.cs +++ b/Wrappers/Wrapper.cs @@ -32,6 +32,19 @@ protected static double GetJsValue(ObjectInstance o, string key) return (double)value.ToObject(); } + protected static double? GetJsValue(ObjectInstance o, string[] key) + { + foreach (string k in key) + { + if (o.TryGetValue(k, out var value)) + { + return (double)value.ToObject(); + } + } + + return null; + } + protected static double? GetJsValueOptional(ObjectInstance o, string key) { if (o.TryGetValue(key, out var value)) @@ -42,6 +55,11 @@ protected static double GetJsValue(ObjectInstance o, string key) return null; } + protected static bool GetJsExist(ObjectInstance o, string key) + { + return o.IsPrimitive(); + } + protected static string GetJsString(ObjectInstance o, string key) { o.TryGetValue(key, out var value); @@ -74,6 +92,27 @@ protected static JSONNode GetCustomData(ObjectInstance o, string key = "_customD return JSON.Parse(customData.AsString()); } + protected static JSONNode GetCustomData(ObjectInstance o, string[] key) + { + foreach(var k in key) + { + var engine = new Engine(); + + var customData = engine + .SetValue("data", o) + .Evaluate($"JSON.stringify(data.{k});"); + + if (customData.IsUndefined()) + { + continue; + } + + return JSON.Parse(customData.AsString()); + } + + return null; + } + public abstract bool SpawnObject(BeatmapObjectContainerCollection collection); internal abstract bool DeleteObject(); From 1370970b93727c83300ea7974f18303284aab1c1 Mon Sep 17 00:00:00 2001 From: KivalEvan <5645391+KivalEvan@users.noreply.github.com> Date: Sat, 24 Sep 2022 06:41:31 -0700 Subject: [PATCH 09/26] Fixed v3 wall, arc, and chain not getting custom data. --- Wrappers/JSONWrapper.cs | 2 +- Wrappers/V3/Arc.cs | 3 ++- Wrappers/V3/Chain.cs | 3 ++- Wrappers/V3/Wall.cs | 4 +++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Wrappers/JSONWrapper.cs b/Wrappers/JSONWrapper.cs index dfbb96c..00d6bb7 100644 --- a/Wrappers/JSONWrapper.cs +++ b/Wrappers/JSONWrapper.cs @@ -139,7 +139,7 @@ public static JSONNode dictToJSON(ExpandoObject o) return node; } - public static JSONNode dictToJSON(Dictionary dict) + public static JSONNode dictToJSON(Dictionary dict) { var node = new JSONObject(); diff --git a/Wrappers/V3/Arc.cs b/Wrappers/V3/Arc.cs index ddba878..d84e39a 100644 --- a/Wrappers/V3/Arc.cs +++ b/Wrappers/V3/Arc.cs @@ -132,7 +132,7 @@ public Arc(Engine engine, BeatmapArc arc) : base(engine, arc) spawned = true; } - public Arc(Engine engine, ObjectInstance o) : base(engine, new BeatmapArc(JSONWrapper.dictToJSON(new Dictionary() + public Arc(Engine engine, ObjectInstance o) : base(engine, new BeatmapArc(JSONWrapper.dictToJSON(new Dictionary() { { "b", (float)GetJsValue(o, "b") }, { "c", (int)GetJsValue(o, "c") }, @@ -150,6 +150,7 @@ public Arc(Engine engine, BeatmapArc arc) : base(engine, arc) })), false, GetJsBool(o, "selected")) { spawned = false; + wrapped.CustomData = GetCustomData(o, new string[] { "customData", "_customData" }); DeleteObject(); } diff --git a/Wrappers/V3/Chain.cs b/Wrappers/V3/Chain.cs index 3cfd8e7..11327d3 100644 --- a/Wrappers/V3/Chain.cs +++ b/Wrappers/V3/Chain.cs @@ -111,7 +111,7 @@ public Chain(Engine engine, BeatmapChain chain) : base(engine, chain) spawned = true; } - public Chain(Engine engine, ObjectInstance o) : base(engine, new BeatmapChain(JSONWrapper.dictToJSON(new Dictionary() + public Chain(Engine engine, ObjectInstance o) : base(engine, new BeatmapChain(JSONWrapper.dictToJSON(new Dictionary() { { "b", (float)GetJsValue(o, "b") }, { "c", (int)GetJsValue(o, "c") }, @@ -127,6 +127,7 @@ public Chain(Engine engine, BeatmapChain chain) : base(engine, chain) })), false, GetJsBool(o, "selected")) { spawned = false; + wrapped.CustomData = GetCustomData(o, new string[] { "customData", "_customData" }); DeleteObject(); } diff --git a/Wrappers/V3/Wall.cs b/Wrappers/V3/Wall.cs index af02ce9..6d50b26 100644 --- a/Wrappers/V3/Wall.cs +++ b/Wrappers/V3/Wall.cs @@ -1,6 +1,7 @@ using Jint; using Jint.Native.Object; using System.Collections.Generic; +using UnityEngine; namespace V3 { @@ -121,7 +122,7 @@ public Wall(Engine engine, BeatmapObstacleV3 wall) : base(engine, wall) spawned = true; } - public Wall(Engine engine, ObjectInstance o) : base(engine, new BeatmapObstacleV3(JSONWrapper.dictToJSON(new Dictionary() + public Wall(Engine engine, ObjectInstance o) : base(engine, new BeatmapObstacleV3(JSONWrapper.dictToJSON(new Dictionary() { { "b", (float)GetJsValue(o, new string[] { "b", "_time" }) }, { "x", (int)GetJsValue(o, new string[] { "x", "_lineIndex" }) }, @@ -133,6 +134,7 @@ public Wall(Engine engine, BeatmapObstacleV3 wall) : base(engine, wall) })), false, GetJsBool(o, "selected")) { spawned = false; + wrapped.CustomData = GetCustomData(o, new string[] { "customData", "_customData" }); DeleteObject(); } From 40aaa9373ecb9ef1f1c5760e348ceec856d4ee8d Mon Sep 17 00:00:00 2001 From: Kival Evan <5645391+KivalEvan@users.noreply.github.com> Date: Fri, 14 Oct 2022 22:27:20 +0800 Subject: [PATCH 10/26] Update for experimental v3 build --- CMJS.cs | 75 ++++++++++++++++++--------------- Checks/Check.cs | 10 +++-- Checks/CheckResult.cs | 11 ++--- Checks/ExternalJS.cs | 85 ++++++++++++++++---------------------- Checks/StackedNotes.cs | 6 ++- Checks/VisionBlocks.cs | 24 ++++++----- ErrorChecker.csproj | 2 +- Wrappers/V2/BpmChange.cs | 13 +++--- Wrappers/V2/CustomEvent.cs | 11 +++-- Wrappers/V2/Event.cs | 16 ++++--- Wrappers/V2/Note.cs | 29 +++++++------ Wrappers/V2/Wall.cs | 41 ++++++++++++++---- Wrappers/V3/Arc.cs | 39 +++++++++-------- Wrappers/V3/BombNote.cs | 21 ++++++---- Wrappers/V3/BpmChange.cs | 21 ++++++---- Wrappers/V3/Chain.cs | 35 +++++++++------- Wrappers/V3/ColorNote.cs | 29 +++++++------ Wrappers/V3/CustomEvent.cs | 17 ++++---- Wrappers/V3/Event.cs | 13 +++--- Wrappers/V3/Wall.cs | 43 ++++++++++++++----- Wrappers/VanillaWrapper.cs | 3 +- Wrappers/Wrapper.cs | 8 ++-- 22 files changed, 318 insertions(+), 234 deletions(-) diff --git a/CMJS.cs b/CMJS.cs index 26eae32..704059f 100644 --- a/CMJS.cs +++ b/CMJS.cs @@ -3,6 +3,14 @@ using System.IO; using System.Linq; using System.Reflection; +using Beatmap.Base; +using Beatmap.Base.Customs; +using Beatmap.Containers; +using Beatmap.Enums; +using Beatmap.V2; +using Beatmap.V2.Customs; +using Beatmap.V3; +using Beatmap.V3.Customs; using HarmonyLib; using UnityEngine; using UnityEngine.SceneManagement; @@ -11,13 +19,13 @@ [Plugin("CM JS")] public class CMJS { - private NotesContainer notesContainer; - private ChainsContainer chainsContainer; - private ArcsContainer arcsContainer; - private ObstaclesContainer wallsContainer; - private EventsContainer eventsContainer; - private CustomEventsContainer customEventsContainer; - private BPMChangesContainer bpmChangesContainer; + private NoteGridContainer notesContainer; + private ChainGridContainer chainsContainer; + private ArcGridContainer arcsContainer; + private ObstacleGridContainer wallsContainer; + private EventGridContainer eventsContainer; + private CustomEventGridContainer customEventsContainer; + private BPMChangeGridContainer bpmChangesContainer; private List checks = new List() { new VisionBlocks(), @@ -58,16 +66,16 @@ private void SceneLoaded(Scene arg0, LoadSceneMode arg1) { if (arg0.buildIndex == 3) // Mapper scene { - notesContainer = UnityEngine.Object.FindObjectOfType(); - arcsContainer = UnityEngine.Object.FindObjectOfType(); - chainsContainer = UnityEngine.Object.FindObjectOfType(); - wallsContainer = UnityEngine.Object.FindObjectOfType(); - eventsContainer = UnityEngine.Object.FindObjectOfType(); - customEventsContainer = UnityEngine.Object.FindObjectOfType(); - bpmChangesContainer = UnityEngine.Object.FindObjectOfType(); + notesContainer = UnityEngine.Object.FindObjectOfType(); + arcsContainer = UnityEngine.Object.FindObjectOfType(); + chainsContainer = UnityEngine.Object.FindObjectOfType(); + wallsContainer = UnityEngine.Object.FindObjectOfType(); + eventsContainer = UnityEngine.Object.FindObjectOfType(); + customEventsContainer = UnityEngine.Object.FindObjectOfType(); + bpmChangesContainer = UnityEngine.Object.FindObjectOfType(); var mapEditorUI = UnityEngine.Object.FindObjectOfType(); - atsc = BeatmapObjectContainerCollection.GetCollectionForType(BeatmapObject.ObjectType.Note).AudioTimeSyncController; + atsc = BeatmapObjectContainerCollection.GetCollectionForType(ObjectType.Note).AudioTimeSyncController; // Add button to UI ui.AddButton(mapEditorUI); @@ -76,14 +84,14 @@ private void SceneLoaded(Scene arg0, LoadSceneMode arg1) public void CheckErrors(Check check) { - bool isV3 = BeatSaberSongContainer.Instance.Map.Version.StartsWith("3"); + bool isV3 = Settings.Instance.Load_MapV3; if (errors != null) { // Remove error outline from old errors foreach (var block in errors.all) { - if (BeatmapObjectContainerCollection.GetCollectionForType(BeatmapObject.ObjectType.Note).LoadedContainers.TryGetValue(block.note, out BeatmapObjectContainer container)) + if (BeatmapObjectContainerCollection.GetCollectionForType(ObjectType.Note).LoadedContainers.TryGetValue(block.note, out ObjectContainer container)) { container.OutlineVisible = SelectionController.IsObjectSelected(container.ObjectData); container.SetOutlineColor(SelectionController.SelectedColor, false); @@ -110,29 +118,30 @@ public void CheckErrors(Check check) if (isV3) { - var allNotes = notesContainer.LoadedObjects.Where(it => it is BeatmapColorNote).Cast().OrderBy(it => it.Time).ToList(); - var allBombs = notesContainer.LoadedObjects.Where(it => it is BeatmapBombNote).Cast().OrderBy(it => it.Time).ToList(); - var allArcs = arcsContainer.LoadedObjects.Cast().OrderBy(it => it.Time).ToList(); - var allChains = chainsContainer.LoadedObjects.Cast().OrderBy(it => it.Time).ToList(); - var allWalls = wallsContainer.LoadedObjects.Where(it => it is BeatmapObstacleV3).Cast().OrderBy(it => it.Time).ToList(); - var allEvents = eventsContainer.LoadedObjects.Where(it => it is MapEventV3).Cast().OrderBy(it => it.Time).ToList(); - var allCustomEvents = customEventsContainer.LoadedObjects.Cast().OrderBy(it => it.Time).ToList(); - var allBpmChanges = bpmChangesContainer.LoadedObjects.Cast().OrderBy(it => it.Time).ToList(); + // TODO: since containers has multiple different object, check events and notes + var allNotes = notesContainer.LoadedObjects.Where(it => it is V3ColorNote).Cast().OrderBy(it => it.Time).ToList(); + var allBombs = notesContainer.LoadedObjects.Where(it => it is V3BombNote).Cast().OrderBy(it => it.Time).ToList(); + var allArcs = arcsContainer.LoadedObjects.Cast().OrderBy(it => it.Time).ToList(); + var allChains = chainsContainer.LoadedObjects.Cast().OrderBy(it => it.Time).ToList(); + var allWalls = wallsContainer.LoadedObjects.Cast().OrderBy(it => it.Time).ToList(); + var allEvents = eventsContainer.LoadedObjects.Cast().OrderBy(it => it.Time).ToList(); + var allCustomEvents = customEventsContainer.LoadedObjects.Cast().OrderBy(it => it.Time).ToList(); + var allBpmChanges = bpmChangesContainer.LoadedObjects.Cast().OrderBy(it => it.Time).ToList(); errors = check.PerformCheck(allNotes, allBombs, allArcs, allChains, allEvents, allWalls, allCustomEvents, allBpmChanges, vals).Commit(); } else { - var allNotes = notesContainer.LoadedObjects.Cast().OrderBy(it => it.Time).ToList(); - var allWalls = wallsContainer.LoadedObjects.Cast().OrderBy(it => it.Time).ToList(); - var allEvents = eventsContainer.LoadedObjects.Cast().OrderBy(it => it.Time).ToList(); - var allCustomEvents = customEventsContainer.LoadedObjects.Cast().OrderBy(it => it.Time).ToList(); - var allBpmChanges = bpmChangesContainer.LoadedObjects.Cast().OrderBy(it => it.Time).ToList(); + var allNotes = notesContainer.LoadedObjects.Cast().OrderBy(it => it.Time).ToList(); + var allWalls = wallsContainer.LoadedObjects.Cast().OrderBy(it => it.Time).ToList(); + var allEvents = eventsContainer.LoadedObjects.Cast().OrderBy(it => it.Time).ToList(); + var allCustomEvents = customEventsContainer.LoadedObjects.Cast().OrderBy(it => it.Time).ToList(); + var allBpmChanges = bpmChangesContainer.LoadedObjects.Cast().OrderBy(it => it.Time).ToList(); errors = check.PerformCheck(allNotes, allEvents, allWalls, allCustomEvents, allBpmChanges, vals).Commit(); } // Highlight blocks in loaded containers in case we don't scrub far enough with MoveToTimeInBeats to load them foreach (var block in errors.errors) { - if (BeatmapObjectContainerCollection.GetCollectionForType(BeatmapObject.ObjectType.Note).LoadedContainers.TryGetValue(block.note, out BeatmapObjectContainer container)) + if (BeatmapObjectContainerCollection.GetCollectionForType(ObjectType.Note).LoadedContainers.TryGetValue(block.note, out ObjectContainer container)) { container.SetOutlineColor(Color.red); } @@ -140,7 +149,7 @@ public void CheckErrors(Check check) foreach (var block in errors.warnings) { - if (BeatmapObjectContainerCollection.GetCollectionForType(BeatmapObject.ObjectType.Note).LoadedContainers.TryGetValue(block.note, out BeatmapObjectContainer container)) + if (BeatmapObjectContainerCollection.GetCollectionForType(ObjectType.Note).LoadedContainers.TryGetValue(block.note, out ObjectContainer container)) { container.SetOutlineColor(Color.yellow); } @@ -199,7 +208,7 @@ public void NextBlock(int offset = 1) } [ObjectLoaded] - private void ObjectLoaded(BeatmapObjectContainer container) + private void ObjectLoaded(ObjectContainer container) { if (container.ObjectData == null || errors == null) return; diff --git a/Checks/Check.cs b/Checks/Check.cs index 2129891..c36b8c7 100644 --- a/Checks/Check.cs +++ b/Checks/Check.cs @@ -1,5 +1,7 @@ using System; using System.Collections.Generic; +using Beatmap.Base; +using Beatmap.Base.Customs; public abstract class Check { @@ -18,12 +20,12 @@ protected Check() : this("") } - protected virtual CheckResult PerformCheck(List notes, List events, List walls, List customEvents, List bpmChanges) + protected virtual CheckResult PerformCheck(List notes, List events, List walls, List customEvents, List bpmChanges) { throw new ArgumentException("Wrong number of parameters"); } - public virtual CheckResult PerformCheck(List notes, List events, List walls, List customEvents, List bpmChanges, params IParamValue[] vals) + public virtual CheckResult PerformCheck(List notes, List events, List walls, List customEvents, List bpmChanges, params IParamValue[] vals) { if (vals.Length == 0 && Params.Count == 0) { @@ -32,12 +34,12 @@ public virtual CheckResult PerformCheck(List notes, List throw new ArgumentException("Wrong number of parameters"); } - protected virtual CheckResult PerformCheck(List notes, List bombs, List arcs, List chains, List events, List walls, List customEvents, List bpmChanges) + protected virtual CheckResult PerformCheck(List notes, List bombs, List arcs, List chains, List events, List walls, List customEvents, List bpmChanges) { throw new ArgumentException("Wrong number of parameters"); } - public virtual CheckResult PerformCheck(List notes, List bombs, List arcs, List chains, List events, List walls, List customEvents, List bpmChanges, params IParamValue[] vals) + public virtual CheckResult PerformCheck(List notes, List bombs, List arcs, List chains, List events, List walls, List customEvents, List bpmChanges, params IParamValue[] vals) { if (vals.Length == 0 && Params.Count == 0) { diff --git a/Checks/CheckResult.cs b/Checks/CheckResult.cs index a32f559..371399c 100644 --- a/Checks/CheckResult.cs +++ b/Checks/CheckResult.cs @@ -1,13 +1,14 @@ using System.Collections.Generic; using System.Linq; +using Beatmap.Base; public class CheckResult { public class Problem { - public BeatmapNote note; + public BaseNote note; public string reason; - public Problem(BeatmapNote note, string reason) + public Problem(BaseNote note, string reason) { this.note = note; this.reason = reason; @@ -30,17 +31,17 @@ public void Clear() all = null; } - public void Add(BeatmapNote note, string reason = "") + public void Add(BaseNote note, string reason = "") { AddError(note, reason); } - public void AddError(BeatmapNote note, string reason = "") + public void AddError(BaseNote note, string reason = "") { errors.Add(new Problem(note, reason)); } - public void AddWarning(BeatmapNote note, string reason = "") + public void AddWarning(BaseNote note, string reason = "") { warnings.Add(new Problem(note, reason)); } diff --git a/Checks/ExternalJS.cs b/Checks/ExternalJS.cs index b3d1a87..4e7c427 100644 --- a/Checks/ExternalJS.cs +++ b/Checks/ExternalJS.cs @@ -12,6 +12,13 @@ using System.Linq; using System.Reflection; using System.Threading; +using Beatmap.Base; +using Beatmap.Base.Customs; +using Beatmap.Enums; +using Beatmap.V2; +using Beatmap.V2.Customs; +using Beatmap.V3; +using Beatmap.V3.Customs; using Esprima; using UnityEngine; @@ -205,7 +212,7 @@ public override void OnSelected() if (!valid) LoadJS(); } - private BeatmapNote FromDynamic(dynamic note, List notes) + private BaseNote FromDynamic(dynamic note, List notes) { float _time = Convert.ChangeType(note._time, typeof(float)); int _lineIndex = Convert.ChangeType(note._lineIndex, typeof(int)); @@ -213,35 +220,13 @@ private BeatmapNote FromDynamic(dynamic note, List notes) int _type = Convert.ChangeType(note._type, typeof(int)); int _cutDirection = Convert.ChangeType(note._cutDirection, typeof(int)); - return notes.Find(it => - { - return Mathf.Approximately(_time, it.Time) && - _lineIndex == it.LineIndex && - _lineLayer == it.LineLayer && - _type == it.Type && - _cutDirection == it.CutDirection; - }); + return notes.Find(it => Mathf.Approximately(_time, it.Time) && + _lineIndex == it.PosX && + _lineLayer == it.PosY && + _type == it.Type && + _cutDirection == it.CutDirection); } - private BeatmapColorNote FromDynamic(dynamic note, List notes) - { - float b = Convert.ChangeType(note.b, typeof(float)); - int x = Convert.ChangeType(note.x, typeof(int)); - int y = Convert.ChangeType(note.y, typeof(int)); - int c = Convert.ChangeType(note.c, typeof(int)); - int d = Convert.ChangeType(note.d, typeof(int)); - int a = Convert.ChangeType(note.a, typeof(int)); - - return notes.Find(it => - { - return Mathf.Approximately(b, it.Time) && - x == it.LineIndex && - y == it.LineLayer && - c == it.Type && - d == it.CutDirection && - a == it.AngleOffset; - }); - } - + class MapData { public float currentBPM { get; private set; } public float songBPM { get; private set; } @@ -265,14 +250,14 @@ public MapData(float currentBPM, float songBPM, float NJS, float offset, string } } - public override CheckResult PerformCheck(List notes, List events, List walls, List customEvents, List bpmChanges, params IParamValue[] vals) + public override CheckResult PerformCheck(List notes, List events, List walls, List customEvents, List bpmChanges, params IParamValue[] vals) { result.Clear(); - var atsc = BeatmapObjectContainerCollection.GetCollectionForType(BeatmapObject.ObjectType.Note).AudioTimeSyncController; + var atsc = BeatmapObjectContainerCollection.GetCollectionForType(ObjectType.Note).AudioTimeSyncController; var currentBeat = atsc.CurrentBeat; - var collection = BeatmapObjectContainerCollection.GetCollectionForType(BeatmapObject.ObjectType.BpmChange); + var collection = BeatmapObjectContainerCollection.GetCollectionForType(ObjectType.BpmChange); var lastBPMChange = collection.FindLastBpm(atsc.CurrentBeat); var currentBPM = lastBPMChange?.Bpm ?? atsc.Song.BeatsPerMinute; @@ -356,11 +341,11 @@ public override CheckResult PerformCheck(List notes, List SelectionController.DeselectAll(); var actions = new List(); - actions.AddRange(Reconcile(originalNotes, engine.GetValue("notes").AsArray(), notes, i => new V2.Note(engine, i), BeatmapObject.ObjectType.Note)); - actions.AddRange(Reconcile(originalWalls, engine.GetValue("walls").AsArray(), walls, i => new V2.Wall(engine, i), BeatmapObject.ObjectType.Obstacle)); - actions.AddRange(Reconcile(originalEvents, engine.GetValue("events").AsArray(), events, i => new V2.Event(engine, i), BeatmapObject.ObjectType.Event)); - actions.AddRange(Reconcile(originalCustomEvents, engine.GetValue("customEvents").AsArray(), customEvents, i => new V2.CustomEvent(engine, i), BeatmapObject.ObjectType.CustomEvent)); - actions.AddRange(Reconcile(originalBpmChanges, engine.GetValue("bpmChanges").AsArray(), bpmChanges, i => new V2.BpmChange(engine, i), BeatmapObject.ObjectType.BpmChange)); + actions.AddRange(Reconcile(originalNotes, engine.GetValue("notes").AsArray(), notes, i => new V2.Note(engine, i), ObjectType.Note)); + actions.AddRange(Reconcile(originalWalls, engine.GetValue("walls").AsArray(), walls, i => new V2.Wall(engine, i), ObjectType.Obstacle)); + actions.AddRange(Reconcile(originalEvents, engine.GetValue("events").AsArray(), events, i => new V2.Event(engine, i), ObjectType.Event)); + actions.AddRange(Reconcile(originalCustomEvents, engine.GetValue("customEvents").AsArray(), customEvents, i => new V2.CustomEvent(engine, i), ObjectType.CustomEvent)); + actions.AddRange(Reconcile(originalBpmChanges, engine.GetValue("bpmChanges").AsArray(), bpmChanges, i => new V2.BpmChange(engine, i), ObjectType.BpmChange)); SelectionController.SelectionChangedEvent?.Invoke(); @@ -376,14 +361,14 @@ public override CheckResult PerformCheck(List notes, List return result; } - public override CheckResult PerformCheck(List notes, List bombs, List arcs, List chains, List events, List walls, List customEvents, List bpmChanges, params IParamValue[] vals) + public override CheckResult PerformCheck(List notes, List bombs, List arcs, List chains, List events, List walls, List customEvents, List bpmChanges, params IParamValue[] vals) { result.Clear(); - var atsc = BeatmapObjectContainerCollection.GetCollectionForType(BeatmapObject.ObjectType.Note).AudioTimeSyncController; + var atsc = BeatmapObjectContainerCollection.GetCollectionForType(ObjectType.Note).AudioTimeSyncController; var currentBeat = atsc.CurrentBeat; - var collection = BeatmapObjectContainerCollection.GetCollectionForType(BeatmapObject.ObjectType.BpmChange); + var collection = BeatmapObjectContainerCollection.GetCollectionForType(ObjectType.BpmChange); var lastBPMChange = collection.FindLastBpm(atsc.CurrentBeat); var currentBPM = lastBPMChange?.Bpm ?? atsc.Song.BeatsPerMinute; @@ -476,14 +461,14 @@ public override CheckResult PerformCheck(List notes, List(); - actions.AddRange(Reconcile(originalNotes, engine.GetValue("notes").AsArray(), notes, i => new V3.ColorNote(engine, i), BeatmapObject.ObjectType.Note)); - actions.AddRange(Reconcile(originalBombs, engine.GetValue("bombs").AsArray(), bombs, i => new V3.BombNote(engine, i), BeatmapObject.ObjectType.Note)); - actions.AddRange(Reconcile(originalArcs, engine.GetValue("arcs").AsArray(), arcs, i => new V3.Arc(engine, i), BeatmapObject.ObjectType.Arc)); - actions.AddRange(Reconcile(originalChains, engine.GetValue("chains").AsArray(), chains, i => new V3.Chain(engine, i), BeatmapObject.ObjectType.Chain)); - actions.AddRange(Reconcile(originalWalls, engine.GetValue("walls").AsArray(), walls, i => new V3.Wall(engine, i), BeatmapObject.ObjectType.Obstacle)); - actions.AddRange(Reconcile(originalEvents, engine.GetValue("events").AsArray(), events, i => new V3.Event(engine, i), BeatmapObject.ObjectType.Event)); - actions.AddRange(Reconcile(originalCustomEvents, engine.GetValue("customEvents").AsArray(), customEvents, i => new V3.CustomEvent(engine, i), BeatmapObject.ObjectType.CustomEvent)); - actions.AddRange(Reconcile(originalBpmChanges, engine.GetValue("bpmChanges").AsArray(), bpmChanges, i => new V3.BpmChange(engine, i), BeatmapObject.ObjectType.BpmChange)); + actions.AddRange(Reconcile(originalNotes, engine.GetValue("notes").AsArray(), notes, i => new V3.ColorNote(engine, i), ObjectType.Note)); + actions.AddRange(Reconcile(originalBombs, engine.GetValue("bombs").AsArray(), bombs, i => new V3.BombNote(engine, i), ObjectType.Note)); + actions.AddRange(Reconcile(originalArcs, engine.GetValue("arcs").AsArray(), arcs, i => new V3.Arc(engine, i), ObjectType.Arc)); + actions.AddRange(Reconcile(originalChains, engine.GetValue("chains").AsArray(), chains, i => new V3.Chain(engine, i), ObjectType.Chain)); + actions.AddRange(Reconcile(originalWalls, engine.GetValue("walls").AsArray(), walls, i => new V3.Wall(engine, i), ObjectType.Obstacle)); + actions.AddRange(Reconcile(originalEvents, engine.GetValue("events").AsArray(), events, i => new V3.Event(engine, i), ObjectType.Event)); + actions.AddRange(Reconcile(originalCustomEvents, engine.GetValue("customEvents").AsArray(), customEvents, i => new V3.CustomEvent(engine, i), ObjectType.CustomEvent)); + actions.AddRange(Reconcile(originalBpmChanges, engine.GetValue("bpmChanges").AsArray(), bpmChanges, i => new V3.BpmChange(engine, i), ObjectType.BpmChange)); SelectionController.SelectionChangedEvent?.Invoke(); @@ -500,7 +485,7 @@ public override CheckResult PerformCheck(List notes, List Reconcile(IEnumerable original, ArrayInstance noteArr, List notes, Func inst, BeatmapObject.ObjectType type) where U : Wrapper where T : BeatmapObject + private List Reconcile(IEnumerable original, ArrayInstance noteArr, List notes, Func inst, ObjectType type) where U : Wrapper where T : BaseObject { TimeLog("Reconcile " + original.GetType()); @@ -580,7 +565,7 @@ private List Reconcile(IEnumerable original, ArrayInstan } else { - beatmapActions.Add(new BeatmapObjectPlacementAction(note.wrapped, Enumerable.Empty(), "Script spawned object")); + beatmapActions.Add(new BeatmapObjectPlacementAction(note.wrapped, Enumerable.Empty(), "Script spawned object")); } } diff --git a/Checks/StackedNotes.cs b/Checks/StackedNotes.cs index 2330d64..681b719 100644 --- a/Checks/StackedNotes.cs +++ b/Checks/StackedNotes.cs @@ -1,5 +1,7 @@ using System; using System.Collections.Generic; +using Beatmap.Base; +using Beatmap.Base.Customs; class StackedNotes : Check { @@ -7,7 +9,7 @@ public StackedNotes() : base("Stacked Notes") { } - protected override CheckResult PerformCheck(List notes, List events, List walls, List customEvents, List bpmChanges) + protected override CheckResult PerformCheck(List notes, List events, List walls, List customEvents, List bpmChanges) { result.Clear(); @@ -23,7 +25,7 @@ protected override CheckResult PerformCheck(List notes, List notes, List events, List walls, List customEvents, List bpmChanges, params IParamValue[] vals) + public override CheckResult PerformCheck(List notes, List events, List walls, List customEvents, List bpmChanges, params IParamValue[] vals) { if (vals.Length > 1) { @@ -18,15 +20,15 @@ public override CheckResult PerformCheck(List notes, List throw new ArgumentException("Wrong number of parameters"); } - public CheckResult PerformCheck(List notes, float minTime, float maxTime) + public CheckResult PerformCheck(List notes, float minTime, float maxTime) { result.Clear(); float visionBlockLeft = -1f; float visionBlockRight = -1f; - BeatmapNote visionBlockLeftNote = null; - BeatmapNote visionBlockRightNote = null; + BaseNote visionBlockLeftNote = null; + BaseNote visionBlockRightNote = null; if (notes.Count > 0) { visionBlockLeftNote = notes[0]; @@ -36,13 +38,13 @@ public CheckResult PerformCheck(List notes, float minTime, float ma foreach (var note in notes) { if (note.Time - visionBlockLeft <= maxTime) { - if (note.LineIndex < 2 && note.Time - visionBlockLeft > minTime) + if (note.PosX < 2 && note.Time - visionBlockLeft > minTime) { result.Add(visionBlockLeftNote, "Blocks vision of upcoming note on the left"); result.AddWarning(note, "Is blocked"); } - if (note.LineLayer == 1 && note.LineIndex == 1) + if (note.PosY == 1 && note.PosX == 1) { result.Add(visionBlockLeftNote, "Blocks vision of upcoming note on the left"); result.AddWarning(note, "Is blocked"); @@ -51,27 +53,27 @@ public CheckResult PerformCheck(List notes, float minTime, float ma if (note.Time - visionBlockRight <= maxTime) { - if (note.LineIndex > 1 && note.Time - visionBlockRight > minTime) + if (note.PosX > 1 && note.Time - visionBlockRight > minTime) { result.Add(visionBlockRightNote, "Blocks vision of upcoming note on the right"); result.AddWarning(note, "Is blocked"); } - if (note.LineLayer == 1 && note.LineIndex == 2 && note.Time - visionBlockLeft <= maxTime) + if (note.PosY == 1 && note.PosX == 2 && note.Time - visionBlockLeft <= maxTime) { result.Add(visionBlockRightNote, "Blocks vision of upcoming note on the right"); result.AddWarning(note, "Is blocked"); } } - if (note.Type != 3 && note.LineLayer == 1) + if (note.Type != 3 && note.PosY == 1) { - if (note.LineIndex == 1) + if (note.PosX == 1) { visionBlockLeft = note.Time; visionBlockLeftNote = note; } - else if (note.LineIndex == 2) + else if (note.PosX == 2) { visionBlockRight = note.Time; visionBlockRightNote = note; diff --git a/ErrorChecker.csproj b/ErrorChecker.csproj index dea0058..918663b 100644 --- a/ErrorChecker.csproj +++ b/ErrorChecker.csproj @@ -6,7 +6,7 @@ - F:\Programs\CM v3 + C:\Users\mnaba\Build\CM Dev Debug AnyCPU {600D3953-D125-4C0F-A5CF-0E3906D6B6F6} diff --git a/Wrappers/V2/BpmChange.cs b/Wrappers/V2/BpmChange.cs index 2940221..4f2b6e2 100644 --- a/Wrappers/V2/BpmChange.cs +++ b/Wrappers/V2/BpmChange.cs @@ -1,9 +1,12 @@ -using Jint; +using Beatmap.Base.Customs; +using Beatmap.Enums; +using Beatmap.V2.Customs; +using Jint; using Jint.Native.Object; namespace V2 { - class BpmChange : Wrapper + class BpmChange : Wrapper { public float _time { @@ -45,12 +48,12 @@ public float _metronomeOffset } } - public BpmChange(Engine engine, BeatmapBPMChange bpmChange) : base(engine, bpmChange) + public BpmChange(Engine engine, BaseBpmChange bpmChange) : base(engine, bpmChange) { spawned = true; } - public BpmChange(Engine engine, ObjectInstance o) : base(engine, new BeatmapBPMChange( + public BpmChange(Engine engine, ObjectInstance o) : base(engine, new V2BpmChange( (float)GetJsValue(o, "_BPM"), (float)GetJsValue(o, "_time") ) @@ -78,7 +81,7 @@ internal override bool DeleteObject() { if (!spawned) return false; - var collection = BeatmapObjectContainerCollection.GetCollectionForType(BeatmapObject.ObjectType.BpmChange); + var collection = BeatmapObjectContainerCollection.GetCollectionForType(ObjectType.BpmChange); collection.DeleteObject(wrapped, false); spawned = false; diff --git a/Wrappers/V2/CustomEvent.cs b/Wrappers/V2/CustomEvent.cs index b2484ce..1657b07 100644 --- a/Wrappers/V2/CustomEvent.cs +++ b/Wrappers/V2/CustomEvent.cs @@ -1,10 +1,13 @@ using System; +using Beatmap.Base.Customs; +using Beatmap.Enums; +using Beatmap.V2.Customs; using Jint; using Jint.Native.Object; namespace V2 { - class CustomEvent : Wrapper + class CustomEvent : Wrapper { public float _time { @@ -39,13 +42,13 @@ public object _data } } - public CustomEvent(Engine engine, BeatmapCustomEvent customEvent) : base(engine, customEvent) + public CustomEvent(Engine engine, BaseCustomEvent customEvent) : base(engine, customEvent) { spawned = true; InitWrapper(); } - public CustomEvent(Engine engine, ObjectInstance o) : base(engine, new BeatmapCustomEvent( + public CustomEvent(Engine engine, ObjectInstance o) : base(engine, new V2CustomEvent( (float)GetJsValue(o, "_time"), GetJsString(o, "_type"), GetCustomData(o, "_data") @@ -71,7 +74,7 @@ internal override bool DeleteObject() { if (!spawned) return false; - var collection = BeatmapObjectContainerCollection.GetCollectionForType(BeatmapObject.ObjectType.Event); + var collection = BeatmapObjectContainerCollection.GetCollectionForType(ObjectType.CustomEvent); collection.DeleteObject(wrapped, false); spawned = false; diff --git a/Wrappers/V2/Event.cs b/Wrappers/V2/Event.cs index 5609ccd..cc97b4b 100644 --- a/Wrappers/V2/Event.cs +++ b/Wrappers/V2/Event.cs @@ -1,9 +1,13 @@ -using Jint; +using Beatmap.Base; +using Beatmap.Enums; +using Beatmap.Shared; +using Beatmap.V2; +using Jint; using Jint.Native.Object; namespace V2 { - class Event : VanillaWrapper + class Event : VanillaWrapper { public float _time { @@ -85,12 +89,12 @@ public float f } } - public Event(Engine engine, MapEvent mapEvent) : base(engine, mapEvent) + public Event(Engine engine, BaseEvent mapEvent) : base(engine, mapEvent) { spawned = true; } - public Event(Engine engine, ObjectInstance o) : base(engine, new MapEvent( + public Event(Engine engine, ObjectInstance o) : base(engine, new V2Event( (float)GetJsValue(o, new string[] { "_time", "b" }), (int)GetJsValue(o, new string[] { "_type", "et" }), (int)GetJsValue(o, new string[] { "_value", "i" }), @@ -109,7 +113,7 @@ public override bool SpawnObject(BeatmapObjectContainerCollection collection) if (wrapped.CustomData != null && wrapped.CustomData["_lightGradient"] != null) { - wrapped.LightGradient = new MapEvent.ChromaGradient(wrapped.CustomData["_lightGradient"]); + wrapped.CustomLightGradient = new ChromaLightGradient(wrapped.CustomData["_lightGradient"]); } collection.SpawnObject(wrapped, false, false); @@ -122,7 +126,7 @@ internal override bool DeleteObject() { if (!spawned) return false; - var collection = BeatmapObjectContainerCollection.GetCollectionForType(BeatmapObject.ObjectType.Event); + var collection = BeatmapObjectContainerCollection.GetCollectionForType(ObjectType.Event); collection.DeleteObject(wrapped, false); spawned = false; diff --git a/Wrappers/V2/Note.cs b/Wrappers/V2/Note.cs index e57b287..96fcc8a 100644 --- a/Wrappers/V2/Note.cs +++ b/Wrappers/V2/Note.cs @@ -1,9 +1,12 @@ -using Jint; +using Beatmap.Base; +using Beatmap.Enums; +using Beatmap.V2; +using Jint; using Jint.Native.Object; namespace V2 { - class Note : VanillaWrapper + class Note : VanillaWrapper { public float _time { @@ -17,21 +20,21 @@ public float _time public int _lineIndex { - get => wrapped.LineIndex; + get => wrapped.PosX; set { DeleteObject(); - wrapped.LineIndex = value; + wrapped.PosX = value; } } public int _lineLayer { - get => wrapped.LineLayer; + get => wrapped.PosY; set { DeleteObject(); - wrapped.LineLayer = value; + wrapped.PosY = value; } } @@ -67,21 +70,21 @@ public float b public int x { - get => wrapped.LineIndex; + get => wrapped.PosX; set { DeleteObject(); - wrapped.LineIndex = value; + wrapped.PosX = value; } } public int y { - get => wrapped.LineLayer; + get => wrapped.PosY; set { DeleteObject(); - wrapped.LineLayer = value; + wrapped.PosY = value; } } @@ -113,12 +116,12 @@ public int d } } - public Note(Engine engine, BeatmapNote note) : base(engine, note) + public Note(Engine engine, BaseNote note) : base(engine, note) { spawned = true; } - public Note(Engine engine, ObjectInstance o) : base(engine, new BeatmapNote( + public Note(Engine engine, ObjectInstance o) : base(engine, new V2Note( (float)GetJsValue(o, new string[] { "_time", "b" }), (int)GetJsValue(o, new string[] { "_lineIndex", "x" }), (int)GetJsValue(o, new string[] { "_lineLayer", "y" }), @@ -146,7 +149,7 @@ internal override bool DeleteObject() { if (!spawned) return false; - var collection = BeatmapObjectContainerCollection.GetCollectionForType(BeatmapObject.ObjectType.Note); + var collection = BeatmapObjectContainerCollection.GetCollectionForType(ObjectType.Note); collection.DeleteObject(wrapped, false); spawned = false; diff --git a/Wrappers/V2/Wall.cs b/Wrappers/V2/Wall.cs index 29ad618..268119f 100644 --- a/Wrappers/V2/Wall.cs +++ b/Wrappers/V2/Wall.cs @@ -1,9 +1,12 @@ -using Jint; +using Beatmap.Base; +using Beatmap.Enums; +using Beatmap.V2; +using Jint; using Jint.Native.Object; namespace V2 { - class Wall : VanillaWrapper + class Wall : VanillaWrapper { public float _time { @@ -17,11 +20,21 @@ public float _time public int _lineIndex { - get => wrapped.LineIndex; + get => wrapped.PosX; set { DeleteObject(); - wrapped.LineIndex = value; + wrapped.PosX = value; + } + } + + public int _lineLayer + { + get => wrapped.PosY; + set + { + DeleteObject(); + wrapped.PosY = value; } } @@ -55,6 +68,16 @@ public int _width } } + public int _height + { + get => wrapped.Height; + set + { + DeleteObject(); + wrapped.Height = value; + } + } + public float b { get => wrapped.Time; @@ -67,11 +90,11 @@ public float b public int x { - get => wrapped.LineIndex; + get => wrapped.PosX; set { DeleteObject(); - wrapped.LineIndex = value; + wrapped.PosX = value; } } @@ -111,12 +134,12 @@ public int h } } - public Wall(Engine engine, BeatmapObstacle wall) : base(engine, wall) + public Wall(Engine engine, BaseObstacle wall) : base(engine, wall) { spawned = true; } - public Wall(Engine engine, ObjectInstance o) : base(engine, new BeatmapObstacle( + public Wall(Engine engine, ObjectInstance o) : base(engine, new V2Obstacle( (float)GetJsValue(o, new string[] { "_time", "b" }), (int)GetJsValue(o, new string[] { "_lineIndex", "x" }), (int)(GetJsValueOptional(o, "_type") ?? (GetJsValue(o, "y") < 2 ? 0 : 1)), @@ -144,7 +167,7 @@ internal override bool DeleteObject() { if (!spawned) return false; - var collection = BeatmapObjectContainerCollection.GetCollectionForType(BeatmapObject.ObjectType.Obstacle); + var collection = BeatmapObjectContainerCollection.GetCollectionForType(ObjectType.Obstacle); collection.DeleteObject(wrapped, false); spawned = false; diff --git a/Wrappers/V3/Arc.cs b/Wrappers/V3/Arc.cs index d84e39a..0e260df 100644 --- a/Wrappers/V3/Arc.cs +++ b/Wrappers/V3/Arc.cs @@ -2,10 +2,13 @@ using Jint.Native.Object; using SimpleJSON; using System.Collections.Generic; +using Beatmap.Base; +using Beatmap.Enums; +using Beatmap.V3; namespace V3 { - class Arc : VanillaWrapper + class Arc : VanillaWrapper { public float b { @@ -29,41 +32,41 @@ public int c public int x { - get => wrapped.X; + get => wrapped.PosX; set { DeleteObject(); - wrapped.X = value; + wrapped.PosX = value; } } public int y { - get => wrapped.Y; + get => wrapped.PosY; set { DeleteObject(); - wrapped.Y = value; + wrapped.PosY = value; } } public int d { - get => wrapped.Direction; + get => wrapped.CutDirection; set { DeleteObject(); - wrapped.Direction = value; + wrapped.CutDirection = value; } } public float mu { - get => wrapped.HeadControlPointLengthMultiplier; + get => wrapped.ControlPointLengthMultiplier; set { DeleteObject(); - wrapped.HeadControlPointLengthMultiplier = value; + wrapped.ControlPointLengthMultiplier = value; } } @@ -79,21 +82,21 @@ public float tb public int tx { - get => wrapped.TailX; + get => wrapped.TailPosX; set { DeleteObject(); - wrapped.TailX = value; + wrapped.TailPosX = value; } } public int ty { - get => wrapped.TailX; + get => wrapped.TailPosY; set { DeleteObject(); - wrapped.TailX = value; + wrapped.TailPosY = value; } } @@ -119,20 +122,20 @@ public float tmu public int m { - get => wrapped.ArcMidAnchorMode; + get => wrapped.MidAnchorMode; set { DeleteObject(); - wrapped.ArcMidAnchorMode = value; + wrapped.MidAnchorMode = value; } } - public Arc(Engine engine, BeatmapArc arc) : base(engine, arc) + public Arc(Engine engine, BaseArc arc) : base(engine, arc) { spawned = true; } - public Arc(Engine engine, ObjectInstance o) : base(engine, new BeatmapArc(JSONWrapper.dictToJSON(new Dictionary() + public Arc(Engine engine, ObjectInstance o) : base(engine, new V3Arc(JSONWrapper.dictToJSON(new Dictionary() { { "b", (float)GetJsValue(o, "b") }, { "c", (int)GetJsValue(o, "c") }, @@ -169,7 +172,7 @@ internal override bool DeleteObject() { if (!spawned) return false; - var collection = BeatmapObjectContainerCollection.GetCollectionForType(BeatmapObject.ObjectType.Note); + var collection = BeatmapObjectContainerCollection.GetCollectionForType(ObjectType.Arc); collection.DeleteObject(wrapped, false); spawned = false; diff --git a/Wrappers/V3/BombNote.cs b/Wrappers/V3/BombNote.cs index bdc4418..132461e 100644 --- a/Wrappers/V3/BombNote.cs +++ b/Wrappers/V3/BombNote.cs @@ -1,9 +1,12 @@ -using Jint; +using Beatmap.Base; +using Beatmap.Enums; +using Beatmap.V3; +using Jint; using Jint.Native.Object; namespace V3 { - class BombNote : VanillaWrapper + class BombNote : VanillaWrapper { public float b { @@ -17,30 +20,30 @@ public float b public int x { - get => wrapped.LineIndex; + get => wrapped.PosX; set { DeleteObject(); - wrapped.LineIndex = value; + wrapped.PosX = value; } } public int y { - get => wrapped.LineLayer; + get => wrapped.PosY; set { DeleteObject(); - wrapped.LineLayer = value; + wrapped.PosY = value; } } - public BombNote(Engine engine, BeatmapBombNote bomb) : base(engine, bomb) + public BombNote(Engine engine, BaseBombNote bomb) : base(engine, bomb) { spawned = true; } - public BombNote(Engine engine, ObjectInstance o) : base(engine, new BeatmapBombNote( + public BombNote(Engine engine, ObjectInstance o) : base(engine, new V3BombNote( (float)GetJsValue(o, "b"), (int)GetJsValue(o, "x"), (int)GetJsValue(o, "y"), @@ -66,7 +69,7 @@ internal override bool DeleteObject() { if (!spawned) return false; - var collection = BeatmapObjectContainerCollection.GetCollectionForType(BeatmapObject.ObjectType.Note); + var collection = BeatmapObjectContainerCollection.GetCollectionForType(ObjectType.Note); collection.DeleteObject(wrapped, false); spawned = false; diff --git a/Wrappers/V3/BpmChange.cs b/Wrappers/V3/BpmChange.cs index cf6b854..a5f76b0 100644 --- a/Wrappers/V3/BpmChange.cs +++ b/Wrappers/V3/BpmChange.cs @@ -1,9 +1,12 @@ -using Jint; +using Beatmap.Base.Customs; +using Beatmap.Enums; +using Beatmap.V3.Customs; +using Jint; using Jint.Native.Object; namespace V3 { - class BpmChange : Wrapper + class BpmChange : Wrapper { public float _time { @@ -45,18 +48,18 @@ public float _metronomeOffset } } - public BpmChange(Engine engine, BeatmapBPMChange bpmChange) : base(engine, bpmChange) + public BpmChange(Engine engine, BaseBpmChange bpmChange) : base(engine, bpmChange) { spawned = true; } - public BpmChange(Engine engine, ObjectInstance o) : base(engine, new BeatmapBPMChange( - (float)GetJsValue(o, "_BPM"), - (float)GetJsValue(o, "_time") + public BpmChange(Engine engine, ObjectInstance o) : base(engine, new V3BpmChange( + (float)GetJsValue(o, "m"), + (float)GetJsValue(o, "b") ) { - BeatsPerBar = (float)GetJsValue(o, "_beatsPerBar"), - MetronomeOffset = (float)GetJsValue(o, "_metronomeOffset") + BeatsPerBar = (float)GetJsValue(o, "p"), + MetronomeOffset = (float)GetJsValue(o, "o") }, false, GetJsBool(o, "selected")) { spawned = false; @@ -78,7 +81,7 @@ internal override bool DeleteObject() { if (!spawned) return false; - var collection = BeatmapObjectContainerCollection.GetCollectionForType(BeatmapObject.ObjectType.BpmChange); + var collection = BeatmapObjectContainerCollection.GetCollectionForType(ObjectType.BpmChange); collection.DeleteObject(wrapped, false); spawned = false; diff --git a/Wrappers/V3/Chain.cs b/Wrappers/V3/Chain.cs index 11327d3..f591a86 100644 --- a/Wrappers/V3/Chain.cs +++ b/Wrappers/V3/Chain.cs @@ -1,10 +1,13 @@ using Jint; using Jint.Native.Object; using System.Collections.Generic; +using Beatmap.Base; +using Beatmap.Enums; +using Beatmap.V3; namespace V3 { - class Chain : VanillaWrapper + class Chain : VanillaWrapper { public float b { @@ -28,31 +31,31 @@ public int c public int x { - get => wrapped.X; + get => wrapped.PosX; set { DeleteObject(); - wrapped.X = value; + wrapped.PosX = value; } } public int y { - get => wrapped.Y; + get => wrapped.PosY; set { DeleteObject(); - wrapped.Y = value; + wrapped.PosY = value; } } public int d { - get => wrapped.Direction; + get => wrapped.CutDirection; set { DeleteObject(); - wrapped.Direction = value; + wrapped.CutDirection = value; } } @@ -68,21 +71,21 @@ public float tb public int tx { - get => wrapped.TailX; + get => wrapped.TailPosX; set { DeleteObject(); - wrapped.TailX = value; + wrapped.TailPosX = value; } } public int ty { - get => wrapped.TailX; + get => wrapped.TailPosY; set { DeleteObject(); - wrapped.TailX = value; + wrapped.TailPosY = value; } } @@ -98,20 +101,20 @@ public int sc public float s { - get => wrapped.SquishAmount; + get => wrapped.Squish; set { DeleteObject(); - wrapped.SquishAmount = value; + wrapped.Squish = value; } } - public Chain(Engine engine, BeatmapChain chain) : base(engine, chain) + public Chain(Engine engine, BaseChain chain) : base(engine, chain) { spawned = true; } - public Chain(Engine engine, ObjectInstance o) : base(engine, new BeatmapChain(JSONWrapper.dictToJSON(new Dictionary() + public Chain(Engine engine, ObjectInstance o) : base(engine, new V3Chain(JSONWrapper.dictToJSON(new Dictionary() { { "b", (float)GetJsValue(o, "b") }, { "c", (int)GetJsValue(o, "c") }, @@ -146,7 +149,7 @@ internal override bool DeleteObject() { if (!spawned) return false; - var collection = BeatmapObjectContainerCollection.GetCollectionForType(BeatmapObject.ObjectType.Note); + var collection = BeatmapObjectContainerCollection.GetCollectionForType(ObjectType.Chain); collection.DeleteObject(wrapped, false); spawned = false; diff --git a/Wrappers/V3/ColorNote.cs b/Wrappers/V3/ColorNote.cs index a796a99..dd5b0b5 100644 --- a/Wrappers/V3/ColorNote.cs +++ b/Wrappers/V3/ColorNote.cs @@ -1,9 +1,12 @@ -using Jint; +using Beatmap.Base; +using Beatmap.Enums; +using Beatmap.V3; +using Jint; using Jint.Native.Object; namespace V3 { - class ColorNote : VanillaWrapper + class ColorNote : VanillaWrapper { public float _time { @@ -17,21 +20,21 @@ public float _time public int _lineIndex { - get => wrapped.LineIndex; + get => wrapped.PosX; set { DeleteObject(); - wrapped.LineIndex = value; + wrapped.PosX = value; } } public int _lineLayer { - get => wrapped.LineLayer; + get => wrapped.PosY; set { DeleteObject(); - wrapped.LineLayer = value; + wrapped.PosY = value; } } @@ -67,21 +70,21 @@ public float b public int x { - get => wrapped.LineIndex; + get => wrapped.PosX; set { DeleteObject(); - wrapped.LineIndex = value; + wrapped.PosX = value; } } public int y { - get => wrapped.LineLayer; + get => wrapped.PosY; set { DeleteObject(); - wrapped.LineLayer = value; + wrapped.PosY = value; } } @@ -115,12 +118,12 @@ public int d } } - public ColorNote(Engine engine, BeatmapColorNote note) : base(engine, note) + public ColorNote(Engine engine, BaseNote note) : base(engine, note) { spawned = true; } - public ColorNote(Engine engine, ObjectInstance o) : base(engine, new BeatmapColorNote( + public ColorNote(Engine engine, ObjectInstance o) : base(engine, new V3ColorNote( (float)GetJsValue(o, new string[] { "b", "_time" }), (int)GetJsValue(o, new string[] { "x", "_lineIndex" }), (int)GetJsValue(o, new string[] { "y", "_lineLayer" }), @@ -149,7 +152,7 @@ internal override bool DeleteObject() { if (!spawned) return false; - var collection = BeatmapObjectContainerCollection.GetCollectionForType(BeatmapObject.ObjectType.Note); + var collection = BeatmapObjectContainerCollection.GetCollectionForType(ObjectType.Note); collection.DeleteObject(wrapped, false); spawned = false; diff --git a/Wrappers/V3/CustomEvent.cs b/Wrappers/V3/CustomEvent.cs index 49ff5ab..4681708 100644 --- a/Wrappers/V3/CustomEvent.cs +++ b/Wrappers/V3/CustomEvent.cs @@ -1,10 +1,13 @@ using System; +using Beatmap.Base.Customs; +using Beatmap.Enums; +using Beatmap.V3.Customs; using Jint; using Jint.Native.Object; namespace V3 { - class CustomEvent : Wrapper + class CustomEvent : Wrapper { public float _time { @@ -39,16 +42,16 @@ public object _data } } - public CustomEvent(Engine engine, BeatmapCustomEvent customEvent) : base(engine, customEvent) + public CustomEvent(Engine engine, BaseCustomEvent customEvent) : base(engine, customEvent) { spawned = true; InitWrapper(); } - public CustomEvent(Engine engine, ObjectInstance o) : base(engine, new BeatmapCustomEvent( - (float)GetJsValue(o, "_time"), - GetJsString(o, "_type"), - GetCustomData(o, "_data") + public CustomEvent(Engine engine, ObjectInstance o) : base(engine, new V3CustomEvent( + (float)GetJsValue(o, "b"), + GetJsString(o, "t"), + GetCustomData(o, "d") ), false, GetJsBool(o, "selected")) { spawned = false; @@ -71,7 +74,7 @@ internal override bool DeleteObject() { if (!spawned) return false; - var collection = BeatmapObjectContainerCollection.GetCollectionForType(BeatmapObject.ObjectType.Event); + var collection = BeatmapObjectContainerCollection.GetCollectionForType(ObjectType.CustomEvent); collection.DeleteObject(wrapped, false); spawned = false; diff --git a/Wrappers/V3/Event.cs b/Wrappers/V3/Event.cs index 9bbc293..7d4a4a8 100644 --- a/Wrappers/V3/Event.cs +++ b/Wrappers/V3/Event.cs @@ -1,10 +1,13 @@ using Jint; using Jint.Native.Object; using System.Collections.Generic; +using Beatmap.Base; +using Beatmap.Enums; +using Beatmap.V3; namespace V3 { - class Event : VanillaWrapper + class Event : VanillaWrapper { public float _time { @@ -86,18 +89,18 @@ public float f } } - public Event(Engine engine, MapEventV3 mapEvent) : base(engine, mapEvent) + public Event(Engine engine, BaseEvent mapEvent) : base(engine, mapEvent) { spawned = true; } - public Event(Engine engine, ObjectInstance o) : base(engine, new MapEventV3(new MapEvent( + public Event(Engine engine, ObjectInstance o) : base(engine, new V3BasicEvent( (float)GetJsValue(o, new string[] { "b", "_time" }), (int)GetJsValue(o, new string[] { "et", "_type" }), (int)GetJsValue(o, new string[] { "i", "_value" }), GetCustomData(o, new string[] { "customData", "_customData" }), (float)GetJsValue(o, new string[] { "f", "_floatValue" }) - )), false, GetJsBool(o, "selected")) + ), false, GetJsBool(o, "selected")) { spawned = false; @@ -118,7 +121,7 @@ internal override bool DeleteObject() { if (!spawned) return false; - var collection = BeatmapObjectContainerCollection.GetCollectionForType(BeatmapObject.ObjectType.Event); + var collection = BeatmapObjectContainerCollection.GetCollectionForType(ObjectType.Event); collection.DeleteObject(wrapped, false); spawned = false; diff --git a/Wrappers/V3/Wall.cs b/Wrappers/V3/Wall.cs index 6d50b26..23e92c9 100644 --- a/Wrappers/V3/Wall.cs +++ b/Wrappers/V3/Wall.cs @@ -1,11 +1,14 @@ using Jint; using Jint.Native.Object; using System.Collections.Generic; +using Beatmap.Base; +using Beatmap.Enums; +using Beatmap.V3; using UnityEngine; namespace V3 { - class Wall : VanillaWrapper + class Wall : VanillaWrapper { public float _time { @@ -19,11 +22,21 @@ public float _time public int _lineIndex { - get => wrapped.LineIndex; + get => wrapped.PosX; set { DeleteObject(); - wrapped.LineIndex = value; + wrapped.PosX = value; + } + } + + public int _lineLayer + { + get => wrapped.PosY; + set + { + DeleteObject(); + wrapped.PosY = value; } } @@ -57,6 +70,16 @@ public int _width } } + public int _height + { + get => wrapped.Height; + set + { + DeleteObject(); + wrapped.Height = value; + } + } + public float b { get => wrapped.Time; @@ -69,21 +92,21 @@ public float b public int x { - get => wrapped.LineIndex; + get => wrapped.PosX; set { DeleteObject(); - wrapped.LineIndex = value; + wrapped.PosX = value; } } public int y { - get => wrapped.LineLayer; + get => wrapped.PosY; set { DeleteObject(); - wrapped.LineLayer = value; + wrapped.PosY = value; } } @@ -117,12 +140,12 @@ public int h } } - public Wall(Engine engine, BeatmapObstacleV3 wall) : base(engine, wall) + public Wall(Engine engine, BaseObstacle wall) : base(engine, wall) { spawned = true; } - public Wall(Engine engine, ObjectInstance o) : base(engine, new BeatmapObstacleV3(JSONWrapper.dictToJSON(new Dictionary() + public Wall(Engine engine, ObjectInstance o) : base(engine, new V3Obstacle(JSONWrapper.dictToJSON(new Dictionary() { { "b", (float)GetJsValue(o, new string[] { "b", "_time" }) }, { "x", (int)GetJsValue(o, new string[] { "x", "_lineIndex" }) }, @@ -153,7 +176,7 @@ internal override bool DeleteObject() { if (!spawned) return false; - var collection = BeatmapObjectContainerCollection.GetCollectionForType(BeatmapObject.ObjectType.Obstacle); + var collection = BeatmapObjectContainerCollection.GetCollectionForType(ObjectType.Obstacle); collection.DeleteObject(wrapped, false); spawned = false; diff --git a/Wrappers/VanillaWrapper.cs b/Wrappers/VanillaWrapper.cs index aa28e65..a9a51dc 100644 --- a/Wrappers/VanillaWrapper.cs +++ b/Wrappers/VanillaWrapper.cs @@ -1,7 +1,8 @@ using System; +using Beatmap.Base; using Jint; -abstract class VanillaWrapper : Wrapper where T : BeatmapObject +abstract class VanillaWrapper : Wrapper where T : BaseObject { private Lazy customData; private Action reconcile; diff --git a/Wrappers/Wrapper.cs b/Wrappers/Wrapper.cs index c70c234..3cf3bba 100644 --- a/Wrappers/Wrapper.cs +++ b/Wrappers/Wrapper.cs @@ -1,8 +1,10 @@ -using Jint; +using Beatmap.Base; +using Beatmap.Helper; +using Jint; using Jint.Native.Object; using SimpleJSON; -abstract class Wrapper where T : BeatmapObject +abstract class Wrapper where T : BaseObject { protected readonly Engine engine; protected bool spawned; @@ -22,7 +24,7 @@ public Wrapper(Engine engine, T wrapped, bool hasOriginal = true, bool? selected { this.engine = engine; this.wrapped = wrapped; - if (hasOriginal) original = BeatmapObject.GenerateCopy(wrapped); + if (hasOriginal) original = BeatmapFactory.Clone(wrapped); _selected = selected.GetValueOrDefault(SelectionController.IsObjectSelected(wrapped)); } From 6845c4edf610b0243ac8d2439660d1ed5f71e2af Mon Sep 17 00:00:00 2001 From: Kival Evan <5645391+KivalEvan@users.noreply.github.com> Date: Sun, 8 Jan 2023 06:05:14 -0800 Subject: [PATCH 11/26] Refresh custom data on modify --- Wrappers/V2/Event.cs | 4 ++-- Wrappers/V3/Arc.cs | 8 +++----- Wrappers/V3/BombNote.cs | 2 +- Wrappers/V3/Chain.cs | 2 +- Wrappers/V3/Event.cs | 6 +++--- Wrappers/V3/Wall.cs | 1 - Wrappers/VanillaWrapper.cs | 21 ++++++++++++++++++--- Wrappers/Wrapper.cs | 7 ++++--- 8 files changed, 32 insertions(+), 19 deletions(-) diff --git a/Wrappers/V2/Event.cs b/Wrappers/V2/Event.cs index cc97b4b..d4ecb48 100644 --- a/Wrappers/V2/Event.cs +++ b/Wrappers/V2/Event.cs @@ -98,8 +98,8 @@ public Event(Engine engine, BaseEvent mapEvent) : base(engine, mapEvent) (float)GetJsValue(o, new string[] { "_time", "b" }), (int)GetJsValue(o, new string[] { "_type", "et" }), (int)GetJsValue(o, new string[] { "_value", "i" }), - GetCustomData(o, new string[] { "_customData", "customData" }), - (float)GetJsValue(o, new string[] { "_floatValue", "f" }) + (float)GetJsValue(o, new string[] { "_floatValue", "f" }), + GetCustomData(o, new string[] { "_customData", "customData" }) ), false, GetJsBool(o, "selected")) { spawned = false; diff --git a/Wrappers/V3/Arc.cs b/Wrappers/V3/Arc.cs index 0e260df..2092284 100644 --- a/Wrappers/V3/Arc.cs +++ b/Wrappers/V3/Arc.cs @@ -1,6 +1,5 @@ using Jint; using Jint.Native.Object; -using SimpleJSON; using System.Collections.Generic; using Beatmap.Base; using Beatmap.Enums; @@ -62,11 +61,11 @@ public int d public float mu { - get => wrapped.ControlPointLengthMultiplier; + get => wrapped.HeadControlPointLengthMultiplier; set { DeleteObject(); - wrapped.ControlPointLengthMultiplier = value; + wrapped.HeadControlPointLengthMultiplier = value; } } @@ -149,11 +148,10 @@ public Arc(Engine engine, BaseArc arc) : base(engine, arc) { "tc", (int)GetJsValue(o, "tc") }, { "tmu", (float)GetJsValue(o, "tmu") }, { "m", (int)GetJsValue(o, "m") }, - { "customData", GetCustomData(o, "customData") } + { "customData", GetCustomData(o, new string[] { "customData", "_customData" }) } })), false, GetJsBool(o, "selected")) { spawned = false; - wrapped.CustomData = GetCustomData(o, new string[] { "customData", "_customData" }); DeleteObject(); } diff --git a/Wrappers/V3/BombNote.cs b/Wrappers/V3/BombNote.cs index 132461e..beeecbd 100644 --- a/Wrappers/V3/BombNote.cs +++ b/Wrappers/V3/BombNote.cs @@ -47,7 +47,7 @@ public BombNote(Engine engine, BaseBombNote bomb) : base(engine, bomb) (float)GetJsValue(o, "b"), (int)GetJsValue(o, "x"), (int)GetJsValue(o, "y"), - GetCustomData(o, "customData") + GetCustomData(o, new string[] { "customData", "_customData" }) ), false, GetJsBool(o, "selected")) { spawned = false; diff --git a/Wrappers/V3/Chain.cs b/Wrappers/V3/Chain.cs index f591a86..6674ebc 100644 --- a/Wrappers/V3/Chain.cs +++ b/Wrappers/V3/Chain.cs @@ -126,7 +126,7 @@ public Chain(Engine engine, BaseChain chain) : base(engine, chain) { "ty", (int)GetJsValue(o, "ty") }, { "sc", (int)GetJsValue(o, "sc") }, { "s", (float)GetJsValue(o, "s") }, - { "customData", GetCustomData(o, "customData") } + { "customData", GetCustomData(o, new string[] { "customData", "_customData" }) } })), false, GetJsBool(o, "selected")) { spawned = false; diff --git a/Wrappers/V3/Event.cs b/Wrappers/V3/Event.cs index 7d4a4a8..afef0c9 100644 --- a/Wrappers/V3/Event.cs +++ b/Wrappers/V3/Event.cs @@ -1,6 +1,5 @@ using Jint; using Jint.Native.Object; -using System.Collections.Generic; using Beatmap.Base; using Beatmap.Enums; using Beatmap.V3; @@ -89,6 +88,7 @@ public float f } } + public Event(Engine engine, BaseEvent mapEvent) : base(engine, mapEvent) { spawned = true; @@ -98,8 +98,8 @@ public Event(Engine engine, BaseEvent mapEvent) : base(engine, mapEvent) (float)GetJsValue(o, new string[] { "b", "_time" }), (int)GetJsValue(o, new string[] { "et", "_type" }), (int)GetJsValue(o, new string[] { "i", "_value" }), - GetCustomData(o, new string[] { "customData", "_customData" }), - (float)GetJsValue(o, new string[] { "f", "_floatValue" }) + (float)GetJsValue(o, new string[] { "f", "_floatValue" }), + GetCustomData(o, new string[] { "customData", "_customData" }) ), false, GetJsBool(o, "selected")) { spawned = false; diff --git a/Wrappers/V3/Wall.cs b/Wrappers/V3/Wall.cs index 23e92c9..f3a9b4a 100644 --- a/Wrappers/V3/Wall.cs +++ b/Wrappers/V3/Wall.cs @@ -4,7 +4,6 @@ using Beatmap.Base; using Beatmap.Enums; using Beatmap.V3; -using UnityEngine; namespace V3 { diff --git a/Wrappers/VanillaWrapper.cs b/Wrappers/VanillaWrapper.cs index a9a51dc..72bde93 100644 --- a/Wrappers/VanillaWrapper.cs +++ b/Wrappers/VanillaWrapper.cs @@ -4,16 +4,29 @@ abstract class VanillaWrapper : Wrapper where T : BaseObject { - private Lazy customData; + private Lazy pCustomData; private Action reconcile; + public object customData + { + get => wrapped.CustomData == null ? null : pCustomData.Value; + set + { + DeleteObject(); + wrapped.CustomData = JSONWrapper.castObjToJSON(value); + wrapped.RefreshCustom(); + InitWrapper(); + } + } + public object _customData { - get => wrapped.CustomData == null ? null : customData.Value; + get => wrapped.CustomData == null ? null : pCustomData.Value; set { DeleteObject(); wrapped.CustomData = JSONWrapper.castObjToJSON(value); + wrapped.RefreshCustom(); InitWrapper(); } } @@ -26,7 +39,7 @@ protected VanillaWrapper(Engine engine, T wrapped, bool hasOriginal = true, bool private void InitWrapper() { reconcile = null; - customData = new Lazy(() => + pCustomData = new Lazy(() => new JSONWrapper(engine, ref reconcile, wrapped.CustomData, DeleteObject) ); } @@ -39,5 +52,7 @@ internal override void Reconcile() { wrapped.CustomData = null; } + + wrapped.RefreshCustom(); } } diff --git a/Wrappers/Wrapper.cs b/Wrappers/Wrapper.cs index 3cf3bba..0c3ccbe 100644 --- a/Wrappers/Wrapper.cs +++ b/Wrappers/Wrapper.cs @@ -1,4 +1,5 @@ -using Beatmap.Base; +using System.Collections.Generic; +using Beatmap.Base; using Beatmap.Helper; using Jint; using Jint.Native.Object; @@ -34,7 +35,7 @@ protected static double GetJsValue(ObjectInstance o, string key) return (double)value.ToObject(); } - protected static double? GetJsValue(ObjectInstance o, string[] key) + protected static double? GetJsValue(ObjectInstance o, IEnumerable key) { foreach (string k in key) { @@ -94,7 +95,7 @@ protected static JSONNode GetCustomData(ObjectInstance o, string key = "_customD return JSON.Parse(customData.AsString()); } - protected static JSONNode GetCustomData(ObjectInstance o, string[] key) + protected static JSONNode GetCustomData(ObjectInstance o, IEnumerable key) { foreach(var k in key) { From 930ef64dc7e0819252d6e75138c129db043d7353 Mon Sep 17 00:00:00 2001 From: Kival Evan <5645391+KivalEvan@users.noreply.github.com> Date: Sun, 8 Jan 2023 06:05:34 -0800 Subject: [PATCH 12/26] Update Jint --- ErrorChecker.csproj | 6 ++--- README.md | 62 ++++++++++++++++++++++++++------------------- packages.config | 4 +-- 3 files changed, 41 insertions(+), 31 deletions(-) diff --git a/ErrorChecker.csproj b/ErrorChecker.csproj index 918663b..58cb435 100644 --- a/ErrorChecker.csproj +++ b/ErrorChecker.csproj @@ -6,7 +6,7 @@ - C:\Users\mnaba\Build\CM Dev + F:\Programs\CM Dev Debug AnyCPU {600D3953-D125-4C0F-A5CF-0E3906D6B6F6} @@ -46,10 +46,10 @@ packages\Costura.Fody.5.8.0-alpha0098\lib\netstandard1.0\Costura.dll - packages\Esprima.3.0.0-beta-7\lib\net462\Esprima.dll + packages\Esprima.3.0.0-beta-9\lib\net462\Esprima.dll - packages\Jint.3.0.0-beta-2041\lib\net462\Jint.dll + packages\Jint.3.0.0-beta-2044\lib\net462\Jint.dll $(ChromapperDir)\ChroMapper_Data\Managed\Main.dll diff --git a/README.md b/README.md index 23dc03f..7147d5a 100644 --- a/README.md +++ b/README.md @@ -7,20 +7,22 @@ Simple plugin that adds an error checker to [ChroMapper](https://github.com/Caed Download the latest release, place the entire folder in your `ChroMapper/Plugins` directory ### Built-in plugins -* Vision Blocks - * Copy of the logic in MMA2's error checker - * Finds blocks that are obscured by blocks in the center two positions -* Stacked Blocks - * Finds blocks that may be overlapping - * Looks for notes less than 0.1 beats of each other in the same position + +- Vision Blocks + - Copy of the logic in MMA2's error checker + - Finds blocks that are obscured by blocks in the center two positions +- Stacked Blocks + - Finds blocks that may be overlapping + - Looks for notes less than 0.1 beats of each other in the same position ### JS Checks You can add more error check types directly by placing javascript files in the same directory as the plugin. -The parser uses [Jint 3 (beta)](https://github.com/sebastienros/jint/issues/343) and [esprima](https://github.com/sebastienros/esprima-dotnet) which can parse ES6 but not all features are supported, for instance esprima can parse `class` but Jint will through an exception so you'll have to rewrite these as old-style functions and prototypes +The parser uses [Jint 3 (beta)](https://github.com/sebastienros/jint/issues/343) and [esprima](https://github.com/sebastienros/esprima-dotnet) which can parse ES6 but not all features are supported, for instance esprima can parse `class` but Jint will throw an exception so you'll have to rewrite these as old-style functions and prototypes As this is essentially alpha the interface for these checks may change but for now you just need to create a block similar to: + ``` module.exports = { name: "My error check", @@ -29,27 +31,35 @@ module.exports = { }; ``` -* **name** appears in the drop-down ingame. -* **params** is an object, for each key a text field will be show to the user where they can enter a value which will be passed to you as a float -* **run** is a function that will be called when the user runs your check, this is currently designed to be compatible with MM scripts, you just need to add the name and params. - * The first parameter to the function is the position the user is looking at in the map - * Next is an array of notes ordered by time (I can't guarantee what order notes that happen at the same time will be in for now) which can be modified. You can directly modify the values of notes in the array with code like `notes[0]._time = 10;` -OR if you want to generate a fresh array you need to provide your new array in object returned from your function (see below) - * Lighting events are provided next and work the same as notes - * Obstacles are last of the map objects and work the same as notes - * In MM scripts the parameter here was called save? I don't know what it did but this parameter is just an empty object and has no use. Provided for compatibility. - * The global parameter can be used to persist data between runs of your script, it will be unchanged on future invocations. It also includes a `params` array which contains the values set for your params. (I _assume_ this will be returned in order) - * Data has information about the map, currently the list of data is as follows: - * currentBPM - The bpm at the cursor accounting for BPM changes - * songBPM - The bpm of the song - * NJS - The note jump speed set for the song - * offset - How far into the song the user starts - * Custom events are custom objects used for [noodling](https://github.com/Aeroluna/NoodleExtensions/blob/master/Documentation/AnimationDocs.md#custom-events) - * BPM Changes may be useful for working out what the bpm is at a point in a map or programatically creating slides +- **name** appears in the drop-down ingame. +- **params** is an object, for each key a text field will be show to the user where they can enter a value which will be passed to you as a float +- **run** is a function that will be called when the user runs your check, this is currently designed to be compatible with MM scripts, you just need to add the name and params. + - **cursor** is the position the user is looking at in the map + - **notes** is an array of notes ordered by time (I can't guarantee what order notes that happen at the same time will be in for now) which can be modified. You can directly modify the values of notes in the array with code like `notes[0]._time = 10;` + OR if you want to generate a fresh array you need to provide your new array in object returned from your function (see below) + - **events** are provided next and work the same as notes + - **walls** are last of the map objects and work the same as notes + - **\_** In MM scripts the parameter here was called save? I don't know what it did but this parameter is just an empty object and has no use. Provided for compatibility. + - **globals** can be used to persist data between runs of your script, it will be unchanged on future invocations. It also includes a `params` array which contains the values set for your params. (I _assume_ this will be returned in order) + - **data** has information about the map, currently the list of data is as follows: + - currentBPM - The bpm at the cursor accounting for BPM changes + - songBPM - The bpm of the song + - NJS - The note jump speed set for the song + - offset - How far into the song the user starts + - characteristic - Current beatmap characteristics + - difficulty - Current beatmap difficulty + - environment - Current beatmap environment + - version - Current beatmap version + - **customEvents** are custom objects used for [noodling](https://github.com/Aeroluna/NoodleExtensions/blob/master/Documentation/AnimationDocs.md#custom-events) + - **bpmChanges** may be useful for working out what the bpm is at a point in a map or programatically creating slides + - **bombs** - v3 + - **arcs** - v3 + - **chains** - v3 Two functions will be defined before calling `performCheck` -* **addError**(note, reason) - Pass back the problem note object, all it's properties (except `_customData`) must match the original passed note for it to be marked properly and you can provide a reason as the second parameter -* **addWarning**(note, reason) - The same as `addError` except the note will only be highlighted yellow + +- **addError**(note, reason) - Pass back the problem note object, all it's properties (except `_customData`) must match the original passed note for it to be marked properly and you can provide a reason as the second parameter +- **addWarning**(note, reason) - The same as `addError` except the note will only be highlighted yellow [There are example scripts in Examples](Examples) diff --git a/packages.config b/packages.config index 2fa5c4c..ac6721f 100644 --- a/packages.config +++ b/packages.config @@ -1,9 +1,9 @@  - + - + From d81286e757f878c7a5f78898af1f96049b8401a1 Mon Sep 17 00:00:00 2001 From: Kival Evan <5645391+KivalEvan@users.noreply.github.com> Date: Sat, 28 Jan 2023 03:03:13 -0800 Subject: [PATCH 13/26] Utilise beatmap factory --- CMJS.cs | 2 +- Checks/Check.cs | 4 +- Checks/ExternalJS.cs | 54 +++---- ErrorChecker.csproj | 21 +-- Wrappers/{V3 => Beatmap}/Arc.cs | 68 ++++----- Wrappers/{V3 => Beatmap}/BombNote.cs | 41 +++--- Wrappers/{V3 => Beatmap}/BpmChange.cs | 66 +++++++-- Wrappers/{V3 => Beatmap}/Chain.cs | 65 ++++----- Wrappers/{V2 => Beatmap}/CustomEvent.cs | 65 ++++++--- Wrappers/{V3 => Beatmap}/Event.cs | 50 +++---- Wrappers/{V2 => Beatmap}/Note.cs | 58 ++++---- Wrappers/{V2 => Beatmap}/Wall.cs | 74 ++++------ Wrappers/V2/BpmChange.cs | 96 ------------ Wrappers/V2/Event.cs | 136 ----------------- Wrappers/V3/ColorNote.cs | 162 --------------------- Wrappers/V3/CustomEvent.cs | 97 ------------- Wrappers/V3/Wall.cs | 185 ------------------------ Wrappers/Wrapper.cs | 15 +- 18 files changed, 311 insertions(+), 948 deletions(-) rename Wrappers/{V3 => Beatmap}/Arc.cs (78%) rename Wrappers/{V3 => Beatmap}/BombNote.cs (85%) rename Wrappers/{V3 => Beatmap}/BpmChange.cs (60%) rename Wrappers/{V3 => Beatmap}/Chain.cs (75%) rename Wrappers/{V2 => Beatmap}/CustomEvent.cs (69%) rename Wrappers/{V3 => Beatmap}/Event.cs (81%) rename Wrappers/{V2 => Beatmap}/Note.cs (78%) rename Wrappers/{V2 => Beatmap}/Wall.cs (78%) delete mode 100644 Wrappers/V2/BpmChange.cs delete mode 100644 Wrappers/V2/Event.cs delete mode 100644 Wrappers/V3/ColorNote.cs delete mode 100644 Wrappers/V3/CustomEvent.cs delete mode 100644 Wrappers/V3/Wall.cs diff --git a/CMJS.cs b/CMJS.cs index 704059f..37e1421 100644 --- a/CMJS.cs +++ b/CMJS.cs @@ -120,7 +120,7 @@ public void CheckErrors(Check check) { // TODO: since containers has multiple different object, check events and notes var allNotes = notesContainer.LoadedObjects.Where(it => it is V3ColorNote).Cast().OrderBy(it => it.Time).ToList(); - var allBombs = notesContainer.LoadedObjects.Where(it => it is V3BombNote).Cast().OrderBy(it => it.Time).ToList(); + var allBombs = notesContainer.LoadedObjects.Where(it => it is V3BombNote).Cast().OrderBy(it => it.Time).ToList(); var allArcs = arcsContainer.LoadedObjects.Cast().OrderBy(it => it.Time).ToList(); var allChains = chainsContainer.LoadedObjects.Cast().OrderBy(it => it.Time).ToList(); var allWalls = wallsContainer.LoadedObjects.Cast().OrderBy(it => it.Time).ToList(); diff --git a/Checks/Check.cs b/Checks/Check.cs index c36b8c7..6752610 100644 --- a/Checks/Check.cs +++ b/Checks/Check.cs @@ -34,12 +34,12 @@ public virtual CheckResult PerformCheck(List notes, List ev throw new ArgumentException("Wrong number of parameters"); } - protected virtual CheckResult PerformCheck(List notes, List bombs, List arcs, List chains, List events, List walls, List customEvents, List bpmChanges) + protected virtual CheckResult PerformCheck(List notes, List bombs, List arcs, List chains, List events, List walls, List customEvents, List bpmChanges) { throw new ArgumentException("Wrong number of parameters"); } - public virtual CheckResult PerformCheck(List notes, List bombs, List arcs, List chains, List events, List walls, List customEvents, List bpmChanges, params IParamValue[] vals) + public virtual CheckResult PerformCheck(List notes, List bombs, List arcs, List chains, List events, List walls, List customEvents, List bpmChanges, params IParamValue[] vals) { if (vals.Length == 0 && Params.Count == 0) { diff --git a/Checks/ExternalJS.cs b/Checks/ExternalJS.cs index 4e7c427..afd6b10 100644 --- a/Checks/ExternalJS.cs +++ b/Checks/ExternalJS.cs @@ -261,11 +261,11 @@ public override CheckResult PerformCheck(List notes, List e var lastBPMChange = collection.FindLastBpm(atsc.CurrentBeat); var currentBPM = lastBPMChange?.Bpm ?? atsc.Song.BeatsPerMinute; - var originalNotes = notes.Select(it => new V2.Note(engine, it)).ToArray(); - var originalWalls = walls.Select(it => new V2.Wall(engine, it)).ToArray(); - var originalEvents = events.Select(it => new V2.Event(engine, it)).ToArray(); - var originalCustomEvents = customEvents.Select(it => new V2.CustomEvent(engine, it)).ToArray(); - var originalBpmChanges = bpmChanges.Select(it => new V2.BpmChange(engine, it)).ToArray(); + var originalNotes = notes.Select(it => new Note(engine, it)).ToArray(); + var originalWalls = walls.Select(it => new Wall(engine, it)).ToArray(); + var originalEvents = events.Select(it => new Event(engine, it)).ToArray(); + var originalCustomEvents = customEvents.Select(it => new CustomEvent(engine, it)).ToArray(); + var originalBpmChanges = bpmChanges.Select(it => new BpmChange(engine, it)).ToArray(); try { @@ -341,11 +341,11 @@ public override CheckResult PerformCheck(List notes, List e SelectionController.DeselectAll(); var actions = new List(); - actions.AddRange(Reconcile(originalNotes, engine.GetValue("notes").AsArray(), notes, i => new V2.Note(engine, i), ObjectType.Note)); - actions.AddRange(Reconcile(originalWalls, engine.GetValue("walls").AsArray(), walls, i => new V2.Wall(engine, i), ObjectType.Obstacle)); - actions.AddRange(Reconcile(originalEvents, engine.GetValue("events").AsArray(), events, i => new V2.Event(engine, i), ObjectType.Event)); - actions.AddRange(Reconcile(originalCustomEvents, engine.GetValue("customEvents").AsArray(), customEvents, i => new V2.CustomEvent(engine, i), ObjectType.CustomEvent)); - actions.AddRange(Reconcile(originalBpmChanges, engine.GetValue("bpmChanges").AsArray(), bpmChanges, i => new V2.BpmChange(engine, i), ObjectType.BpmChange)); + actions.AddRange(Reconcile(originalNotes, engine.GetValue("notes").AsArray(), notes, i => new Note(engine, i), ObjectType.Note)); + actions.AddRange(Reconcile(originalWalls, engine.GetValue("walls").AsArray(), walls, i => new Wall(engine, i), ObjectType.Obstacle)); + actions.AddRange(Reconcile(originalEvents, engine.GetValue("events").AsArray(), events, i => new Event(engine, i), ObjectType.Event)); + actions.AddRange(Reconcile(originalCustomEvents, engine.GetValue("customEvents").AsArray(), customEvents, i => new CustomEvent(engine, i), ObjectType.CustomEvent)); + actions.AddRange(Reconcile(originalBpmChanges, engine.GetValue("bpmChanges").AsArray(), bpmChanges, i => new BpmChange(engine, i), ObjectType.BpmChange)); SelectionController.SelectionChangedEvent?.Invoke(); @@ -361,7 +361,7 @@ public override CheckResult PerformCheck(List notes, List e return result; } - public override CheckResult PerformCheck(List notes, List bombs, List arcs, List chains, List events, List walls, List customEvents, List bpmChanges, params IParamValue[] vals) + public override CheckResult PerformCheck(List notes, List bombs, List arcs, List chains, List events, List walls, List customEvents, List bpmChanges, params IParamValue[] vals) { result.Clear(); @@ -372,14 +372,14 @@ public override CheckResult PerformCheck(List notes, List new V3.ColorNote(engine, it)).ToArray(); - var originalBombs = bombs.Select(it => new V3.BombNote(engine, it)).ToArray(); - var originalArcs = arcs.Select(it => new V3.Arc(engine, it)).ToArray(); - var originalChains = chains.Select(it => new V3.Chain(engine, it)).ToArray(); - var originalWalls = walls.Select(it => new V3.Wall(engine, it)).ToArray(); - var originalEvents = events.Select(it => new V3.Event(engine, it)).ToArray(); - var originalCustomEvents = customEvents.Select(it => new V3.CustomEvent(engine, it)).ToArray(); - var originalBpmChanges = bpmChanges.Select(it => new V3.BpmChange(engine, it)).ToArray(); + var originalNotes = notes.Select(it => new Note(engine, it)).ToArray(); + var originalBombs = bombs.Select(it => new BombNote(engine, it)).ToArray(); + var originalArcs = arcs.Select(it => new Arc(engine, it)).ToArray(); + var originalChains = chains.Select(it => new Chain(engine, it)).ToArray(); + var originalWalls = walls.Select(it => new Wall(engine, it)).ToArray(); + var originalEvents = events.Select(it => new Event(engine, it)).ToArray(); + var originalCustomEvents = customEvents.Select(it => new CustomEvent(engine, it)).ToArray(); + var originalBpmChanges = bpmChanges.Select(it => new BpmChange(engine, it)).ToArray(); try { @@ -461,14 +461,14 @@ public override CheckResult PerformCheck(List notes, List(); - actions.AddRange(Reconcile(originalNotes, engine.GetValue("notes").AsArray(), notes, i => new V3.ColorNote(engine, i), ObjectType.Note)); - actions.AddRange(Reconcile(originalBombs, engine.GetValue("bombs").AsArray(), bombs, i => new V3.BombNote(engine, i), ObjectType.Note)); - actions.AddRange(Reconcile(originalArcs, engine.GetValue("arcs").AsArray(), arcs, i => new V3.Arc(engine, i), ObjectType.Arc)); - actions.AddRange(Reconcile(originalChains, engine.GetValue("chains").AsArray(), chains, i => new V3.Chain(engine, i), ObjectType.Chain)); - actions.AddRange(Reconcile(originalWalls, engine.GetValue("walls").AsArray(), walls, i => new V3.Wall(engine, i), ObjectType.Obstacle)); - actions.AddRange(Reconcile(originalEvents, engine.GetValue("events").AsArray(), events, i => new V3.Event(engine, i), ObjectType.Event)); - actions.AddRange(Reconcile(originalCustomEvents, engine.GetValue("customEvents").AsArray(), customEvents, i => new V3.CustomEvent(engine, i), ObjectType.CustomEvent)); - actions.AddRange(Reconcile(originalBpmChanges, engine.GetValue("bpmChanges").AsArray(), bpmChanges, i => new V3.BpmChange(engine, i), ObjectType.BpmChange)); + actions.AddRange(Reconcile(originalNotes, engine.GetValue("notes").AsArray(), notes, i => new Note(engine, i), ObjectType.Note)); + actions.AddRange(Reconcile(originalBombs, engine.GetValue("bombs").AsArray(), bombs, i => new BombNote(engine, i), ObjectType.Note)); + actions.AddRange(Reconcile(originalArcs, engine.GetValue("arcs").AsArray(), arcs, i => new Arc(engine, i), ObjectType.Arc)); + actions.AddRange(Reconcile(originalChains, engine.GetValue("chains").AsArray(), chains, i => new Chain(engine, i), ObjectType.Chain)); + actions.AddRange(Reconcile(originalWalls, engine.GetValue("walls").AsArray(), walls, i => new Wall(engine, i), ObjectType.Obstacle)); + actions.AddRange(Reconcile(originalEvents, engine.GetValue("events").AsArray(), events, i => new Event(engine, i), ObjectType.Event)); + actions.AddRange(Reconcile(originalCustomEvents, engine.GetValue("customEvents").AsArray(), customEvents, i => new CustomEvent(engine, i), ObjectType.CustomEvent)); + actions.AddRange(Reconcile(originalBpmChanges, engine.GetValue("bpmChanges").AsArray(), bpmChanges, i => new BpmChange(engine, i), ObjectType.BpmChange)); SelectionController.SelectionChangedEvent?.Invoke(); diff --git a/ErrorChecker.csproj b/ErrorChecker.csproj index 58cb435..c22be18 100644 --- a/ErrorChecker.csproj +++ b/ErrorChecker.csproj @@ -255,21 +255,16 @@ - - - - - - - - - - - + + + + + + + + - - diff --git a/Wrappers/V3/Arc.cs b/Wrappers/Beatmap/Arc.cs similarity index 78% rename from Wrappers/V3/Arc.cs rename to Wrappers/Beatmap/Arc.cs index 2092284..81ec8c9 100644 --- a/Wrappers/V3/Arc.cs +++ b/Wrappers/Beatmap/Arc.cs @@ -1,14 +1,38 @@ -using Jint; -using Jint.Native.Object; -using System.Collections.Generic; -using Beatmap.Base; +using Beatmap.Base; using Beatmap.Enums; -using Beatmap.V3; +using Beatmap.Helper; +using Jint; +using Jint.Native.Object; -namespace V3 -{ - class Arc : VanillaWrapper + internal class Arc : VanillaWrapper { + public Arc(Engine engine, BaseArc arc) : base(engine, arc) + { + spawned = true; + } + + public Arc(Engine engine, ObjectInstance o) : base(engine, BeatmapFactory.Arc( + (float)GetJsValue(o, "b"), + (int)GetJsValue(o, "c"), + (int)GetJsValue(o, "x"), + (int)GetJsValue(o, "y"), + (int)GetJsValue(o, "d"), + 0, + (float)GetJsValue(o, "mu"), + (float)GetJsValue(o, "tb"), + (int)GetJsValue(o, "tx"), + (int)GetJsValue(o, "ty"), + (int)GetJsValue(o, "tc"), + (float)GetJsValue(o, "tmu"), + (int)GetJsValue(o, "m"), + GetCustomData(o, new[] { "customData", "_customData" }) + ), false, GetJsBool(o, "selected")) + { + spawned = false; + + DeleteObject(); + } + public float b { get => wrapped.Time; @@ -129,33 +153,6 @@ public int m } } - public Arc(Engine engine, BaseArc arc) : base(engine, arc) - { - spawned = true; - } - - public Arc(Engine engine, ObjectInstance o) : base(engine, new V3Arc(JSONWrapper.dictToJSON(new Dictionary() - { - { "b", (float)GetJsValue(o, "b") }, - { "c", (int)GetJsValue(o, "c") }, - { "x", (int) GetJsValue(o, "x") }, - { "y", (int)GetJsValue(o, "y") }, - { "d", (int)GetJsValue(o, "d") }, - { "mu", (float)GetJsValue(o, "mu") }, - { "tb", (float)GetJsValue(o, "tb") }, - { "tx", (int)GetJsValue(o, "tx") }, - { "ty", (int)GetJsValue(o, "ty") }, - { "tc", (int)GetJsValue(o, "tc") }, - { "tmu", (float)GetJsValue(o, "tmu") }, - { "m", (int)GetJsValue(o, "m") }, - { "customData", GetCustomData(o, new string[] { "customData", "_customData" }) } - })), false, GetJsBool(o, "selected")) - { - spawned = false; - - DeleteObject(); - } - public override bool SpawnObject(BeatmapObjectContainerCollection collection) { if (spawned) return false; @@ -177,4 +174,3 @@ internal override bool DeleteObject() return true; } } -} diff --git a/Wrappers/V3/BombNote.cs b/Wrappers/Beatmap/BombNote.cs similarity index 85% rename from Wrappers/V3/BombNote.cs rename to Wrappers/Beatmap/BombNote.cs index beeecbd..8b374d2 100644 --- a/Wrappers/V3/BombNote.cs +++ b/Wrappers/Beatmap/BombNote.cs @@ -1,13 +1,28 @@ using Beatmap.Base; using Beatmap.Enums; -using Beatmap.V3; +using Beatmap.Helper; using Jint; using Jint.Native.Object; -namespace V3 -{ - class BombNote : VanillaWrapper + internal class BombNote : VanillaWrapper { + public BombNote(Engine engine, BaseNote bomb) : base(engine, bomb) + { + spawned = true; + } + + public BombNote(Engine engine, ObjectInstance o) : base(engine, BeatmapFactory.Bomb( + (float)GetJsValue(o, "b"), + (int)GetJsValue(o, "x"), + (int)GetJsValue(o, "y"), + GetCustomData(o, new[] { "customData", "_customData" }) + ), false, GetJsBool(o, "selected")) + { + spawned = false; + + DeleteObject(); + } + public float b { get => wrapped.Time; @@ -38,23 +53,6 @@ public int y } } - public BombNote(Engine engine, BaseBombNote bomb) : base(engine, bomb) - { - spawned = true; - } - - public BombNote(Engine engine, ObjectInstance o) : base(engine, new V3BombNote( - (float)GetJsValue(o, "b"), - (int)GetJsValue(o, "x"), - (int)GetJsValue(o, "y"), - GetCustomData(o, new string[] { "customData", "_customData" }) - ), false, GetJsBool(o, "selected")) - { - spawned = false; - - DeleteObject(); - } - public override bool SpawnObject(BeatmapObjectContainerCollection collection) { if (spawned) return false; @@ -76,4 +74,3 @@ internal override bool DeleteObject() return true; } } -} diff --git a/Wrappers/V3/BpmChange.cs b/Wrappers/Beatmap/BpmChange.cs similarity index 60% rename from Wrappers/V3/BpmChange.cs rename to Wrappers/Beatmap/BpmChange.cs index a5f76b0..bd9ed06 100644 --- a/Wrappers/V3/BpmChange.cs +++ b/Wrappers/Beatmap/BpmChange.cs @@ -1,13 +1,29 @@ using Beatmap.Base.Customs; using Beatmap.Enums; +using Beatmap.Helper; using Beatmap.V3.Customs; using Jint; using Jint.Native.Object; -namespace V3 -{ - class BpmChange : Wrapper + internal class BpmChange : Wrapper { + public BpmChange(Engine engine, BaseBpmChange bpmChange) : base(engine, bpmChange) + { + spawned = true; + } + + public BpmChange(Engine engine, ObjectInstance o) : base(engine, BeatmapFactory.BpmChange( + (float)GetJsValue(o, new [] { "b", "_time" }), + (float)GetJsValue(o, new [] { "m", "_BPM" }) + ), false, GetJsBool(o, "selected")) + { + spawned = false; + wrapped.BeatsPerBar = (float)(GetJsValue(o, new[] { "p", "_beatsPerBar" }) ?? 4f); + wrapped.MetronomeOffset = (float)(GetJsValue(o, new[] { "o", "_metronomeOffset" }) ?? 4f); + + DeleteObject(); + } + public float _time { get => wrapped.Time; @@ -48,23 +64,44 @@ public float _metronomeOffset } } - public BpmChange(Engine engine, BaseBpmChange bpmChange) : base(engine, bpmChange) + public float b { - spawned = true; + get => wrapped.Time; + set + { + DeleteObject(); + wrapped.Time = value; + } } - public BpmChange(Engine engine, ObjectInstance o) : base(engine, new V3BpmChange( - (float)GetJsValue(o, "m"), - (float)GetJsValue(o, "b") - ) + public float m { - BeatsPerBar = (float)GetJsValue(o, "p"), - MetronomeOffset = (float)GetJsValue(o, "o") - }, false, GetJsBool(o, "selected")) + get => wrapped.Bpm; + set + { + DeleteObject(); + wrapped.Bpm = value; + } + } + + public float p { - spawned = false; + get => wrapped.BeatsPerBar; + set + { + DeleteObject(); + wrapped.BeatsPerBar = value; + } + } - DeleteObject(); + public float o + { + get => wrapped.MetronomeOffset; + set + { + DeleteObject(); + wrapped.MetronomeOffset = value; + } } public override bool SpawnObject(BeatmapObjectContainerCollection collection) @@ -93,4 +130,3 @@ internal override void Reconcile() // Nothing :) } } -} diff --git a/Wrappers/V3/Chain.cs b/Wrappers/Beatmap/Chain.cs similarity index 75% rename from Wrappers/V3/Chain.cs rename to Wrappers/Beatmap/Chain.cs index 6674ebc..7f6388b 100644 --- a/Wrappers/V3/Chain.cs +++ b/Wrappers/Beatmap/Chain.cs @@ -1,14 +1,36 @@ -using Jint; -using Jint.Native.Object; -using System.Collections.Generic; -using Beatmap.Base; +using Beatmap.Base; using Beatmap.Enums; -using Beatmap.V3; +using Beatmap.Helper; +using Jint; +using Jint.Native.Object; -namespace V3 -{ - class Chain : VanillaWrapper + internal class Chain : VanillaWrapper { + public Chain(Engine engine, BaseChain chain) : base(engine, chain) + { + spawned = true; + } + + public Chain(Engine engine, ObjectInstance o) : base(engine, BeatmapFactory.Chain( + (int)GetJsValue(o, "b"), + (int)GetJsValue(o, "c"), + (int)GetJsValue(o, "x"), + (int)GetJsValue(o, "y"), + (int)GetJsValue(o, "d"), + 0, + (float)GetJsValue(o, "tb"), + (int)GetJsValue(o, "tx"), + (int)GetJsValue(o, "ty"), + (int)GetJsValue(o, "sc"), + (float)GetJsValue(o, "s"), + GetCustomData(o, new[] { "customData", "_customData" }) + ), false, GetJsBool(o, "selected")) + { + spawned = false; + + DeleteObject(); + } + public float b { get => wrapped.Time; @@ -109,32 +131,6 @@ public float s } } - public Chain(Engine engine, BaseChain chain) : base(engine, chain) - { - spawned = true; - } - - public Chain(Engine engine, ObjectInstance o) : base(engine, new V3Chain(JSONWrapper.dictToJSON(new Dictionary() - { - { "b", (float)GetJsValue(o, "b") }, - { "c", (int)GetJsValue(o, "c") }, - { "x", (int) GetJsValue(o, "x") }, - { "y", (int)GetJsValue(o, "y") }, - { "d", (int)GetJsValue(o, "d") }, - { "tb", (float)GetJsValue(o, "tb") }, - { "tx", (int)GetJsValue(o, "tx") }, - { "ty", (int)GetJsValue(o, "ty") }, - { "sc", (int)GetJsValue(o, "sc") }, - { "s", (float)GetJsValue(o, "s") }, - { "customData", GetCustomData(o, new string[] { "customData", "_customData" }) } - })), false, GetJsBool(o, "selected")) - { - spawned = false; - wrapped.CustomData = GetCustomData(o, new string[] { "customData", "_customData" }); - - DeleteObject(); - } - public override bool SpawnObject(BeatmapObjectContainerCollection collection) { if (spawned) return false; @@ -156,4 +152,3 @@ internal override bool DeleteObject() return true; } } -} diff --git a/Wrappers/V2/CustomEvent.cs b/Wrappers/Beatmap/CustomEvent.cs similarity index 69% rename from Wrappers/V2/CustomEvent.cs rename to Wrappers/Beatmap/CustomEvent.cs index 1657b07..09c7147 100644 --- a/Wrappers/V2/CustomEvent.cs +++ b/Wrappers/Beatmap/CustomEvent.cs @@ -1,14 +1,33 @@ using System; using Beatmap.Base.Customs; using Beatmap.Enums; -using Beatmap.V2.Customs; +using Beatmap.Helper; using Jint; using Jint.Native.Object; -namespace V2 -{ - class CustomEvent : Wrapper + internal class CustomEvent : Wrapper { + private Lazy customData; + private Action reconcile; + + public CustomEvent(Engine engine, BaseCustomEvent customEvent) : base(engine, customEvent) + { + spawned = true; + InitWrapper(); + } + + public CustomEvent(Engine engine, ObjectInstance o) : base(engine, BeatmapFactory.CustomEvent( + (float)GetJsValue(o, new [] { "b", "_time" }), + GetJsString(o, new [] { "t", "_type" }), + GetCustomData(o, new [] { "d", "_data" }) + ), false, GetJsBool(o, "selected")) + { + spawned = false; + + DeleteObject(); + InitWrapper(); + } + public float _time { get => wrapped.Time; @@ -29,8 +48,6 @@ public string _type } } - private Lazy customData; - private Action reconcile; public object _data { get => wrapped.CustomData == null ? null : customData.Value; @@ -42,22 +59,35 @@ public object _data } } - public CustomEvent(Engine engine, BaseCustomEvent customEvent) : base(engine, customEvent) + public float b { - spawned = true; - InitWrapper(); + get => wrapped.Time; + set + { + DeleteObject(); + wrapped.Time = value; + } } - public CustomEvent(Engine engine, ObjectInstance o) : base(engine, new V2CustomEvent( - (float)GetJsValue(o, "_time"), - GetJsString(o, "_type"), - GetCustomData(o, "_data") - ), false, GetJsBool(o, "selected")) + public string t { - spawned = false; + get => wrapped.Type; + set + { + DeleteObject(); + wrapped.Type = value; + } + } - DeleteObject(); - InitWrapper(); + public object d + { + get => wrapped.CustomData == null ? null : customData.Value; + set + { + DeleteObject(); + wrapped.CustomData = JSONWrapper.castObjToJSON(value); + InitWrapper(); + } } public override bool SpawnObject(BeatmapObjectContainerCollection collection) @@ -94,4 +124,3 @@ internal override void Reconcile() reconcile?.Invoke(); } } -} diff --git a/Wrappers/V3/Event.cs b/Wrappers/Beatmap/Event.cs similarity index 81% rename from Wrappers/V3/Event.cs rename to Wrappers/Beatmap/Event.cs index afef0c9..4a68bdb 100644 --- a/Wrappers/V3/Event.cs +++ b/Wrappers/Beatmap/Event.cs @@ -1,13 +1,29 @@ -using Jint; -using Jint.Native.Object; -using Beatmap.Base; +using Beatmap.Base; using Beatmap.Enums; -using Beatmap.V3; +using Beatmap.Helper; +using Jint; +using Jint.Native.Object; -namespace V3 -{ - class Event : VanillaWrapper + internal class Event : VanillaWrapper { + public Event(Engine engine, BaseEvent mapEvent) : base(engine, mapEvent) + { + spawned = true; + } + + public Event(Engine engine, ObjectInstance o) : base(engine, BeatmapFactory.Event( + (float)GetJsValue(o, new[] { "b", "_time" }), + (int)GetJsValue(o, new[] { "et", "_type" }), + (int)GetJsValue(o, new[] { "i", "_value" }), + (float)GetJsValue(o, new[] { "f", "_floatValue" }), + GetCustomData(o, new[] { "customData", "_customData" }) + ), false, GetJsBool(o, "selected")) + { + spawned = false; + + DeleteObject(); + } + public float _time { get => wrapped.Time; @@ -88,25 +104,6 @@ public float f } } - - public Event(Engine engine, BaseEvent mapEvent) : base(engine, mapEvent) - { - spawned = true; - } - - public Event(Engine engine, ObjectInstance o) : base(engine, new V3BasicEvent( - (float)GetJsValue(o, new string[] { "b", "_time" }), - (int)GetJsValue(o, new string[] { "et", "_type" }), - (int)GetJsValue(o, new string[] { "i", "_value" }), - (float)GetJsValue(o, new string[] { "f", "_floatValue" }), - GetCustomData(o, new string[] { "customData", "_customData" }) - ), false, GetJsBool(o, "selected")) - { - spawned = false; - - DeleteObject(); - } - public override bool SpawnObject(BeatmapObjectContainerCollection collection) { if (spawned) return false; @@ -128,4 +125,3 @@ internal override bool DeleteObject() return true; } } -} diff --git a/Wrappers/V2/Note.cs b/Wrappers/Beatmap/Note.cs similarity index 78% rename from Wrappers/V2/Note.cs rename to Wrappers/Beatmap/Note.cs index 96fcc8a..7053da6 100644 --- a/Wrappers/V2/Note.cs +++ b/Wrappers/Beatmap/Note.cs @@ -1,13 +1,31 @@ using Beatmap.Base; using Beatmap.Enums; -using Beatmap.V2; +using Beatmap.Helper; using Jint; using Jint.Native.Object; -namespace V2 -{ - class Note : VanillaWrapper + internal class Note : VanillaWrapper { + public Note(Engine engine, BaseNote note) : base(engine, note) + { + spawned = true; + } + + public Note(Engine engine, ObjectInstance o) : base(engine, BeatmapFactory.Note( + (float)GetJsValue(o, new[] { "b", "_time" }), + (int)GetJsValue(o, new[] { "x", "_lineIndex" }), + (int)GetJsValue(o, new[] { "y", "_lineLayer" }), + (int)GetJsValue(o, new[] { "c", "_type" }), + (int)GetJsValue(o, new[] { "d", "_cutDirection" }), + (int)(GetJsValueOptional(o, "a") ?? 0), + GetCustomData(o, new[] { "customData", "_customData" }) + ), false, GetJsBool(o, "selected")) + { + spawned = false; + + DeleteObject(); + } + public float _time { get => wrapped.Time; @@ -50,11 +68,11 @@ public int _cutDirection public int _type { - get => wrapped.Type; + get => wrapped.Color; set { DeleteObject(); - wrapped.Type = value; + wrapped.Color = value; } } @@ -90,19 +108,21 @@ public int y public int a { - get => 0; + get => wrapped.AngleOffset; set { + DeleteObject(); + wrapped.AngleOffset = value; } } public int c { - get => wrapped.Type; + get => wrapped.Color; set { DeleteObject(); - wrapped.Type = value; + wrapped.Color = value; } } @@ -116,25 +136,6 @@ public int d } } - public Note(Engine engine, BaseNote note) : base(engine, note) - { - spawned = true; - } - - public Note(Engine engine, ObjectInstance o) : base(engine, new V2Note( - (float)GetJsValue(o, new string[] { "_time", "b" }), - (int)GetJsValue(o, new string[] { "_lineIndex", "x" }), - (int)GetJsValue(o, new string[] { "_lineLayer", "y" }), - (int)GetJsValue(o, new string[] { "_type", "c" }), - (int)GetJsValue(o, new string[] { "_cutDirection", "d" }), - GetCustomData(o, new string[] { "_customData", "customData" }) - ), false, GetJsBool(o, "selected")) - { - spawned = false; - - DeleteObject(); - } - public override bool SpawnObject(BeatmapObjectContainerCollection collection) { if (spawned) return false; @@ -156,4 +157,3 @@ internal override bool DeleteObject() return true; } } -} diff --git a/Wrappers/V2/Wall.cs b/Wrappers/Beatmap/Wall.cs similarity index 78% rename from Wrappers/V2/Wall.cs rename to Wrappers/Beatmap/Wall.cs index 268119f..efc6fb0 100644 --- a/Wrappers/V2/Wall.cs +++ b/Wrappers/Beatmap/Wall.cs @@ -1,13 +1,31 @@ using Beatmap.Base; using Beatmap.Enums; -using Beatmap.V2; +using Beatmap.Helper; using Jint; using Jint.Native.Object; -namespace V2 -{ - class Wall : VanillaWrapper + internal class Wall : VanillaWrapper { + public Wall(Engine engine, BaseObstacle wall) : base(engine, wall) + { + spawned = true; + } + + public Wall(Engine engine, ObjectInstance o) : base(engine, BeatmapFactory.Obstacle( + (float)GetJsValue(o, new[] { "b", "_time" }), + (int)GetJsValue(o, new[] { "x", "_lineIndex" }), + (int)(GetJsExist(o, "y") ? GetJsValue(o, "y") : GetJsValue(o, "_type") == 0 ? 0 : 2), + (int)GetJsValue(o, "_type"), + (float)GetJsValue(o, new[] { "d", "_duration" }), + (int)GetJsValue(o, new[] { "w", "_width" }), + (int)(GetJsExist(o, "h") ? GetJsValue(o, "h") : GetJsValue(o, "_type") == 0 ? 5 : 3), + GetCustomData(o, new[] { "customData", "_customData" })), false, GetJsBool(o, "selected")) + { + spawned = false; + + DeleteObject(); + } + public float _time { get => wrapped.Time; @@ -28,16 +46,6 @@ public int _lineIndex } } - public int _lineLayer - { - get => wrapped.PosY; - set - { - DeleteObject(); - wrapped.PosY = value; - } - } - public int _type { get => wrapped.Type; @@ -68,16 +76,6 @@ public int _width } } - public int _height - { - get => wrapped.Height; - set - { - DeleteObject(); - wrapped.Height = value; - } - } - public float b { get => wrapped.Time; @@ -100,9 +98,11 @@ public int x public int y { - get => 0; + get => wrapped.PosY; set { + DeleteObject(); + wrapped.PosY = value; } } @@ -128,31 +128,14 @@ public int w public int h { - get => 0; + get => wrapped.Height; set { + DeleteObject(); + wrapped.Height = value; } } - public Wall(Engine engine, BaseObstacle wall) : base(engine, wall) - { - spawned = true; - } - - public Wall(Engine engine, ObjectInstance o) : base(engine, new V2Obstacle( - (float)GetJsValue(o, new string[] { "_time", "b" }), - (int)GetJsValue(o, new string[] { "_lineIndex", "x" }), - (int)(GetJsValueOptional(o, "_type") ?? (GetJsValue(o, "y") < 2 ? 0 : 1)), - (float)GetJsValue(o, new string[] { "_duration", "d" }), - (int)GetJsValue(o, new string[] { "_width", "w" }), - GetCustomData(o, new string[] { "_customData", "customData" }) - ), false, GetJsBool(o, "selected")) - { - spawned = false; - - DeleteObject(); - } - public override bool SpawnObject(BeatmapObjectContainerCollection collection) { if (spawned) return false; @@ -174,4 +157,3 @@ internal override bool DeleteObject() return true; } } -} diff --git a/Wrappers/V2/BpmChange.cs b/Wrappers/V2/BpmChange.cs deleted file mode 100644 index 4f2b6e2..0000000 --- a/Wrappers/V2/BpmChange.cs +++ /dev/null @@ -1,96 +0,0 @@ -using Beatmap.Base.Customs; -using Beatmap.Enums; -using Beatmap.V2.Customs; -using Jint; -using Jint.Native.Object; - -namespace V2 -{ - class BpmChange : Wrapper - { - public float _time - { - get => wrapped.Time; - set - { - DeleteObject(); - wrapped.Time = value; - } - } - - public float _BPM - { - get => wrapped.Bpm; - set - { - DeleteObject(); - wrapped.Bpm = value; - } - } - - public float _beatsPerBar - { - get => wrapped.BeatsPerBar; - set - { - DeleteObject(); - wrapped.BeatsPerBar = value; - } - } - - public float _metronomeOffset - { - get => wrapped.MetronomeOffset; - set - { - DeleteObject(); - wrapped.MetronomeOffset = value; - } - } - - public BpmChange(Engine engine, BaseBpmChange bpmChange) : base(engine, bpmChange) - { - spawned = true; - } - - public BpmChange(Engine engine, ObjectInstance o) : base(engine, new V2BpmChange( - (float)GetJsValue(o, "_BPM"), - (float)GetJsValue(o, "_time") - ) - { - BeatsPerBar = (float)GetJsValue(o, "_beatsPerBar"), - MetronomeOffset = (float)GetJsValue(o, "_metronomeOffset") - }, false, GetJsBool(o, "selected")) - { - spawned = false; - - DeleteObject(); - } - - public override bool SpawnObject(BeatmapObjectContainerCollection collection) - { - if (spawned) return false; - - collection.SpawnObject(wrapped, false, false); - - spawned = true; - return true; - } - - internal override bool DeleteObject() - { - if (!spawned) return false; - - var collection = BeatmapObjectContainerCollection.GetCollectionForType(ObjectType.BpmChange); - collection.DeleteObject(wrapped, false); - - spawned = false; - return true; - } - - internal override void Reconcile() - { - // Nothing :) - } - } -} diff --git a/Wrappers/V2/Event.cs b/Wrappers/V2/Event.cs deleted file mode 100644 index d4ecb48..0000000 --- a/Wrappers/V2/Event.cs +++ /dev/null @@ -1,136 +0,0 @@ -using Beatmap.Base; -using Beatmap.Enums; -using Beatmap.Shared; -using Beatmap.V2; -using Jint; -using Jint.Native.Object; - -namespace V2 -{ - class Event : VanillaWrapper - { - public float _time - { - get => wrapped.Time; - set - { - DeleteObject(); - wrapped.Time = value; - } - } - - public int _type - { - get => wrapped.Type; - set - { - DeleteObject(); - wrapped.Type = value; - } - } - - public int _value - { - get => wrapped.Value; - set - { - DeleteObject(); - wrapped.Value = value; - } - } - - public float _floatValue - { - get => wrapped.FloatValue; - set - { - DeleteObject(); - wrapped.FloatValue = value; - } - } - - public float b - { - get => wrapped.Time; - set - { - DeleteObject(); - wrapped.Time = value; - } - } - - public int et - { - get => wrapped.Type; - set - { - DeleteObject(); - wrapped.Type = value; - } - } - - public int i - { - get => wrapped.Value; - set - { - DeleteObject(); - wrapped.Value = value; - } - } - - public float f - { - get => wrapped.FloatValue; - set - { - DeleteObject(); - wrapped.FloatValue = value; - } - } - - public Event(Engine engine, BaseEvent mapEvent) : base(engine, mapEvent) - { - spawned = true; - } - - public Event(Engine engine, ObjectInstance o) : base(engine, new V2Event( - (float)GetJsValue(o, new string[] { "_time", "b" }), - (int)GetJsValue(o, new string[] { "_type", "et" }), - (int)GetJsValue(o, new string[] { "_value", "i" }), - (float)GetJsValue(o, new string[] { "_floatValue", "f" }), - GetCustomData(o, new string[] { "_customData", "customData" }) - ), false, GetJsBool(o, "selected")) - { - spawned = false; - - DeleteObject(); - } - - public override bool SpawnObject(BeatmapObjectContainerCollection collection) - { - if (spawned) return false; - - if (wrapped.CustomData != null && wrapped.CustomData["_lightGradient"] != null) - { - wrapped.CustomLightGradient = new ChromaLightGradient(wrapped.CustomData["_lightGradient"]); - } - - collection.SpawnObject(wrapped, false, false); - - spawned = true; - return true; - } - - internal override bool DeleteObject() - { - if (!spawned) return false; - - var collection = BeatmapObjectContainerCollection.GetCollectionForType(ObjectType.Event); - collection.DeleteObject(wrapped, false); - - spawned = false; - return true; - } - } -} diff --git a/Wrappers/V3/ColorNote.cs b/Wrappers/V3/ColorNote.cs deleted file mode 100644 index dd5b0b5..0000000 --- a/Wrappers/V3/ColorNote.cs +++ /dev/null @@ -1,162 +0,0 @@ -using Beatmap.Base; -using Beatmap.Enums; -using Beatmap.V3; -using Jint; -using Jint.Native.Object; - -namespace V3 -{ - class ColorNote : VanillaWrapper - { - public float _time - { - get => wrapped.Time; - set - { - DeleteObject(); - wrapped.Time = value; - } - } - - public int _lineIndex - { - get => wrapped.PosX; - set - { - DeleteObject(); - wrapped.PosX = value; - } - } - - public int _lineLayer - { - get => wrapped.PosY; - set - { - DeleteObject(); - wrapped.PosY = value; - } - } - - public int _cutDirection - { - get => wrapped.CutDirection; - set - { - DeleteObject(); - wrapped.CutDirection = value; - } - } - - public int _type - { - get => wrapped.Color; - set - { - DeleteObject(); - wrapped.Color = value; - } - } - - public float b - { - get => wrapped.Time; - set - { - DeleteObject(); - wrapped.Time = value; - } - } - - public int x - { - get => wrapped.PosX; - set - { - DeleteObject(); - wrapped.PosX = value; - } - } - - public int y - { - get => wrapped.PosY; - set - { - DeleteObject(); - wrapped.PosY = value; - } - } - - public int a - { - get => wrapped.AngleOffset; - set - { - DeleteObject(); - wrapped.AngleOffset = value; - } - } - - public int c - { - get => wrapped.Color; - set - { - DeleteObject(); - wrapped.Color = value; - } - } - - public int d - { - get => wrapped.CutDirection; - set - { - DeleteObject(); - wrapped.CutDirection = value; - } - } - - public ColorNote(Engine engine, BaseNote note) : base(engine, note) - { - spawned = true; - } - - public ColorNote(Engine engine, ObjectInstance o) : base(engine, new V3ColorNote( - (float)GetJsValue(o, new string[] { "b", "_time" }), - (int)GetJsValue(o, new string[] { "x", "_lineIndex" }), - (int)GetJsValue(o, new string[] { "y", "_lineLayer" }), - (int)GetJsValue(o, new string[] { "c", "_type" }), - (int)GetJsValue(o, new string[] { "d", "_cutDirection" }), - (int)(GetJsValueOptional(o, "a") ?? 0), - GetCustomData(o, new string[] { "customData", "_customData" }) - ), false, GetJsBool(o, "selected")) - { - spawned = false; - - DeleteObject(); - } - - public override bool SpawnObject(BeatmapObjectContainerCollection collection) - { - if (spawned) return false; - - collection.SpawnObject(wrapped, false, false); - - spawned = true; - return true; - } - - internal override bool DeleteObject() - { - if (!spawned) return false; - - var collection = BeatmapObjectContainerCollection.GetCollectionForType(ObjectType.Note); - collection.DeleteObject(wrapped, false); - - spawned = false; - return true; - } - } -} diff --git a/Wrappers/V3/CustomEvent.cs b/Wrappers/V3/CustomEvent.cs deleted file mode 100644 index 4681708..0000000 --- a/Wrappers/V3/CustomEvent.cs +++ /dev/null @@ -1,97 +0,0 @@ -using System; -using Beatmap.Base.Customs; -using Beatmap.Enums; -using Beatmap.V3.Customs; -using Jint; -using Jint.Native.Object; - -namespace V3 -{ - class CustomEvent : Wrapper - { - public float _time - { - get => wrapped.Time; - set - { - DeleteObject(); - wrapped.Time = value; - } - } - - public string _type - { - get => wrapped.Type; - set - { - DeleteObject(); - wrapped.Type = value; - } - } - - private Lazy customData; - private Action reconcile; - public object _data - { - get => wrapped.CustomData == null ? null : customData.Value; - set - { - DeleteObject(); - wrapped.CustomData = JSONWrapper.castObjToJSON(value); - InitWrapper(); - } - } - - public CustomEvent(Engine engine, BaseCustomEvent customEvent) : base(engine, customEvent) - { - spawned = true; - InitWrapper(); - } - - public CustomEvent(Engine engine, ObjectInstance o) : base(engine, new V3CustomEvent( - (float)GetJsValue(o, "b"), - GetJsString(o, "t"), - GetCustomData(o, "d") - ), false, GetJsBool(o, "selected")) - { - spawned = false; - - DeleteObject(); - InitWrapper(); - } - - public override bool SpawnObject(BeatmapObjectContainerCollection collection) - { - if (spawned) return false; - - collection.SpawnObject(wrapped, false, false); - - spawned = true; - return true; - } - - internal override bool DeleteObject() - { - if (!spawned) return false; - - var collection = BeatmapObjectContainerCollection.GetCollectionForType(ObjectType.CustomEvent); - collection.DeleteObject(wrapped, false); - - spawned = false; - return true; - } - - private void InitWrapper() - { - reconcile = null; - customData = new Lazy(() => - new JSONWrapper(engine, ref reconcile, wrapped.CustomData, DeleteObject) - ); - } - - internal override void Reconcile() - { - reconcile?.Invoke(); - } - } -} diff --git a/Wrappers/V3/Wall.cs b/Wrappers/V3/Wall.cs deleted file mode 100644 index f3a9b4a..0000000 --- a/Wrappers/V3/Wall.cs +++ /dev/null @@ -1,185 +0,0 @@ -using Jint; -using Jint.Native.Object; -using System.Collections.Generic; -using Beatmap.Base; -using Beatmap.Enums; -using Beatmap.V3; - -namespace V3 -{ - class Wall : VanillaWrapper - { - public float _time - { - get => wrapped.Time; - set - { - DeleteObject(); - wrapped.Time = value; - } - } - - public int _lineIndex - { - get => wrapped.PosX; - set - { - DeleteObject(); - wrapped.PosX = value; - } - } - - public int _lineLayer - { - get => wrapped.PosY; - set - { - DeleteObject(); - wrapped.PosY = value; - } - } - - public int _type - { - get => wrapped.Type; - set - { - DeleteObject(); - wrapped.Type = value; - } - } - - public float _duration - { - get => wrapped.Duration; - set - { - DeleteObject(); - wrapped.Duration = value; - } - } - - public int _width - { - get => wrapped.Width; - set - { - DeleteObject(); - wrapped.Width = value; - } - } - - public int _height - { - get => wrapped.Height; - set - { - DeleteObject(); - wrapped.Height = value; - } - } - - public float b - { - get => wrapped.Time; - set - { - DeleteObject(); - wrapped.Time = value; - } - } - - public int x - { - get => wrapped.PosX; - set - { - DeleteObject(); - wrapped.PosX = value; - } - } - - public int y - { - get => wrapped.PosY; - set - { - DeleteObject(); - wrapped.PosY = value; - } - } - - public float d - { - get => wrapped.Duration; - set - { - DeleteObject(); - wrapped.Duration = value; - } - } - - public int w - { - get => wrapped.Width; - set - { - DeleteObject(); - wrapped.Width = value; - } - } - - public int h - { - get => wrapped.Height; - set - { - DeleteObject(); - wrapped.Height = value; - } - } - - public Wall(Engine engine, BaseObstacle wall) : base(engine, wall) - { - spawned = true; - } - - public Wall(Engine engine, ObjectInstance o) : base(engine, new V3Obstacle(JSONWrapper.dictToJSON(new Dictionary() - { - { "b", (float)GetJsValue(o, new string[] { "b", "_time" }) }, - { "x", (int)GetJsValue(o, new string[] { "x", "_lineIndex" }) }, - { "y", (int)(GetJsExist(o, "_type") ? (GetJsValue(o, "_type") == 0 ? 0 : 2) : GetJsValue(o, "y")) }, - { "d", (float)GetJsValue(o, new string[] { "d", "_duration" }) }, - { "w", (int)GetJsValue(o, new string[] { "w", "_width" }) }, - { "h", (int)(GetJsExist(o, "_type") ? (GetJsValue(o, "_type") == 0 ? 5 : 3) : GetJsValue(o, "h")) }, - { "customData", GetCustomData(o, new string[] { "customData", "_customData" }) } - })), false, GetJsBool(o, "selected")) - { - spawned = false; - wrapped.CustomData = GetCustomData(o, new string[] { "customData", "_customData" }); - - DeleteObject(); - } - - public override bool SpawnObject(BeatmapObjectContainerCollection collection) - { - if (spawned) return false; - - collection.SpawnObject(wrapped, false, false); - - spawned = true; - return true; - } - - internal override bool DeleteObject() - { - if (!spawned) return false; - - var collection = BeatmapObjectContainerCollection.GetCollectionForType(ObjectType.Obstacle); - collection.DeleteObject(wrapped, false); - - spawned = false; - return true; - } - } -} diff --git a/Wrappers/Wrapper.cs b/Wrappers/Wrapper.cs index 0c3ccbe..ee544b7 100644 --- a/Wrappers/Wrapper.cs +++ b/Wrappers/Wrapper.cs @@ -37,7 +37,7 @@ protected static double GetJsValue(ObjectInstance o, string key) protected static double? GetJsValue(ObjectInstance o, IEnumerable key) { - foreach (string k in key) + foreach (var k in key) { if (o.TryGetValue(k, out var value)) { @@ -69,6 +69,19 @@ protected static string GetJsString(ObjectInstance o, string key) return (string)value.ToObject(); } + protected static string GetJsString(ObjectInstance o, IEnumerable key) + { + foreach (var k in key) + { + if (o.TryGetValue(k, out var value)) + { + return (string)value.ToObject(); + } + } + + return null; + } + protected static bool? GetJsBool(ObjectInstance o, string key) { if (o.TryGetValue(key, out var value)) From 73599ee761e4742324c76849f2cf2e41ec325621 Mon Sep 17 00:00:00 2001 From: Kival Evan <5645391+KivalEvan@users.noreply.github.com> Date: Sat, 28 Jan 2023 03:38:13 -0800 Subject: [PATCH 14/26] Add LiteNetLib to reference --- ErrorChecker.csproj | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ErrorChecker.csproj b/ErrorChecker.csproj index c22be18..548b518 100644 --- a/ErrorChecker.csproj +++ b/ErrorChecker.csproj @@ -6,7 +6,6 @@ - F:\Programs\CM Dev Debug AnyCPU {600D3953-D125-4C0F-A5CF-0E3906D6B6F6} @@ -64,6 +63,10 @@ $(ChromapperDir)\ChroMapper_Data\Managed\Plugins.dll False + + $(ChromapperDir)\ChroMapper_Data\Managed\LiteNetLib.dll + False + $(ChromapperDir)\ChroMapper_Data\Managed\0Harmony.dll False From ba8aff6187c7f5258e530538f5c1df6bffc92661 Mon Sep 17 00:00:00 2001 From: Kival Evan <5645391+KivalEvan@users.noreply.github.com> Date: Sat, 28 Jan 2023 03:50:20 -0800 Subject: [PATCH 15/26] Fix built in script and remove redundant method --- CMJS.cs | 2 +- Checks/Check.cs | 14 ------ Checks/ExternalJS.cs | 111 ----------------------------------------- Checks/StackedNotes.cs | 2 +- Checks/VisionBlocks.cs | 2 +- 5 files changed, 3 insertions(+), 128 deletions(-) diff --git a/CMJS.cs b/CMJS.cs index 37e1421..85f1ac1 100644 --- a/CMJS.cs +++ b/CMJS.cs @@ -135,7 +135,7 @@ public void CheckErrors(Check check) var allEvents = eventsContainer.LoadedObjects.Cast().OrderBy(it => it.Time).ToList(); var allCustomEvents = customEventsContainer.LoadedObjects.Cast().OrderBy(it => it.Time).ToList(); var allBpmChanges = bpmChangesContainer.LoadedObjects.Cast().OrderBy(it => it.Time).ToList(); - errors = check.PerformCheck(allNotes, allEvents, allWalls, allCustomEvents, allBpmChanges, vals).Commit(); + errors = check.PerformCheck(allNotes, new List(), new List(), new List(), allEvents, allWalls, allCustomEvents, allBpmChanges, vals).Commit(); } // Highlight blocks in loaded containers in case we don't scrub far enough with MoveToTimeInBeats to load them diff --git a/Checks/Check.cs b/Checks/Check.cs index 6752610..dc466e8 100644 --- a/Checks/Check.cs +++ b/Checks/Check.cs @@ -20,20 +20,6 @@ protected Check() : this("") } - protected virtual CheckResult PerformCheck(List notes, List events, List walls, List customEvents, List bpmChanges) - { - throw new ArgumentException("Wrong number of parameters"); - } - - public virtual CheckResult PerformCheck(List notes, List events, List walls, List customEvents, List bpmChanges, params IParamValue[] vals) - { - if (vals.Length == 0 && Params.Count == 0) - { - return PerformCheck(notes, events, walls, customEvents, bpmChanges); - } - throw new ArgumentException("Wrong number of parameters"); - } - protected virtual CheckResult PerformCheck(List notes, List bombs, List arcs, List chains, List events, List walls, List customEvents, List bpmChanges) { throw new ArgumentException("Wrong number of parameters"); diff --git a/Checks/ExternalJS.cs b/Checks/ExternalJS.cs index afd6b10..832cb54 100644 --- a/Checks/ExternalJS.cs +++ b/Checks/ExternalJS.cs @@ -250,117 +250,6 @@ public MapData(float currentBPM, float songBPM, float NJS, float offset, string } } - public override CheckResult PerformCheck(List notes, List events, List walls, List customEvents, List bpmChanges, params IParamValue[] vals) - { - result.Clear(); - - var atsc = BeatmapObjectContainerCollection.GetCollectionForType(ObjectType.Note).AudioTimeSyncController; - var currentBeat = atsc.CurrentBeat; - - var collection = BeatmapObjectContainerCollection.GetCollectionForType(ObjectType.BpmChange); - var lastBPMChange = collection.FindLastBpm(atsc.CurrentBeat); - var currentBPM = lastBPMChange?.Bpm ?? atsc.Song.BeatsPerMinute; - - var originalNotes = notes.Select(it => new Note(engine, it)).ToArray(); - var originalWalls = walls.Select(it => new Wall(engine, it)).ToArray(); - var originalEvents = events.Select(it => new Event(engine, it)).ToArray(); - var originalCustomEvents = customEvents.Select(it => new CustomEvent(engine, it)).ToArray(); - var originalBpmChanges = bpmChanges.Select(it => new BpmChange(engine, it)).ToArray(); - - try - { - var valsToString = vals.Select(paramValue => - { - switch (paramValue) - { - case ParamValue pvf: - return pvf.value.ToString(); - case ParamValue pvs: - return $"\"{pvs.value}\""; - case ParamValue pvb: - return pvb.value ? "true" : "false"; - default: - return "null"; - } - }); - - var valsCombined = string.Join(",", valsToString); - - TimeLog("Init"); - - var tmp = engine - .SetValue("notes", originalNotes) - .SetValue("walls", originalWalls) - .SetValue("events", originalEvents) - .SetValue("customEvents", originalCustomEvents) - .SetValue("bpmChanges", originalBpmChanges) - .SetValue("data", new MapData( - currentBPM, - atsc.Song.BeatsPerMinute, - BeatSaberSongContainer.Instance.DifficultyData.NoteJumpMovementSpeed, - BeatSaberSongContainer.Instance.DifficultyData.NoteJumpStartBeatOffset, - BeatSaberSongContainer.Instance.DifficultyData.ParentBeatmapSet.BeatmapCharacteristicName, - BeatSaberSongContainer.Instance.DifficultyData.Difficulty, - (BeatSaberSongContainer.Instance.DifficultyData.ParentBeatmapSet.BeatmapCharacteristicName == "360Degree" || BeatSaberSongContainer.Instance.DifficultyData.ParentBeatmapSet.BeatmapCharacteristicName == "90Degree") ? BeatSaberSongContainer.Instance.Song.AllDirectionsEnvironmentName : BeatSaberSongContainer.Instance.Song.EnvironmentName, - BeatSaberSongContainer.Instance.Map.Version - )) - .SetValue("cursor", currentBeat) - .SetValue("minTime", 0.24f) - .SetValue("maxTime", 0.75f) - .SetValue("addError", new Action((dynamic note, string str) => - { - var obj = FromDynamic(note, notes); - - if (obj != null) - result.Add(obj, str ?? ""); - })) - .SetValue("addWarning", new Action((dynamic note, string str) => - { - var obj = FromDynamic(note, notes); - - if (obj != null) - result.AddWarning(obj, str ?? ""); - })); - - TimeLog("Run"); - - tmp.Execute("global.params = [" + valsCombined + "];" + - "var output = module.exports.run ? module.exports.run(cursor, notes, events, walls, {}, global, data, customEvents, bpmChanges) : module.exports.performCheck({notes: notes}" + (vals.Length > 0 ? ", " + valsCombined : "") + ");" + - "if (output && output.notes) { notes = output.notes; };" + - "if (output && output.events) { events = output.events; };" + - "if (output && output.customEvents) { customEvents = output.customEvents; };" + - "if (output && output.bpmChanges) { bpmChanges = output.bpmChanges; };" + - "if (output && output.walls) { walls = output.walls; };"); - } - catch (JavaScriptException jse) - { - Debug.LogWarning($"Error running {fileName}\n{jse.Message}"); - } - - TimeLog("Reconcile"); - - SelectionController.DeselectAll(); - var actions = new List(); - actions.AddRange(Reconcile(originalNotes, engine.GetValue("notes").AsArray(), notes, i => new Note(engine, i), ObjectType.Note)); - actions.AddRange(Reconcile(originalWalls, engine.GetValue("walls").AsArray(), walls, i => new Wall(engine, i), ObjectType.Obstacle)); - actions.AddRange(Reconcile(originalEvents, engine.GetValue("events").AsArray(), events, i => new Event(engine, i), ObjectType.Event)); - actions.AddRange(Reconcile(originalCustomEvents, engine.GetValue("customEvents").AsArray(), customEvents, i => new CustomEvent(engine, i), ObjectType.CustomEvent)); - actions.AddRange(Reconcile(originalBpmChanges, engine.GetValue("bpmChanges").AsArray(), bpmChanges, i => new BpmChange(engine, i), ObjectType.BpmChange)); - - SelectionController.SelectionChangedEvent?.Invoke(); - - TimeLog("Registering undo actions"); - - if (actions.Count > 0) - { - var allAction = new ActionCollectionAction(actions, true, true, "External Script"); - BeatmapActionContainer.AddAction(allAction); - } - - TimeLog("Fin"); - - return result; - } public override CheckResult PerformCheck(List notes, List bombs, List arcs, List chains, List events, List walls, List customEvents, List bpmChanges, params IParamValue[] vals) { result.Clear(); diff --git a/Checks/StackedNotes.cs b/Checks/StackedNotes.cs index 681b719..4bf24af 100644 --- a/Checks/StackedNotes.cs +++ b/Checks/StackedNotes.cs @@ -9,7 +9,7 @@ public StackedNotes() : base("Stacked Notes") { } - protected override CheckResult PerformCheck(List notes, List events, List walls, List customEvents, List bpmChanges) + protected override CheckResult PerformCheck(List notes, List bombs, List arcs, List chains, List events, List walls, List customEvents, List bpmChanges) { result.Clear(); diff --git a/Checks/VisionBlocks.cs b/Checks/VisionBlocks.cs index 91a43f4..c48988e 100644 --- a/Checks/VisionBlocks.cs +++ b/Checks/VisionBlocks.cs @@ -11,7 +11,7 @@ public VisionBlocks() : base("Vision Blocks") Params.Add(new FloatParam("Max Time", 0.75f)); } - public override CheckResult PerformCheck(List notes, List events, List walls, List customEvents, List bpmChanges, params IParamValue[] vals) + public override CheckResult PerformCheck(List notes, List bombs, List arcs, List chains, List events, List walls, List customEvents, List bpmChanges, params IParamValue[] vals) { if (vals.Length > 1) { From 70a7d710f711f699ca60101a5ae7e32558efa784 Mon Sep 17 00:00:00 2001 From: Kival Evan <5645391+KivalEvan@users.noreply.github.com> Date: Sat, 28 Jan 2023 15:47:47 -0800 Subject: [PATCH 16/26] Change params to JS object for string indexing --- CMJS.cs | 8 ++++---- Checks/Check.cs | 2 +- Checks/ExternalJS.cs | 26 +++++++++++++------------- Checks/VisionBlocks.cs | 6 ++++-- 4 files changed, 22 insertions(+), 20 deletions(-) diff --git a/CMJS.cs b/CMJS.cs index 85f1ac1..bbf1a72 100644 --- a/CMJS.cs +++ b/CMJS.cs @@ -106,13 +106,13 @@ public void CheckErrors(Check check) switch (it) { case UITextInput textInput: - return check.Params[idx].Parse(textInput.InputField.text); + return new KeyValuePair(check.Params[idx].name, check.Params[idx].Parse(textInput.InputField.text)); case UIDropdown dropdown: - return check.Params[idx].Parse(dropdown.Dropdown.value.ToString()); + return new KeyValuePair(check.Params[idx].name, check.Params[idx].Parse(dropdown.Dropdown.value.ToString())); case Toggle toggle: - return check.Params[idx].Parse(toggle.isOn.ToString()); + return new KeyValuePair(check.Params[idx].name, check.Params[idx].Parse(toggle.isOn.ToString())); default: - return new ParamValue(null); // IDK + return new KeyValuePair(check.Params[idx].name, new ParamValue(null)); // IDK } }).ToArray(); diff --git a/Checks/Check.cs b/Checks/Check.cs index dc466e8..0bc338a 100644 --- a/Checks/Check.cs +++ b/Checks/Check.cs @@ -25,7 +25,7 @@ protected virtual CheckResult PerformCheck(List notes, List throw new ArgumentException("Wrong number of parameters"); } - public virtual CheckResult PerformCheck(List notes, List bombs, List arcs, List chains, List events, List walls, List customEvents, List bpmChanges, params IParamValue[] vals) + public virtual CheckResult PerformCheck(List notes, List bombs, List arcs, List chains, List events, List walls, List customEvents, List bpmChanges, params KeyValuePair[] vals) { if (vals.Length == 0 && Params.Count == 0) { diff --git a/Checks/ExternalJS.cs b/Checks/ExternalJS.cs index 832cb54..a261b25 100644 --- a/Checks/ExternalJS.cs +++ b/Checks/ExternalJS.cs @@ -8,6 +8,7 @@ using System; using System.Collections.Generic; using System.Dynamic; +using System.Globalization; using System.IO; using System.Linq; using System.Reflection; @@ -15,10 +16,6 @@ using Beatmap.Base; using Beatmap.Base.Customs; using Beatmap.Enums; -using Beatmap.V2; -using Beatmap.V2.Customs; -using Beatmap.V3; -using Beatmap.V3.Customs; using Esprima; using UnityEngine; @@ -250,7 +247,9 @@ public MapData(float currentBPM, float songBPM, float NJS, float offset, string } } - public override CheckResult PerformCheck(List notes, List bombs, List arcs, List chains, List events, List walls, List customEvents, List bpmChanges, params IParamValue[] vals) + public override CheckResult PerformCheck(List notes, List bombs, List arcs, + List chains, List events, List walls, List customEvents, + List bpmChanges, params KeyValuePair[] vals) { result.Clear(); @@ -274,20 +273,21 @@ public override CheckResult PerformCheck(List notes, List bo { var valsToString = vals.Select(paramValue => { - switch (paramValue) + switch (paramValue.Value) { case ParamValue pvf: - return pvf.value.ToString(); + return new KeyValuePair(paramValue.Key, pvf.value.ToString(CultureInfo.InvariantCulture)); case ParamValue pvs: - return $"\"{pvs.value}\""; + return new KeyValuePair(paramValue.Key, $"\"{pvs.value}\""); case ParamValue pvb: - return pvb.value ? "true" : "false"; + return new KeyValuePair(paramValue.Key, pvb.value ? "true" : "false"); default: - return "null"; + return new KeyValuePair(paramValue.Key, "null"); } }); - var valsCombined = string.Join(",", valsToString); + var valsObj = string.Join(",", valsToString.Select((v, idx) => $"{idx.ToString()}:{v.Value},\"{v.Key}\":{v.Value}")); + var valsParams = string.Join(",", valsToString.Select(v => v.Value)); TimeLog("Init"); @@ -330,8 +330,8 @@ public override CheckResult PerformCheck(List notes, List bo TimeLog("Run"); - tmp.Execute("global.params = [" + valsCombined + "];" + - "var output = module.exports.run ? module.exports.run(cursor, notes, events, walls, {}, global, data, customEvents, bpmChanges, bombs, arcs, chains) : module.exports.performCheck({notes: notes}" + (vals.Length > 0 ? ", " + valsCombined : "") + ");" + + tmp.Execute("global.params = {" + valsObj + "};" + + "var output = module.exports.run ? module.exports.run(cursor, notes, events, walls, {}, global, data, customEvents, bpmChanges, bombs, arcs, chains) : module.exports.performCheck({notes: notes}" + (vals.Length > 0 ? ", " + valsParams : "") + ");" + "if (output && output.notes) { notes = output.notes; };" + "if (output && output.bombs) { bombs = output.bombs; };" + "if (output && output.arcs) { arcs = output.arcs; };" + diff --git a/Checks/VisionBlocks.cs b/Checks/VisionBlocks.cs index c48988e..4ee84c3 100644 --- a/Checks/VisionBlocks.cs +++ b/Checks/VisionBlocks.cs @@ -11,11 +11,13 @@ public VisionBlocks() : base("Vision Blocks") Params.Add(new FloatParam("Max Time", 0.75f)); } - public override CheckResult PerformCheck(List notes, List bombs, List arcs, List chains, List events, List walls, List customEvents, List bpmChanges, params IParamValue[] vals) + public override CheckResult PerformCheck(List notes, List bombs, List arcs, + List chains, List events, List walls, List customEvents, + List bpmChanges, params KeyValuePair[] vals) { if (vals.Length > 1) { - return PerformCheck(notes, ((ParamValue) vals[0]).value, ((ParamValue) vals[1]).value); + return PerformCheck(notes, ((ParamValue) vals[0].Value).value, ((ParamValue) vals[1].Value).value); } throw new ArgumentException("Wrong number of parameters"); } From 1fb45b42654d3fd2592f844be2a717696894841a Mon Sep 17 00:00:00 2001 From: Kival Evan <5645391+KivalEvan@users.noreply.github.com> Date: Sun, 29 Jan 2023 10:05:21 -0800 Subject: [PATCH 17/26] Clean-up wrappers --- Wrappers/Beatmap/Arc.cs | 248 ++++++++++++++++---------------- Wrappers/Beatmap/BombNote.cs | 102 ++++++------- Wrappers/Beatmap/BpmChange.cs | 181 ++++++++++++----------- Wrappers/Beatmap/Chain.cs | 216 ++++++++++++++-------------- Wrappers/Beatmap/CustomEvent.cs | 178 +++++++++++------------ Wrappers/Beatmap/Event.cs | 174 +++++++++++----------- Wrappers/Beatmap/Note.cs | 220 ++++++++++++++-------------- Wrappers/Beatmap/Wall.cs | 220 ++++++++++++++-------------- Wrappers/JSONWrapper.cs | 12 -- 9 files changed, 769 insertions(+), 782 deletions(-) diff --git a/Wrappers/Beatmap/Arc.cs b/Wrappers/Beatmap/Arc.cs index 81ec8c9..a00c806 100644 --- a/Wrappers/Beatmap/Arc.cs +++ b/Wrappers/Beatmap/Arc.cs @@ -4,173 +4,173 @@ using Jint; using Jint.Native.Object; - internal class Arc : VanillaWrapper +internal class Arc : VanillaWrapper +{ + public Arc(Engine engine, BaseArc arc) : base(engine, arc) { - public Arc(Engine engine, BaseArc arc) : base(engine, arc) - { - spawned = true; - } + spawned = true; + } - public Arc(Engine engine, ObjectInstance o) : base(engine, BeatmapFactory.Arc( - (float)GetJsValue(o, "b"), - (int)GetJsValue(o, "c"), - (int)GetJsValue(o, "x"), - (int)GetJsValue(o, "y"), - (int)GetJsValue(o, "d"), - 0, - (float)GetJsValue(o, "mu"), - (float)GetJsValue(o, "tb"), - (int)GetJsValue(o, "tx"), - (int)GetJsValue(o, "ty"), - (int)GetJsValue(o, "tc"), - (float)GetJsValue(o, "tmu"), - (int)GetJsValue(o, "m"), - GetCustomData(o, new[] { "customData", "_customData" }) - ), false, GetJsBool(o, "selected")) - { - spawned = false; + public Arc(Engine engine, ObjectInstance o) : base(engine, BeatmapFactory.Arc( + (float)GetJsValue(o, "b"), + (int)GetJsValue(o, "c"), + (int)GetJsValue(o, "x"), + (int)GetJsValue(o, "y"), + (int)GetJsValue(o, "d"), + 0, + (float)GetJsValue(o, "mu"), + (float)GetJsValue(o, "tb"), + (int)GetJsValue(o, "tx"), + (int)GetJsValue(o, "ty"), + (int)GetJsValue(o, "tc"), + (float)GetJsValue(o, "tmu"), + (int)GetJsValue(o, "m"), + GetCustomData(o, new[] { "customData", "_customData" }) + ), false, GetJsBool(o, "selected")) + { + spawned = false; - DeleteObject(); - } + DeleteObject(); + } - public float b + public float b + { + get => wrapped.Time; + set { - get => wrapped.Time; - set - { - DeleteObject(); - wrapped.Time = value; - } + DeleteObject(); + wrapped.Time = value; } + } - public int c + public int x + { + get => wrapped.PosX; + set { - get => wrapped.Color; - set - { - DeleteObject(); - wrapped.Color = value; - } + DeleteObject(); + wrapped.PosX = value; } + } - public int x + public int y + { + get => wrapped.PosY; + set { - get => wrapped.PosX; - set - { - DeleteObject(); - wrapped.PosX = value; - } + DeleteObject(); + wrapped.PosY = value; } + } - public int y + public int c + { + get => wrapped.Color; + set { - get => wrapped.PosY; - set - { - DeleteObject(); - wrapped.PosY = value; - } + DeleteObject(); + wrapped.Color = value; } + } - public int d + public int d + { + get => wrapped.CutDirection; + set { - get => wrapped.CutDirection; - set - { - DeleteObject(); - wrapped.CutDirection = value; - } + DeleteObject(); + wrapped.CutDirection = value; } + } - public float mu + public float mu + { + get => wrapped.HeadControlPointLengthMultiplier; + set { - get => wrapped.HeadControlPointLengthMultiplier; - set - { - DeleteObject(); - wrapped.HeadControlPointLengthMultiplier = value; - } + DeleteObject(); + wrapped.HeadControlPointLengthMultiplier = value; } + } - public float tb + public float tb + { + get => wrapped.TailTime; + set { - get => wrapped.TailTime; - set - { - DeleteObject(); - wrapped.TailTime = value; - } + DeleteObject(); + wrapped.TailTime = value; } + } - public int tx + public int tx + { + get => wrapped.TailPosX; + set { - get => wrapped.TailPosX; - set - { - DeleteObject(); - wrapped.TailPosX = value; - } + DeleteObject(); + wrapped.TailPosX = value; } + } - public int ty + public int ty + { + get => wrapped.TailPosY; + set { - get => wrapped.TailPosY; - set - { - DeleteObject(); - wrapped.TailPosY = value; - } + DeleteObject(); + wrapped.TailPosY = value; } + } - public int tc + public int tc + { + get => wrapped.TailCutDirection; + set { - get => wrapped.TailCutDirection; - set - { - DeleteObject(); - wrapped.TailCutDirection = value; - } + DeleteObject(); + wrapped.TailCutDirection = value; } + } - public float tmu + public float tmu + { + get => wrapped.TailControlPointLengthMultiplier; + set { - get => wrapped.TailControlPointLengthMultiplier; - set - { - DeleteObject(); - wrapped.TailControlPointLengthMultiplier = value; - } + DeleteObject(); + wrapped.TailControlPointLengthMultiplier = value; } + } - public int m + public int m + { + get => wrapped.MidAnchorMode; + set { - get => wrapped.MidAnchorMode; - set - { - DeleteObject(); - wrapped.MidAnchorMode = value; - } + DeleteObject(); + wrapped.MidAnchorMode = value; } + } - public override bool SpawnObject(BeatmapObjectContainerCollection collection) - { - if (spawned) return false; + public override bool SpawnObject(BeatmapObjectContainerCollection collection) + { + if (spawned) return false; - collection.SpawnObject(wrapped, false, false); + collection.SpawnObject(wrapped, false, false); - spawned = true; - return true; - } + spawned = true; + return true; + } - internal override bool DeleteObject() - { - if (!spawned) return false; + internal override bool DeleteObject() + { + if (!spawned) return false; - var collection = BeatmapObjectContainerCollection.GetCollectionForType(ObjectType.Arc); - collection.DeleteObject(wrapped, false); + var collection = BeatmapObjectContainerCollection.GetCollectionForType(ObjectType.Arc); + collection.DeleteObject(wrapped, false); - spawned = false; - return true; - } + spawned = false; + return true; } +} diff --git a/Wrappers/Beatmap/BombNote.cs b/Wrappers/Beatmap/BombNote.cs index 8b374d2..8576c8a 100644 --- a/Wrappers/Beatmap/BombNote.cs +++ b/Wrappers/Beatmap/BombNote.cs @@ -4,73 +4,73 @@ using Jint; using Jint.Native.Object; - internal class BombNote : VanillaWrapper +internal class BombNote : VanillaWrapper +{ + public BombNote(Engine engine, BaseNote bomb) : base(engine, bomb) { - public BombNote(Engine engine, BaseNote bomb) : base(engine, bomb) - { - spawned = true; - } + spawned = true; + } - public BombNote(Engine engine, ObjectInstance o) : base(engine, BeatmapFactory.Bomb( - (float)GetJsValue(o, "b"), - (int)GetJsValue(o, "x"), - (int)GetJsValue(o, "y"), - GetCustomData(o, new[] { "customData", "_customData" }) - ), false, GetJsBool(o, "selected")) - { - spawned = false; + public BombNote(Engine engine, ObjectInstance o) : base(engine, BeatmapFactory.Bomb( + (float)GetJsValue(o, "b"), + (int)GetJsValue(o, "x"), + (int)GetJsValue(o, "y"), + GetCustomData(o, new[] { "customData", "_customData" }) + ), false, GetJsBool(o, "selected")) + { + spawned = false; - DeleteObject(); - } + DeleteObject(); + } - public float b + public float b + { + get => wrapped.Time; + set { - get => wrapped.Time; - set - { - DeleteObject(); - wrapped.Time = value; - } + DeleteObject(); + wrapped.Time = value; } + } - public int x + public int x + { + get => wrapped.PosX; + set { - get => wrapped.PosX; - set - { - DeleteObject(); - wrapped.PosX = value; - } + DeleteObject(); + wrapped.PosX = value; } + } - public int y + public int y + { + get => wrapped.PosY; + set { - get => wrapped.PosY; - set - { - DeleteObject(); - wrapped.PosY = value; - } + DeleteObject(); + wrapped.PosY = value; } + } - public override bool SpawnObject(BeatmapObjectContainerCollection collection) - { - if (spawned) return false; + public override bool SpawnObject(BeatmapObjectContainerCollection collection) + { + if (spawned) return false; - collection.SpawnObject(wrapped, false, false); + collection.SpawnObject(wrapped, false, false); - spawned = true; - return true; - } + spawned = true; + return true; + } - internal override bool DeleteObject() - { - if (!spawned) return false; + internal override bool DeleteObject() + { + if (!spawned) return false; - var collection = BeatmapObjectContainerCollection.GetCollectionForType(ObjectType.Note); - collection.DeleteObject(wrapped, false); + var collection = BeatmapObjectContainerCollection.GetCollectionForType(ObjectType.Note); + collection.DeleteObject(wrapped, false); - spawned = false; - return true; - } + spawned = false; + return true; } +} diff --git a/Wrappers/Beatmap/BpmChange.cs b/Wrappers/Beatmap/BpmChange.cs index bd9ed06..ff4a8a0 100644 --- a/Wrappers/Beatmap/BpmChange.cs +++ b/Wrappers/Beatmap/BpmChange.cs @@ -1,132 +1,131 @@ using Beatmap.Base.Customs; using Beatmap.Enums; using Beatmap.Helper; -using Beatmap.V3.Customs; using Jint; using Jint.Native.Object; - internal class BpmChange : Wrapper +internal class BpmChange : Wrapper +{ + public BpmChange(Engine engine, BaseBpmChange bpmChange) : base(engine, bpmChange) { - public BpmChange(Engine engine, BaseBpmChange bpmChange) : base(engine, bpmChange) - { - spawned = true; - } + spawned = true; + } - public BpmChange(Engine engine, ObjectInstance o) : base(engine, BeatmapFactory.BpmChange( - (float)GetJsValue(o, new [] { "b", "_time" }), - (float)GetJsValue(o, new [] { "m", "_BPM" }) - ), false, GetJsBool(o, "selected")) - { - spawned = false; - wrapped.BeatsPerBar = (float)(GetJsValue(o, new[] { "p", "_beatsPerBar" }) ?? 4f); - wrapped.MetronomeOffset = (float)(GetJsValue(o, new[] { "o", "_metronomeOffset" }) ?? 4f); + public BpmChange(Engine engine, ObjectInstance o) : base(engine, BeatmapFactory.BpmChange( + (float)GetJsValue(o, new[] { "b", "_time" }), + (float)GetJsValue(o, new[] { "m", "_BPM" }) + ), false, GetJsBool(o, "selected")) + { + spawned = false; + wrapped.BeatsPerBar = (float)(GetJsValue(o, new[] { "p", "_beatsPerBar" }) ?? 4f); + wrapped.MetronomeOffset = (float)(GetJsValue(o, new[] { "o", "_metronomeOffset" }) ?? 4f); - DeleteObject(); - } + DeleteObject(); + } - public float _time + public float _time + { + get => wrapped.Time; + set { - get => wrapped.Time; - set - { - DeleteObject(); - wrapped.Time = value; - } + DeleteObject(); + wrapped.Time = value; } + } - public float _BPM + public float _BPM + { + get => wrapped.Bpm; + set { - get => wrapped.Bpm; - set - { - DeleteObject(); - wrapped.Bpm = value; - } + DeleteObject(); + wrapped.Bpm = value; } + } - public float _beatsPerBar + public float _beatsPerBar + { + get => wrapped.BeatsPerBar; + set { - get => wrapped.BeatsPerBar; - set - { - DeleteObject(); - wrapped.BeatsPerBar = value; - } + DeleteObject(); + wrapped.BeatsPerBar = value; } + } - public float _metronomeOffset + public float _metronomeOffset + { + get => wrapped.MetronomeOffset; + set { - get => wrapped.MetronomeOffset; - set - { - DeleteObject(); - wrapped.MetronomeOffset = value; - } + DeleteObject(); + wrapped.MetronomeOffset = value; } + } - public float b + public float b + { + get => wrapped.Time; + set { - get => wrapped.Time; - set - { - DeleteObject(); - wrapped.Time = value; - } + DeleteObject(); + wrapped.Time = value; } + } - public float m + public float m + { + get => wrapped.Bpm; + set { - get => wrapped.Bpm; - set - { - DeleteObject(); - wrapped.Bpm = value; - } + DeleteObject(); + wrapped.Bpm = value; } + } - public float p + public float p + { + get => wrapped.BeatsPerBar; + set { - get => wrapped.BeatsPerBar; - set - { - DeleteObject(); - wrapped.BeatsPerBar = value; - } + DeleteObject(); + wrapped.BeatsPerBar = value; } + } - public float o + public float o + { + get => wrapped.MetronomeOffset; + set { - get => wrapped.MetronomeOffset; - set - { - DeleteObject(); - wrapped.MetronomeOffset = value; - } + DeleteObject(); + wrapped.MetronomeOffset = value; } + } - public override bool SpawnObject(BeatmapObjectContainerCollection collection) - { - if (spawned) return false; + public override bool SpawnObject(BeatmapObjectContainerCollection collection) + { + if (spawned) return false; - collection.SpawnObject(wrapped, false, false); + collection.SpawnObject(wrapped, false, false); - spawned = true; - return true; - } + spawned = true; + return true; + } - internal override bool DeleteObject() - { - if (!spawned) return false; + internal override bool DeleteObject() + { + if (!spawned) return false; - var collection = BeatmapObjectContainerCollection.GetCollectionForType(ObjectType.BpmChange); - collection.DeleteObject(wrapped, false); + var collection = BeatmapObjectContainerCollection.GetCollectionForType(ObjectType.BpmChange); + collection.DeleteObject(wrapped, false); - spawned = false; - return true; - } + spawned = false; + return true; + } - internal override void Reconcile() - { - // Nothing :) - } + internal override void Reconcile() + { + // Nothing :) } +} diff --git a/Wrappers/Beatmap/Chain.cs b/Wrappers/Beatmap/Chain.cs index 7f6388b..2d50240 100644 --- a/Wrappers/Beatmap/Chain.cs +++ b/Wrappers/Beatmap/Chain.cs @@ -4,151 +4,151 @@ using Jint; using Jint.Native.Object; - internal class Chain : VanillaWrapper +internal class Chain : VanillaWrapper +{ + public Chain(Engine engine, BaseChain chain) : base(engine, chain) { - public Chain(Engine engine, BaseChain chain) : base(engine, chain) - { - spawned = true; - } + spawned = true; + } - public Chain(Engine engine, ObjectInstance o) : base(engine, BeatmapFactory.Chain( - (int)GetJsValue(o, "b"), - (int)GetJsValue(o, "c"), - (int)GetJsValue(o, "x"), - (int)GetJsValue(o, "y"), - (int)GetJsValue(o, "d"), - 0, - (float)GetJsValue(o, "tb"), - (int)GetJsValue(o, "tx"), - (int)GetJsValue(o, "ty"), - (int)GetJsValue(o, "sc"), - (float)GetJsValue(o, "s"), - GetCustomData(o, new[] { "customData", "_customData" }) - ), false, GetJsBool(o, "selected")) - { - spawned = false; + public Chain(Engine engine, ObjectInstance o) : base(engine, BeatmapFactory.Chain( + (int)GetJsValue(o, "b"), + (int)GetJsValue(o, "c"), + (int)GetJsValue(o, "x"), + (int)GetJsValue(o, "y"), + (int)GetJsValue(o, "d"), + 0, + (float)GetJsValue(o, "tb"), + (int)GetJsValue(o, "tx"), + (int)GetJsValue(o, "ty"), + (int)GetJsValue(o, "sc"), + (float)GetJsValue(o, "s"), + GetCustomData(o, new[] { "customData", "_customData" }) + ), false, GetJsBool(o, "selected")) + { + spawned = false; - DeleteObject(); - } + DeleteObject(); + } - public float b + public float b + { + get => wrapped.Time; + set { - get => wrapped.Time; - set - { - DeleteObject(); - wrapped.Time = value; - } + DeleteObject(); + wrapped.Time = value; } + } - public int c + public int x + { + get => wrapped.PosX; + set { - get => wrapped.Color; - set - { - DeleteObject(); - wrapped.Color = value; - } + DeleteObject(); + wrapped.PosX = value; } + } - public int x + public int y + { + get => wrapped.PosY; + set { - get => wrapped.PosX; - set - { - DeleteObject(); - wrapped.PosX = value; - } + DeleteObject(); + wrapped.PosY = value; } + } - public int y + public int c + { + get => wrapped.Color; + set { - get => wrapped.PosY; - set - { - DeleteObject(); - wrapped.PosY = value; - } + DeleteObject(); + wrapped.Color = value; } + } - public int d + public int d + { + get => wrapped.CutDirection; + set { - get => wrapped.CutDirection; - set - { - DeleteObject(); - wrapped.CutDirection = value; - } + DeleteObject(); + wrapped.CutDirection = value; } + } - public float tb + public float tb + { + get => wrapped.TailTime; + set { - get => wrapped.TailTime; - set - { - DeleteObject(); - wrapped.TailTime = value; - } + DeleteObject(); + wrapped.TailTime = value; } + } - public int tx + public int tx + { + get => wrapped.TailPosX; + set { - get => wrapped.TailPosX; - set - { - DeleteObject(); - wrapped.TailPosX = value; - } + DeleteObject(); + wrapped.TailPosX = value; } + } - public int ty + public int ty + { + get => wrapped.TailPosY; + set { - get => wrapped.TailPosY; - set - { - DeleteObject(); - wrapped.TailPosY = value; - } + DeleteObject(); + wrapped.TailPosY = value; } + } - public int sc + public int sc + { + get => wrapped.SliceCount; + set { - get => wrapped.SliceCount; - set - { - DeleteObject(); - wrapped.SliceCount = value; - } + DeleteObject(); + wrapped.SliceCount = value; } + } - public float s + public float s + { + get => wrapped.Squish; + set { - get => wrapped.Squish; - set - { - DeleteObject(); - wrapped.Squish = value; - } + DeleteObject(); + wrapped.Squish = value; } + } - public override bool SpawnObject(BeatmapObjectContainerCollection collection) - { - if (spawned) return false; + public override bool SpawnObject(BeatmapObjectContainerCollection collection) + { + if (spawned) return false; - collection.SpawnObject(wrapped, false, false); + collection.SpawnObject(wrapped, false, false); - spawned = true; - return true; - } + spawned = true; + return true; + } - internal override bool DeleteObject() - { - if (!spawned) return false; + internal override bool DeleteObject() + { + if (!spawned) return false; - var collection = BeatmapObjectContainerCollection.GetCollectionForType(ObjectType.Chain); - collection.DeleteObject(wrapped, false); + var collection = BeatmapObjectContainerCollection.GetCollectionForType(ObjectType.Chain); + collection.DeleteObject(wrapped, false); - spawned = false; - return true; - } + spawned = false; + return true; } +} diff --git a/Wrappers/Beatmap/CustomEvent.cs b/Wrappers/Beatmap/CustomEvent.cs index 09c7147..17739f7 100644 --- a/Wrappers/Beatmap/CustomEvent.cs +++ b/Wrappers/Beatmap/CustomEvent.cs @@ -5,122 +5,122 @@ using Jint; using Jint.Native.Object; - internal class CustomEvent : Wrapper - { - private Lazy customData; - private Action reconcile; +internal class CustomEvent : Wrapper +{ + private Lazy customData; + private Action reconcile; - public CustomEvent(Engine engine, BaseCustomEvent customEvent) : base(engine, customEvent) - { - spawned = true; - InitWrapper(); - } + public CustomEvent(Engine engine, BaseCustomEvent customEvent) : base(engine, customEvent) + { + spawned = true; + InitWrapper(); + } - public CustomEvent(Engine engine, ObjectInstance o) : base(engine, BeatmapFactory.CustomEvent( - (float)GetJsValue(o, new [] { "b", "_time" }), - GetJsString(o, new [] { "t", "_type" }), - GetCustomData(o, new [] { "d", "_data" }) - ), false, GetJsBool(o, "selected")) - { - spawned = false; + public CustomEvent(Engine engine, ObjectInstance o) : base(engine, BeatmapFactory.CustomEvent( + (float)GetJsValue(o, new[] { "b", "_time" }), + GetJsString(o, new[] { "t", "_type" }), + GetCustomData(o, new[] { "d", "_data" }) + ), false, GetJsBool(o, "selected")) + { + spawned = false; - DeleteObject(); - InitWrapper(); - } + DeleteObject(); + InitWrapper(); + } - public float _time + public float _time + { + get => wrapped.Time; + set { - get => wrapped.Time; - set - { - DeleteObject(); - wrapped.Time = value; - } + DeleteObject(); + wrapped.Time = value; } + } - public string _type + public string _type + { + get => wrapped.Type; + set { - get => wrapped.Type; - set - { - DeleteObject(); - wrapped.Type = value; - } + DeleteObject(); + wrapped.Type = value; } + } - public object _data + public object _data + { + get => wrapped.Data == null ? null : customData.Value; + set { - get => wrapped.CustomData == null ? null : customData.Value; - set - { - DeleteObject(); - wrapped.CustomData = JSONWrapper.castObjToJSON(value); - InitWrapper(); - } + DeleteObject(); + wrapped.Data = JSONWrapper.castObjToJSON(value); + InitWrapper(); } + } - public float b + public float b + { + get => wrapped.Time; + set { - get => wrapped.Time; - set - { - DeleteObject(); - wrapped.Time = value; - } + DeleteObject(); + wrapped.Time = value; } + } - public string t + public string t + { + get => wrapped.Type; + set { - get => wrapped.Type; - set - { - DeleteObject(); - wrapped.Type = value; - } + DeleteObject(); + wrapped.Type = value; } + } - public object d + public object d + { + get => wrapped.Data == null ? null : customData.Value; + set { - get => wrapped.CustomData == null ? null : customData.Value; - set - { - DeleteObject(); - wrapped.CustomData = JSONWrapper.castObjToJSON(value); - InitWrapper(); - } + DeleteObject(); + wrapped.Data = JSONWrapper.castObjToJSON(value); + InitWrapper(); } + } - public override bool SpawnObject(BeatmapObjectContainerCollection collection) - { - if (spawned) return false; + public override bool SpawnObject(BeatmapObjectContainerCollection collection) + { + if (spawned) return false; - collection.SpawnObject(wrapped, false, false); + collection.SpawnObject(wrapped, false, false); - spawned = true; - return true; - } + spawned = true; + return true; + } - internal override bool DeleteObject() - { - if (!spawned) return false; + internal override bool DeleteObject() + { + if (!spawned) return false; - var collection = BeatmapObjectContainerCollection.GetCollectionForType(ObjectType.CustomEvent); - collection.DeleteObject(wrapped, false); + var collection = BeatmapObjectContainerCollection.GetCollectionForType(ObjectType.CustomEvent); + collection.DeleteObject(wrapped, false); - spawned = false; - return true; - } + spawned = false; + return true; + } - private void InitWrapper() - { - reconcile = null; - customData = new Lazy(() => - new JSONWrapper(engine, ref reconcile, wrapped.CustomData, DeleteObject) - ); - } + private void InitWrapper() + { + reconcile = null; + customData = new Lazy(() => + new JSONWrapper(engine, ref reconcile, wrapped.Data, DeleteObject) + ); + } - internal override void Reconcile() - { - reconcile?.Invoke(); - } + internal override void Reconcile() + { + reconcile?.Invoke(); } +} diff --git a/Wrappers/Beatmap/Event.cs b/Wrappers/Beatmap/Event.cs index 4a68bdb..12de765 100644 --- a/Wrappers/Beatmap/Event.cs +++ b/Wrappers/Beatmap/Event.cs @@ -4,124 +4,124 @@ using Jint; using Jint.Native.Object; - internal class Event : VanillaWrapper +internal class Event : VanillaWrapper +{ + public Event(Engine engine, BaseEvent mapEvent) : base(engine, mapEvent) { - public Event(Engine engine, BaseEvent mapEvent) : base(engine, mapEvent) - { - spawned = true; - } + spawned = true; + } - public Event(Engine engine, ObjectInstance o) : base(engine, BeatmapFactory.Event( - (float)GetJsValue(o, new[] { "b", "_time" }), - (int)GetJsValue(o, new[] { "et", "_type" }), - (int)GetJsValue(o, new[] { "i", "_value" }), - (float)GetJsValue(o, new[] { "f", "_floatValue" }), - GetCustomData(o, new[] { "customData", "_customData" }) - ), false, GetJsBool(o, "selected")) - { - spawned = false; + public Event(Engine engine, ObjectInstance o) : base(engine, BeatmapFactory.Event( + (float)GetJsValue(o, new[] { "b", "_time" }), + (int)GetJsValue(o, new[] { "et", "_type" }), + (int)GetJsValue(o, new[] { "i", "_value" }), + (float)GetJsValue(o, new[] { "f", "_floatValue" }), + GetCustomData(o, new[] { "customData", "_customData" }) + ), false, GetJsBool(o, "selected")) + { + spawned = false; - DeleteObject(); - } + DeleteObject(); + } - public float _time + public float _time + { + get => wrapped.Time; + set { - get => wrapped.Time; - set - { - DeleteObject(); - wrapped.Time = value; - } + DeleteObject(); + wrapped.Time = value; } + } - public int _type + public int _type + { + get => wrapped.Type; + set { - get => wrapped.Type; - set - { - DeleteObject(); - wrapped.Type = value; - } + DeleteObject(); + wrapped.Type = value; } + } - public int _value + public int _value + { + get => wrapped.Value; + set { - get => wrapped.Value; - set - { - DeleteObject(); - wrapped.Value = value; - } + DeleteObject(); + wrapped.Value = value; } + } - public float _floatValue + public float _floatValue + { + get => wrapped.FloatValue; + set { - get => wrapped.FloatValue; - set - { - DeleteObject(); - wrapped.FloatValue = value; - } + DeleteObject(); + wrapped.FloatValue = value; } + } - public float b + public float b + { + get => wrapped.Time; + set { - get => wrapped.Time; - set - { - DeleteObject(); - wrapped.Time = value; - } + DeleteObject(); + wrapped.Time = value; } + } - public int et + public int et + { + get => wrapped.Type; + set { - get => wrapped.Type; - set - { - DeleteObject(); - wrapped.Type = value; - } + DeleteObject(); + wrapped.Type = value; } + } - public int i + public int i + { + get => wrapped.Value; + set { - get => wrapped.Value; - set - { - DeleteObject(); - wrapped.Value = value; - } + DeleteObject(); + wrapped.Value = value; } + } - public float f + public float f + { + get => wrapped.FloatValue; + set { - get => wrapped.FloatValue; - set - { - DeleteObject(); - wrapped.FloatValue = value; - } + DeleteObject(); + wrapped.FloatValue = value; } + } - public override bool SpawnObject(BeatmapObjectContainerCollection collection) - { - if (spawned) return false; + public override bool SpawnObject(BeatmapObjectContainerCollection collection) + { + if (spawned) return false; - collection.SpawnObject(wrapped, false, false); + collection.SpawnObject(wrapped, false, false); - spawned = true; - return true; - } + spawned = true; + return true; + } - internal override bool DeleteObject() - { - if (!spawned) return false; + internal override bool DeleteObject() + { + if (!spawned) return false; - var collection = BeatmapObjectContainerCollection.GetCollectionForType(ObjectType.Event); - collection.DeleteObject(wrapped, false); + var collection = BeatmapObjectContainerCollection.GetCollectionForType(ObjectType.Event); + collection.DeleteObject(wrapped, false); - spawned = false; - return true; - } + spawned = false; + return true; } +} diff --git a/Wrappers/Beatmap/Note.cs b/Wrappers/Beatmap/Note.cs index 7053da6..039ba9f 100644 --- a/Wrappers/Beatmap/Note.cs +++ b/Wrappers/Beatmap/Note.cs @@ -4,156 +4,156 @@ using Jint; using Jint.Native.Object; - internal class Note : VanillaWrapper +internal class Note : VanillaWrapper +{ + public Note(Engine engine, BaseNote note) : base(engine, note) { - public Note(Engine engine, BaseNote note) : base(engine, note) - { - spawned = true; - } + spawned = true; + } - public Note(Engine engine, ObjectInstance o) : base(engine, BeatmapFactory.Note( - (float)GetJsValue(o, new[] { "b", "_time" }), - (int)GetJsValue(o, new[] { "x", "_lineIndex" }), - (int)GetJsValue(o, new[] { "y", "_lineLayer" }), - (int)GetJsValue(o, new[] { "c", "_type" }), - (int)GetJsValue(o, new[] { "d", "_cutDirection" }), - (int)(GetJsValueOptional(o, "a") ?? 0), - GetCustomData(o, new[] { "customData", "_customData" }) - ), false, GetJsBool(o, "selected")) - { - spawned = false; + public Note(Engine engine, ObjectInstance o) : base(engine, BeatmapFactory.Note( + (float)GetJsValue(o, new[] { "b", "_time" }), + (int)GetJsValue(o, new[] { "x", "_lineIndex" }), + (int)GetJsValue(o, new[] { "y", "_lineLayer" }), + (int)GetJsValue(o, new[] { "c", "_type" }), + (int)GetJsValue(o, new[] { "d", "_cutDirection" }), + (int)(GetJsValueOptional(o, "a") ?? 0), + GetCustomData(o, new[] { "customData", "_customData" }) + ), false, GetJsBool(o, "selected")) + { + spawned = false; - DeleteObject(); - } + DeleteObject(); + } - public float _time + public float _time + { + get => wrapped.Time; + set { - get => wrapped.Time; - set - { - DeleteObject(); - wrapped.Time = value; - } + DeleteObject(); + wrapped.Time = value; } + } - public int _lineIndex + public int _lineIndex + { + get => wrapped.PosX; + set { - get => wrapped.PosX; - set - { - DeleteObject(); - wrapped.PosX = value; - } + DeleteObject(); + wrapped.PosX = value; } + } - public int _lineLayer + public int _lineLayer + { + get => wrapped.PosY; + set { - get => wrapped.PosY; - set - { - DeleteObject(); - wrapped.PosY = value; - } + DeleteObject(); + wrapped.PosY = value; } + } - public int _cutDirection + public int _cutDirection + { + get => wrapped.CutDirection; + set { - get => wrapped.CutDirection; - set - { - DeleteObject(); - wrapped.CutDirection = value; - } + DeleteObject(); + wrapped.CutDirection = value; } + } - public int _type + public int _type + { + get => wrapped.Color; + set { - get => wrapped.Color; - set - { - DeleteObject(); - wrapped.Color = value; - } + DeleteObject(); + wrapped.Color = value; } + } - public float b + public float b + { + get => wrapped.Time; + set { - get => wrapped.Time; - set - { - DeleteObject(); - wrapped.Time = value; - } + DeleteObject(); + wrapped.Time = value; } + } - public int x + public int x + { + get => wrapped.PosX; + set { - get => wrapped.PosX; - set - { - DeleteObject(); - wrapped.PosX = value; - } + DeleteObject(); + wrapped.PosX = value; } + } - public int y + public int y + { + get => wrapped.PosY; + set { - get => wrapped.PosY; - set - { - DeleteObject(); - wrapped.PosY = value; - } + DeleteObject(); + wrapped.PosY = value; } + } - public int a + public int c + { + get => wrapped.Color; + set { - get => wrapped.AngleOffset; - set - { - DeleteObject(); - wrapped.AngleOffset = value; - } + DeleteObject(); + wrapped.Color = value; } + } - public int c + public int d + { + get => wrapped.CutDirection; + set { - get => wrapped.Color; - set - { - DeleteObject(); - wrapped.Color = value; - } + DeleteObject(); + wrapped.CutDirection = value; } + } - public int d + public int a + { + get => wrapped.AngleOffset; + set { - get => wrapped.CutDirection; - set - { - DeleteObject(); - wrapped.CutDirection = value; - } + DeleteObject(); + wrapped.AngleOffset = value; } + } - public override bool SpawnObject(BeatmapObjectContainerCollection collection) - { - if (spawned) return false; + public override bool SpawnObject(BeatmapObjectContainerCollection collection) + { + if (spawned) return false; - collection.SpawnObject(wrapped, false, false); + collection.SpawnObject(wrapped, false, false); - spawned = true; - return true; - } + spawned = true; + return true; + } - internal override bool DeleteObject() - { - if (!spawned) return false; + internal override bool DeleteObject() + { + if (!spawned) return false; - var collection = BeatmapObjectContainerCollection.GetCollectionForType(ObjectType.Note); - collection.DeleteObject(wrapped, false); + var collection = BeatmapObjectContainerCollection.GetCollectionForType(ObjectType.Note); + collection.DeleteObject(wrapped, false); - spawned = false; - return true; - } + spawned = false; + return true; } +} diff --git a/Wrappers/Beatmap/Wall.cs b/Wrappers/Beatmap/Wall.cs index efc6fb0..c5c81b1 100644 --- a/Wrappers/Beatmap/Wall.cs +++ b/Wrappers/Beatmap/Wall.cs @@ -4,156 +4,156 @@ using Jint; using Jint.Native.Object; - internal class Wall : VanillaWrapper +internal class Wall : VanillaWrapper +{ + public Wall(Engine engine, BaseObstacle wall) : base(engine, wall) { - public Wall(Engine engine, BaseObstacle wall) : base(engine, wall) - { - spawned = true; - } + spawned = true; + } - public Wall(Engine engine, ObjectInstance o) : base(engine, BeatmapFactory.Obstacle( - (float)GetJsValue(o, new[] { "b", "_time" }), - (int)GetJsValue(o, new[] { "x", "_lineIndex" }), - (int)(GetJsExist(o, "y") ? GetJsValue(o, "y") : GetJsValue(o, "_type") == 0 ? 0 : 2), - (int)GetJsValue(o, "_type"), - (float)GetJsValue(o, new[] { "d", "_duration" }), - (int)GetJsValue(o, new[] { "w", "_width" }), - (int)(GetJsExist(o, "h") ? GetJsValue(o, "h") : GetJsValue(o, "_type") == 0 ? 5 : 3), - GetCustomData(o, new[] { "customData", "_customData" })), false, GetJsBool(o, "selected")) - { - spawned = false; + public Wall(Engine engine, ObjectInstance o) : base(engine, BeatmapFactory.Obstacle( + (float)GetJsValue(o, new[] { "b", "_time" }), + (int)GetJsValue(o, new[] { "x", "_lineIndex" }), + (int)(GetJsExist(o, "y") ? GetJsValue(o, "y") : GetJsValue(o, "_type") == 0 ? 0 : 2), + (int)GetJsValue(o, "_type"), + (float)GetJsValue(o, new[] { "d", "_duration" }), + (int)GetJsValue(o, new[] { "w", "_width" }), + (int)(GetJsExist(o, "h") ? GetJsValue(o, "h") : GetJsValue(o, "_type") == 0 ? 5 : 3), + GetCustomData(o, new[] { "customData", "_customData" })), false, GetJsBool(o, "selected")) + { + spawned = false; - DeleteObject(); - } + DeleteObject(); + } - public float _time + public float _time + { + get => wrapped.Time; + set { - get => wrapped.Time; - set - { - DeleteObject(); - wrapped.Time = value; - } + DeleteObject(); + wrapped.Time = value; } + } - public int _lineIndex + public int _lineIndex + { + get => wrapped.PosX; + set { - get => wrapped.PosX; - set - { - DeleteObject(); - wrapped.PosX = value; - } + DeleteObject(); + wrapped.PosX = value; } + } - public int _type + public int _type + { + get => wrapped.Type; + set { - get => wrapped.Type; - set - { - DeleteObject(); - wrapped.Type = value; - } + DeleteObject(); + wrapped.Type = value; } + } - public float _duration + public float _duration + { + get => wrapped.Duration; + set { - get => wrapped.Duration; - set - { - DeleteObject(); - wrapped.Duration = value; - } + DeleteObject(); + wrapped.Duration = value; } + } - public int _width + public int _width + { + get => wrapped.Width; + set { - get => wrapped.Width; - set - { - DeleteObject(); - wrapped.Width = value; - } + DeleteObject(); + wrapped.Width = value; } + } - public float b + public float b + { + get => wrapped.Time; + set { - get => wrapped.Time; - set - { - DeleteObject(); - wrapped.Time = value; - } + DeleteObject(); + wrapped.Time = value; } + } - public int x + public int x + { + get => wrapped.PosX; + set { - get => wrapped.PosX; - set - { - DeleteObject(); - wrapped.PosX = value; - } + DeleteObject(); + wrapped.PosX = value; } + } - public int y + public int y + { + get => wrapped.PosY; + set { - get => wrapped.PosY; - set - { - DeleteObject(); - wrapped.PosY = value; - } + DeleteObject(); + wrapped.PosY = value; } + } - public float d + public float d + { + get => wrapped.Duration; + set { - get => wrapped.Duration; - set - { - DeleteObject(); - wrapped.Duration = value; - } + DeleteObject(); + wrapped.Duration = value; } + } - public int w + public int w + { + get => wrapped.Width; + set { - get => wrapped.Width; - set - { - DeleteObject(); - wrapped.Width = value; - } + DeleteObject(); + wrapped.Width = value; } + } - public int h + public int h + { + get => wrapped.Height; + set { - get => wrapped.Height; - set - { - DeleteObject(); - wrapped.Height = value; - } + DeleteObject(); + wrapped.Height = value; } + } - public override bool SpawnObject(BeatmapObjectContainerCollection collection) - { - if (spawned) return false; + public override bool SpawnObject(BeatmapObjectContainerCollection collection) + { + if (spawned) return false; - collection.SpawnObject(wrapped, false, false); + collection.SpawnObject(wrapped, false, false); - spawned = true; - return true; - } + spawned = true; + return true; + } - internal override bool DeleteObject() - { - if (!spawned) return false; + internal override bool DeleteObject() + { + if (!spawned) return false; - var collection = BeatmapObjectContainerCollection.GetCollectionForType(ObjectType.Obstacle); - collection.DeleteObject(wrapped, false); + var collection = BeatmapObjectContainerCollection.GetCollectionForType(ObjectType.Obstacle); + collection.DeleteObject(wrapped, false); - spawned = false; - return true; - } + spawned = false; + return true; } +} diff --git a/Wrappers/JSONWrapper.cs b/Wrappers/JSONWrapper.cs index 00d6bb7..559ae96 100644 --- a/Wrappers/JSONWrapper.cs +++ b/Wrappers/JSONWrapper.cs @@ -139,18 +139,6 @@ public static JSONNode dictToJSON(ExpandoObject o) return node; } - public static JSONNode dictToJSON(Dictionary dict) - { - var node = new JSONObject(); - - foreach (var x in dict) - { - node[x.Key] = castObjToJSON(x.Value); - } - - return node; - } - public object this[string aKey] { get From 89806605f24701c43f4af794dd1f4b11889f0ebb Mon Sep 17 00:00:00 2001 From: Kival Evan <5645391+KivalEvan@users.noreply.github.com> Date: Sun, 29 Jan 2023 14:21:56 -0800 Subject: [PATCH 18/26] Do C# magic --- Checks/ExternalJS.cs | 432 +++++++++++++++++++++++++------------------ 1 file changed, 253 insertions(+), 179 deletions(-) diff --git a/Checks/ExternalJS.cs b/Checks/ExternalJS.cs index a261b25..ddfd4b4 100644 --- a/Checks/ExternalJS.cs +++ b/Checks/ExternalJS.cs @@ -1,11 +1,4 @@ -using Jint; -using Jint.Native; -using Jint.Native.Array; -using Jint.Native.Object; -using Jint.Runtime; -using Jint.Runtime.Interop; -using SimpleJSON; -using System; +using System; using System.Collections.Generic; using System.Dynamic; using System.Globalization; @@ -17,59 +10,48 @@ using Beatmap.Base.Customs; using Beatmap.Enums; using Esprima; +using Jint; +using Jint.Native; +using Jint.Native.Array; +using Jint.Native.Object; +using Jint.Runtime; +using Jint.Runtime.Interop; +using SimpleJSON; using UnityEngine; -class ExternalJS : Check +internal class ExternalJS : Check { - private Engine engine; - private readonly Constraint timeConstraint = new TimeConstraint2(TimeSpan.FromSeconds(30L)); + private const bool DebugMode = false; private readonly string fileName; + private readonly Constraint timeConstraint = new TimeConstraint2(TimeSpan.FromSeconds(30L)); + private Engine engine; private bool valid; - private const bool DebugMode = false; - private static void TimeLog(string msg) { - if (!DebugMode) return; - - var time = DateTime.Now; - Debug.Log($"[{time}.{time.Millisecond}] [CM-JS] {msg}"); + public ExternalJS(string fileName) + { + this.fileName = fileName; + LoadJS(); } - private class TimeConstraint2 : Constraint + private static void TimeLog(string msg) { - private readonly TimeSpan _timeout; - private CancellationTokenSource cts; - - public TimeConstraint2(TimeSpan timeout) => _timeout = timeout; - - public override void Check() - { - if (!cts.IsCancellationRequested) - return; - throw new TimeoutException(); - } + if (!DebugMode) return; - public override void Reset() - { - cts?.Dispose(); - cts = new CancellationTokenSource(this._timeout); - } + var time = DateTime.Now; + Debug.Log($"[{time}.{time.Millisecond}] [CM-JS] {msg}"); } public Func Bind(Func func, T arg) { - return (file) => func(arg, file); + return file => func(arg, file); } private static void LogIt(object o) { if (o is ExpandoObject ex) - { Debug.Log(JSONWrapper.dictToJSON(ex)); - } else - { Debug.Log(o); - } } private static void Alert(string o) @@ -80,20 +62,15 @@ private static void Alert(string o) }, PersistentUI.DialogBoxPresetType.Ok); } - private JsValue require(string folder, string file) { - if (!file.EndsWith(".js")) - { - file += ".js"; - } - string fullPath = Path.Combine(folder, file); - string jsSource = File.ReadAllText(fullPath); - string newFolder = new FileInfo(fullPath).DirectoryName; + private JsValue require(string folder, string file) + { + if (!file.EndsWith(".js")) file += ".js"; + var fullPath = Path.Combine(folder, file); + var jsSource = File.ReadAllText(fullPath); + var newFolder = new FileInfo(fullPath).DirectoryName; try { - var e = new Engine(options => - { - options.Constraint(timeConstraint).LimitRecursion(200); - }) + var e = new Engine(options => { options.Constraint(timeConstraint).LimitRecursion(200); }) .SetValue("log", new Action(LogIt)) .SetValue("alert", new Action(Alert)) .SetValue("require", new Func(Bind(require, newFolder))) @@ -101,10 +78,7 @@ private JsValue require(string folder, string file) { var res = e.Evaluate(jsSource); - if (res.IsUndefined()) - { - res = e.GetValue("exports"); - } + if (res.IsUndefined()) res = e.GetValue("exports"); return res; } @@ -112,13 +86,8 @@ private JsValue require(string folder, string file) { { Debug.Log(jse); } - return null; - } - public ExternalJS(string fileName) - { - this.fileName = fileName; - LoadJS(); + return null; } public override void Reload() @@ -128,10 +97,7 @@ public override void Reload() private void LoadJS() { - engine = new Engine(options => - { - options.Constraint(timeConstraint).LimitRecursion(200); - }); + engine = new Engine(options => { options.Constraint(timeConstraint).LimitRecursion(200); }); var assemblyFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var streamReader = new StreamReader(Path.Combine(assemblyFolder, fileName)); @@ -159,24 +125,14 @@ private void LoadJS() { var ps = JSON.Parse(@params.AsString()).AsObject; foreach (var p in ps) - { if (p.Value.IsBoolean) - { Params.Add(new BoolParam(p.Key, p.Value.AsBool)); - } else if (p.Value.IsString) - { Params.Add(new StringParam(p.Key, p.Value.Value)); - } else if (p.Value.IsNumber) - { Params.Add(new FloatParam(p.Key, p.Value.AsFloat)); - } else if (p.Value.IsArray) - { Params.Add(new ListParam(p.Key, p.Value.AsArray.Children.Select(it => it.Value).ToList())); - } - } } var nameObj = engine.GetValue(exports, "name"); @@ -223,29 +179,6 @@ private BaseNote FromDynamic(dynamic note, List notes) _type == it.Type && _cutDirection == it.CutDirection); } - - class MapData { - public float currentBPM { get; private set; } - public float songBPM { get; private set; } - public float NJS { get; private set; } - public float offset { get; private set; } - public string characteristic { get; private set; } - public string difficulty { get; private set; } - public string environment { get; private set; } - public string version { get; private set; } - - public MapData(float currentBPM, float songBPM, float NJS, float offset, string characteristic, string difficulty, string environment, string version) - { - this.currentBPM = currentBPM; - this.songBPM = songBPM; - this.NJS = NJS; - this.offset = offset; - this.characteristic = characteristic; - this.difficulty = difficulty; - this.environment = environment; - this.version = version; - } - } public override CheckResult PerformCheck(List notes, List bombs, List arcs, List chains, List events, List walls, List customEvents, @@ -253,10 +186,12 @@ public override CheckResult PerformCheck(List notes, List bo { result.Clear(); + var rArgs = new ReceivedArguments(vals); var atsc = BeatmapObjectContainerCollection.GetCollectionForType(ObjectType.Note).AudioTimeSyncController; var currentBeat = atsc.CurrentBeat; - var collection = BeatmapObjectContainerCollection.GetCollectionForType(ObjectType.BpmChange); + var collection = + BeatmapObjectContainerCollection.GetCollectionForType(ObjectType.BpmChange); var lastBPMChange = collection.FindLastBpm(atsc.CurrentBeat); var currentBPM = lastBPMChange?.Bpm ?? atsc.Song.BeatsPerMinute; @@ -271,75 +206,80 @@ public override CheckResult PerformCheck(List notes, List bo try { - var valsToString = vals.Select(paramValue => - { - switch (paramValue.Value) - { - case ParamValue pvf: - return new KeyValuePair(paramValue.Key, pvf.value.ToString(CultureInfo.InvariantCulture)); - case ParamValue pvs: - return new KeyValuePair(paramValue.Key, $"\"{pvs.value}\""); - case ParamValue pvb: - return new KeyValuePair(paramValue.Key, pvb.value ? "true" : "false"); - default: - return new KeyValuePair(paramValue.Key, "null"); - } - }); - - var valsObj = string.Join(",", valsToString.Select((v, idx) => $"{idx.ToString()}:{v.Value},\"{v.Key}\":{v.Value}")); - var valsParams = string.Join(",", valsToString.Select(v => v.Value)); - TimeLog("Init"); var tmp = engine - .SetValue("notes", originalNotes) - .SetValue("bombs", originalBombs) - .SetValue("arcs", originalArcs) - .SetValue("chains", originalChains) - .SetValue("walls", originalWalls) - .SetValue("events", originalEvents) - .SetValue("customEvents", originalCustomEvents) - .SetValue("bpmChanges", originalBpmChanges) - .SetValue("data", new MapData( - currentBPM, - atsc.Song.BeatsPerMinute, - BeatSaberSongContainer.Instance.DifficultyData.NoteJumpMovementSpeed, - BeatSaberSongContainer.Instance.DifficultyData.NoteJumpStartBeatOffset, - BeatSaberSongContainer.Instance.DifficultyData.ParentBeatmapSet.BeatmapCharacteristicName, - BeatSaberSongContainer.Instance.DifficultyData.Difficulty, - (BeatSaberSongContainer.Instance.DifficultyData.ParentBeatmapSet.BeatmapCharacteristicName == "360Degree" || BeatSaberSongContainer.Instance.DifficultyData.ParentBeatmapSet.BeatmapCharacteristicName == "90Degree") ? BeatSaberSongContainer.Instance.Song.AllDirectionsEnvironmentName : BeatSaberSongContainer.Instance.Song.EnvironmentName, - BeatSaberSongContainer.Instance.Map.Version - )) - .SetValue("cursor", currentBeat) - .SetValue("minTime", 0.24f) - .SetValue("maxTime", 0.75f) - .SetValue("addError", new Action((dynamic note, string str) => - { - var obj = FromDynamic(note, notes); + .SetValue("notes", originalNotes) + .SetValue("bombs", originalBombs) + .SetValue("arcs", originalArcs) + .SetValue("chains", originalChains) + .SetValue("walls", originalWalls) + .SetValue("events", originalEvents) + .SetValue("customEvents", originalCustomEvents) + .SetValue("bpmChanges", originalBpmChanges) + .SetValue("data", new MapData( + currentBPM, + atsc.Song.BeatsPerMinute, + BeatSaberSongContainer.Instance.DifficultyData.NoteJumpMovementSpeed, + BeatSaberSongContainer.Instance.DifficultyData.NoteJumpStartBeatOffset, + BeatSaberSongContainer.Instance.DifficultyData.ParentBeatmapSet.BeatmapCharacteristicName, + BeatSaberSongContainer.Instance.DifficultyData.Difficulty, + BeatSaberSongContainer.Instance.DifficultyData.ParentBeatmapSet.BeatmapCharacteristicName == + "360Degree" || + BeatSaberSongContainer.Instance.DifficultyData.ParentBeatmapSet.BeatmapCharacteristicName == + "90Degree" + ? BeatSaberSongContainer.Instance.Song.AllDirectionsEnvironmentName + : BeatSaberSongContainer.Instance.Song.EnvironmentName, + BeatSaberSongContainer.Instance.Map.Version + )) + .SetValue("args", rArgs) + .SetValue("cursor", currentBeat) + .SetValue("minTime", 0.24f) + .SetValue("maxTime", 0.75f) + .SetValue("addError", new Action((dynamic note, string str) => + { + var obj = FromDynamic(note, notes); - if (obj != null) - result.Add(obj, str ?? ""); - })) - .SetValue("addWarning", new Action((dynamic note, string str) => - { - var obj = FromDynamic(note, notes); + if (obj != null) + result.Add(obj, str ?? ""); + })) + .SetValue("addWarning", new Action((dynamic note, string str) => + { + var obj = FromDynamic(note, notes); - if (obj != null) - result.AddWarning(obj, str ?? ""); - })); + if (obj != null) + result.AddWarning(obj, str ?? ""); + })); TimeLog("Run"); - tmp.Execute("global.params = {" + valsObj + "};" + - "var output = module.exports.run ? module.exports.run(cursor, notes, events, walls, {}, global, data, customEvents, bpmChanges, bombs, arcs, chains) : module.exports.performCheck({notes: notes}" + (vals.Length > 0 ? ", " + valsParams : "") + ");" + - "if (output && output.notes) { notes = output.notes; };" + - "if (output && output.bombs) { bombs = output.bombs; };" + - "if (output && output.arcs) { arcs = output.arcs; };" + - "if (output && output.chains) { chains = output.chains; };" + - "if (output && output.events) { events = output.events; };" + - "if (output && output.customEvents) { customEvents = output.customEvents; };" + - "if (output && output.bpmChanges) { bpmChanges = output.bpmChanges; };" + - "if (output && output.walls) { walls = output.walls; };"); + tmp.Execute("global.params = args;" + + "var output = module.exports.run ? module.exports.run(cursor, notes, events, walls, {}, global, data, customEvents, bpmChanges, bombs, arcs, chains) : module.exports.performCheck({notes: notes}" + + (vals.Length > 0 + ? ", " + + string.Join(",", vals.Select(paramValue => + { + switch (paramValue.Value) + { + case ParamValue pvf: + return new KeyValuePair(paramValue.Key, pvf.value.ToString(CultureInfo.InvariantCulture)); + case ParamValue pvs: + return new KeyValuePair(paramValue.Key, $"\"{pvs.value}\""); + case ParamValue pvb: + return new KeyValuePair(paramValue.Key, pvb.value ? "true" : "false"); + default: + return new KeyValuePair(paramValue.Key, "null"); + } + })) + : "") + ");" + + "if (output && output.notes) { notes = output.notes; };" + + "if (output && output.bombs) { bombs = output.bombs; };" + + "if (output && output.arcs) { arcs = output.arcs; };" + + "if (output && output.chains) { chains = output.chains; };" + + "if (output && output.events) { events = output.events; };" + + "if (output && output.customEvents) { customEvents = output.customEvents; };" + + "if (output && output.bpmChanges) { bpmChanges = output.bpmChanges; };" + + "if (output && output.walls) { walls = output.walls; };"); } catch (JavaScriptException jse) { @@ -350,14 +290,22 @@ public override CheckResult PerformCheck(List notes, List bo SelectionController.DeselectAll(); var actions = new List(); - actions.AddRange(Reconcile(originalNotes, engine.GetValue("notes").AsArray(), notes, i => new Note(engine, i), ObjectType.Note)); - actions.AddRange(Reconcile(originalBombs, engine.GetValue("bombs").AsArray(), bombs, i => new BombNote(engine, i), ObjectType.Note)); - actions.AddRange(Reconcile(originalArcs, engine.GetValue("arcs").AsArray(), arcs, i => new Arc(engine, i), ObjectType.Arc)); - actions.AddRange(Reconcile(originalChains, engine.GetValue("chains").AsArray(), chains, i => new Chain(engine, i), ObjectType.Chain)); - actions.AddRange(Reconcile(originalWalls, engine.GetValue("walls").AsArray(), walls, i => new Wall(engine, i), ObjectType.Obstacle)); - actions.AddRange(Reconcile(originalEvents, engine.GetValue("events").AsArray(), events, i => new Event(engine, i), ObjectType.Event)); - actions.AddRange(Reconcile(originalCustomEvents, engine.GetValue("customEvents").AsArray(), customEvents, i => new CustomEvent(engine, i), ObjectType.CustomEvent)); - actions.AddRange(Reconcile(originalBpmChanges, engine.GetValue("bpmChanges").AsArray(), bpmChanges, i => new BpmChange(engine, i), ObjectType.BpmChange)); + actions.AddRange(Reconcile(originalNotes, engine.GetValue("notes").AsArray(), notes, i => new Note(engine, i), + ObjectType.Note)); + actions.AddRange(Reconcile(originalBombs, engine.GetValue("bombs").AsArray(), bombs, + i => new BombNote(engine, i), ObjectType.Note)); + actions.AddRange(Reconcile(originalArcs, engine.GetValue("arcs").AsArray(), arcs, i => new Arc(engine, i), + ObjectType.Arc)); + actions.AddRange(Reconcile(originalChains, engine.GetValue("chains").AsArray(), chains, + i => new Chain(engine, i), ObjectType.Chain)); + actions.AddRange(Reconcile(originalWalls, engine.GetValue("walls").AsArray(), walls, i => new Wall(engine, i), + ObjectType.Obstacle)); + actions.AddRange(Reconcile(originalEvents, engine.GetValue("events").AsArray(), events, + i => new Event(engine, i), ObjectType.Event)); + actions.AddRange(Reconcile(originalCustomEvents, engine.GetValue("customEvents").AsArray(), customEvents, + i => new CustomEvent(engine, i), ObjectType.CustomEvent)); + actions.AddRange(Reconcile(originalBpmChanges, engine.GetValue("bpmChanges").AsArray(), bpmChanges, + i => new BpmChange(engine, i), ObjectType.BpmChange)); SelectionController.SelectionChangedEvent?.Invoke(); @@ -374,14 +322,14 @@ public override CheckResult PerformCheck(List notes, List bo return result; } - private List Reconcile(IEnumerable original, ArrayInstance noteArr, List notes, Func inst, ObjectType type) where U : Wrapper where T : BaseObject + private List Reconcile(IEnumerable original, ArrayInstance noteArr, List notes, + Func inst, ObjectType type) where U : Wrapper where T : BaseObject { TimeLog("Reconcile " + original.GetType()); var beatmapActions = new List(); var outputNotes = new List(); foreach (var test in noteArr) - { if (test is U a) { outputNotes.Add(a); @@ -404,7 +352,6 @@ private List Reconcile(IEnumerable original, ArrayInstan Debug.Log("Something else???"); Debug.Log(test.GetType()); } - } var lookup = original.ToDictionary(x => x.wrapped, x => x); @@ -441,24 +388,151 @@ private List Reconcile(IEnumerable original, ArrayInstan TimeLog("Update selection"); foreach (var note in outputNotes.Where(note => note.selected)) - { SelectionController.Select(note.wrapped, true, false, false); - } TimeLog("Create actions"); - foreach (var note in toAction) { + foreach (var note in toAction) if (note.original != null) + beatmapActions.Add(new BeatmapObjectModifiedAction(note.wrapped, note.wrapped, note.original, + "Script edited object")); + else + beatmapActions.Add(new BeatmapObjectPlacementAction(note.wrapped, Enumerable.Empty(), + "Script spawned object")); + + collection.RefreshPool(); + return beatmapActions; + } + + private class TimeConstraint2 : Constraint + { + private readonly TimeSpan _timeout; + private CancellationTokenSource cts; + + public TimeConstraint2(TimeSpan timeout) + { + _timeout = timeout; + } + + public override void Check() + { + if (!cts.IsCancellationRequested) + return; + throw new TimeoutException(); + } + + public override void Reset() + { + cts?.Dispose(); + cts = new CancellationTokenSource(_timeout); + } + } + + private class MapData + { + public MapData(float currentBPM, float songBPM, float NJS, float offset, string characteristic, + string difficulty, string environment, string version) + { + this.currentBPM = currentBPM; + this.songBPM = songBPM; + this.NJS = NJS; + this.offset = offset; + this.characteristic = characteristic; + this.difficulty = difficulty; + this.environment = environment; + this.version = version; + } + + public float currentBPM { get; } + public float songBPM { get; } + public float NJS { get; } + public float offset { get; } + public string characteristic { get; } + public string difficulty { get; } + public string environment { get; } + public string version { get; } + } + + private class ReceivedArguments + { + private readonly List> keyMap; + + public ReceivedArguments(IEnumerable> p) + { + keyMap = p.ToList(); + } + + private object RetrieveValue(KeyValuePair kvp) + { + switch (kvp.Value) { - beatmapActions.Add(new BeatmapObjectModifiedAction(note.wrapped, note.wrapped, note.original, "Script edited object")); + case ParamValue pvf: + return pvf.value; + case ParamValue pvs: + return pvs.value; + case ParamValue pvb: + return pvb.value; + default: + return null; } + } + + private void SetValue(KeyValuePair kvp, object value) + { + var newValue = JSONWrapper.castObjToJSON(value); + KeyValuePair newKvp; + + if (newValue.IsString) + newKvp = new KeyValuePair(kvp.Key, new ParamValue(newValue)); + else if (newValue.IsNumber) + newKvp = new KeyValuePair(kvp.Key, new ParamValue(newValue.AsFloat)); + else if (newValue.IsBoolean) + newKvp = new KeyValuePair(kvp.Key, new ParamValue(newValue.AsBool)); + else if (newValue.IsArray) + // definitely not allowed + throw new Exception("Array cannot be used to assign parameter"); + else if (newValue.IsObject) + // definitely not allowed + throw new Exception("Object cannot be used to assign parameter"); else + newKvp = new KeyValuePair(kvp.Key, new ParamValue(null)); + + var index = keyMap.FindIndex(r => r.Key == kvp.Key); + if (index != -1) keyMap[index] = newKvp; + } + + public object this[string idx] + { + get + { + var result = int.TryParse(idx, out var idxI) + ? keyMap.ElementAtOrDefault(idxI) + : keyMap.FirstOrDefault(p => p.Key == idx); + return result.Equals(default(KeyValuePair)) ? null : RetrieveValue(result); + } + set { - beatmapActions.Add(new BeatmapObjectPlacementAction(note.wrapped, Enumerable.Empty(), "Script spawned object")); + var result = int.TryParse(idx, out var idxI) + ? keyMap.ElementAtOrDefault(idxI) + : keyMap.FirstOrDefault(p => p.Key == idx); + if (result.Equals(default(KeyValuePair))) return; + SetValue(result, value); + } + } + + public object this[int idx] + { + get + { + var result = keyMap.ElementAtOrDefault(idx); + return result.Equals(default(KeyValuePair)) ? null : RetrieveValue(result); + } + set + { + var result = keyMap.ElementAtOrDefault(idx); + if (result.Equals(default(KeyValuePair))) return; + SetValue(result, value); } } - - collection.RefreshPool(); - return beatmapActions; } } From b7f0edf0fa6dd98e7bc5c556ce9577d6bcb48f9d Mon Sep 17 00:00:00 2001 From: Kival Evan <5645391+KivalEvan@users.noreply.github.com> Date: Sun, 29 Jan 2023 14:39:32 -0800 Subject: [PATCH 19/26] oops, invalid params string join --- Checks/ExternalJS.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Checks/ExternalJS.cs b/Checks/ExternalJS.cs index ddfd4b4..912359f 100644 --- a/Checks/ExternalJS.cs +++ b/Checks/ExternalJS.cs @@ -262,13 +262,13 @@ public override CheckResult PerformCheck(List notes, List bo switch (paramValue.Value) { case ParamValue pvf: - return new KeyValuePair(paramValue.Key, pvf.value.ToString(CultureInfo.InvariantCulture)); + return pvf.value.ToString(CultureInfo.InvariantCulture); case ParamValue pvs: - return new KeyValuePair(paramValue.Key, $"\"{pvs.value}\""); + return $"\"{pvs.value}\""; case ParamValue pvb: - return new KeyValuePair(paramValue.Key, pvb.value ? "true" : "false"); + return pvb.value ? "true" : "false"; default: - return new KeyValuePair(paramValue.Key, "null"); + return "null"; } })) : "") + ");" + From 3bb41f1f36b1e335a5c981d89f5a5b6714faee54 Mon Sep 17 00:00:00 2001 From: Kival Evan <5645391+KivalEvan@users.noreply.github.com> Date: Sun, 29 Jan 2023 15:27:57 -0800 Subject: [PATCH 20/26] A small bit of optimisation --- Checks/ExternalJS.cs | 73 ++++++++++++-------------------------------- 1 file changed, 20 insertions(+), 53 deletions(-) diff --git a/Checks/ExternalJS.cs b/Checks/ExternalJS.cs index 912359f..707a504 100644 --- a/Checks/ExternalJS.cs +++ b/Checks/ExternalJS.cs @@ -455,50 +455,32 @@ public MapData(float currentBPM, float songBPM, float NJS, float offset, string private class ReceivedArguments { - private readonly List> keyMap; + // looks dangerous, probably better with JsValue + private readonly List> keyMap; public ReceivedArguments(IEnumerable> p) { - keyMap = p.ToList(); - } - - private object RetrieveValue(KeyValuePair kvp) - { - switch (kvp.Value) + keyMap = p.Select(kvp => { - case ParamValue pvf: - return pvf.value; - case ParamValue pvs: - return pvs.value; - case ParamValue pvb: - return pvb.value; - default: - return null; - } + switch (kvp.Value) + { + case ParamValue pvf: + return new KeyValuePair(kvp.Key, pvf.value); + case ParamValue pvs: + return new KeyValuePair(kvp.Key, pvs.value); + case ParamValue pvb: + return new KeyValuePair(kvp.Key, pvb.value); + default: + return new KeyValuePair(kvp.Key, null); + } + }).ToList(); } - private void SetValue(KeyValuePair kvp, object value) + private void SetValue(KeyValuePair kvp, object value) { - var newValue = JSONWrapper.castObjToJSON(value); - KeyValuePair newKvp; - - if (newValue.IsString) - newKvp = new KeyValuePair(kvp.Key, new ParamValue(newValue)); - else if (newValue.IsNumber) - newKvp = new KeyValuePair(kvp.Key, new ParamValue(newValue.AsFloat)); - else if (newValue.IsBoolean) - newKvp = new KeyValuePair(kvp.Key, new ParamValue(newValue.AsBool)); - else if (newValue.IsArray) - // definitely not allowed - throw new Exception("Array cannot be used to assign parameter"); - else if (newValue.IsObject) - // definitely not allowed - throw new Exception("Object cannot be used to assign parameter"); - else - newKvp = new KeyValuePair(kvp.Key, new ParamValue(null)); - + // var newValue = JSONWrapper.castObjToJSON(value); var index = keyMap.FindIndex(r => r.Key == kvp.Key); - if (index != -1) keyMap[index] = newKvp; + if (index != -1) keyMap[index] = new KeyValuePair(kvp.Key, value); } public object this[string idx] @@ -508,29 +490,14 @@ public object this[string idx] var result = int.TryParse(idx, out var idxI) ? keyMap.ElementAtOrDefault(idxI) : keyMap.FirstOrDefault(p => p.Key == idx); - return result.Equals(default(KeyValuePair)) ? null : RetrieveValue(result); + return result.Equals(default(KeyValuePair)) ? null : result.Value; } set { var result = int.TryParse(idx, out var idxI) ? keyMap.ElementAtOrDefault(idxI) : keyMap.FirstOrDefault(p => p.Key == idx); - if (result.Equals(default(KeyValuePair))) return; - SetValue(result, value); - } - } - - public object this[int idx] - { - get - { - var result = keyMap.ElementAtOrDefault(idx); - return result.Equals(default(KeyValuePair)) ? null : RetrieveValue(result); - } - set - { - var result = keyMap.ElementAtOrDefault(idx); - if (result.Equals(default(KeyValuePair))) return; + if (result.Equals(default(KeyValuePair))) return; SetValue(result, value); } } From 3ea8930a95e66c61702cef8a3f8246803276967e Mon Sep 17 00:00:00 2001 From: Kival Evan <5645391+KivalEvan@users.noreply.github.com> Date: Tue, 31 Jan 2023 07:25:30 +0800 Subject: [PATCH 21/26] Update README.md --- README.md | 89 ++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 56 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index 7147d5a..fee68d9 100644 --- a/README.md +++ b/README.md @@ -21,45 +21,68 @@ You can add more error check types directly by placing javascript files in the s The parser uses [Jint 3 (beta)](https://github.com/sebastienros/jint/issues/343) and [esprima](https://github.com/sebastienros/esprima-dotnet) which can parse ES6 but not all features are supported, for instance esprima can parse `class` but Jint will throw an exception so you'll have to rewrite these as old-style functions and prototypes -As this is essentially alpha the interface for these checks may change but for now you just need to create a block similar to: +The script made for beatmap v2 can be used for beatmap v3 and vice versa. However, `customData` require special handling by the script to assign correct key for specific version. -``` +#### Module + +This part of the code defines the script to be shown and used in editor. This is currently designed to be compatible with MM scripts, you just need to add the name and params. As this is essentially alpha, the interface for these checks may change but for now you just need to create a block similar to: + +```js module.exports = { name: "My error check", - params: {"Min Time": 0.24}, - run: function(cursor, notes, events, walls, _, global, data, customEvents, bpmChanges) + params: { "Min Time": 0.24 }, + run: (cursor, notes, events, walls, _, global, data, customEvents, bpmChanges, bombs, arcs, chains) => {}, + errorCheck: true }; ``` -- **name** appears in the drop-down ingame. -- **params** is an object, for each key a text field will be show to the user where they can enter a value which will be passed to you as a float -- **run** is a function that will be called when the user runs your check, this is currently designed to be compatible with MM scripts, you just need to add the name and params. - - **cursor** is the position the user is looking at in the map - - **notes** is an array of notes ordered by time (I can't guarantee what order notes that happen at the same time will be in for now) which can be modified. You can directly modify the values of notes in the array with code like `notes[0]._time = 10;` - OR if you want to generate a fresh array you need to provide your new array in object returned from your function (see below) - - **events** are provided next and work the same as notes - - **walls** are last of the map objects and work the same as notes - - **\_** In MM scripts the parameter here was called save? I don't know what it did but this parameter is just an empty object and has no use. Provided for compatibility. - - **globals** can be used to persist data between runs of your script, it will be unchanged on future invocations. It also includes a `params` array which contains the values set for your params. (I _assume_ this will be returned in order) - - **data** has information about the map, currently the list of data is as follows: - - currentBPM - The bpm at the cursor accounting for BPM changes - - songBPM - The bpm of the song - - NJS - The note jump speed set for the song - - offset - How far into the song the user starts - - characteristic - Current beatmap characteristics - - difficulty - Current beatmap difficulty - - environment - Current beatmap environment - - version - Current beatmap version - - **customEvents** are custom objects used for [noodling](https://github.com/Aeroluna/NoodleExtensions/blob/master/Documentation/AnimationDocs.md#custom-events) - - **bpmChanges** may be useful for working out what the bpm is at a point in a map or programatically creating slides - - **bombs** - v3 - - **arcs** - v3 - - **chains** - v3 - -Two functions will be defined before calling `performCheck` - -- **addError**(note, reason) - Pass back the problem note object, all it's properties (except `_customData`) must match the original passed note for it to be marked properly and you can provide a reason as the second parameter -- **addWarning**(note, reason) - The same as `addError` except the note will only be highlighted yellow +- `name` string appears in the drop-down list. +- `params` is an object, for each key a text field will be show to the user where they can enter a value which will be passed to `run` function + - The object is only allowed to have set of certain type of value: + - `"stringKey": "string"` + - `"numberKey": 0.0` + - `"booleanKey": true` + - `"arrayKey": ["ary"]` (only array of string is allowed) +- `run` is a function that will be called when the user runs your check. +- `errorCheck` is an optional boolean property to display error message, default to `true`. + +#### Run Function + +The function uses the data from current active beatmap. You can directly modify the value of beatmap objects in the array with code like `notes[0]._time = 10;` **OR** if you want to generate a fresh array you need to provide your new array in object returned from your function (see below). + +```js +function run(cursor, notes, events, walls, _, global, data, customEvents, bpmChanges, bombs, arcs, chains) {} +``` + + - `cursor` is the current beat time of grid cursor in editor. + - `notes` is an array of objects (v3 will not include bomb note). + - `events` is an array of events (v3 will not include boost and rotation event). + - `walls` is an array of obstacles. + - `_` In MM scripts the parameter here was called save? I don't know what it did but this parameter is just an empty object and has no use. Provided for compatibility. + - `globals` can be used to persist data between runs of your script, it will be unchanged on future invocations. + - `params` is included as an object which contains the values set for your params. + - The value set for params is `number`, `string` and `boolean`. + - It can be accessed via string index `global.params.key` or number index `global.params[0]` (based on the order of `module.exports.params`). + - Property assignment is not possible and re-assignment while allowed is not recommended, assign the param value to new variable is recommended if called often. + - `data` has read-only information about the map, currently the list of data is as follows: + - `currentBPM` is the BPM at the cursor accounting for BPM changes. + - `songBPM` is the BPM of the song. + - `NJS` is the note jump speed on current difficulty. + - `offset` is the offset of NJS on current difficulty. + - `characteristic` is current beatmap characteristics. + - `difficulty` is current beatmap difficulty. + - `environment` is current beatmap environment. + - `version` is current beatmap version. + - `customEvents` is an array of custom objects used for [noodling](https://github.com/Aeroluna/NoodleExtensions/blob/master/Documentation/AnimationDocs.md#custom-events) + - `bpmChanges` may be useful for working out what the bpm is at a point in a map or programatically creating slides. + - `bombs` **V3 ONLY** is an array of bomb notes. + - `arcs` **V3 ONLY** is an array of arcs. + - `chains` **V3 ONLY** is an array of chains. + +Two functions will be defined before calling `run` or `performCheck` + +- `addError(note, reason)` pass back the problem note object, all it's properties (except `customData`) must match the original passed note for it to be marked properly and you can provide a reason as the second parameter. +- `addWarning(note, reason)` is the same as `addError` except the note will only be highlighted yellow. [There are example scripts in Examples](Examples) From 6e4a6433599fd1418ac6c5cb0d8ab404b48bdaa5 Mon Sep 17 00:00:00 2001 From: Kival Evan <5645391+KivalEvan@users.noreply.github.com> Date: Wed, 8 Feb 2023 23:22:49 -0800 Subject: [PATCH 22/26] Fixed arc and chain arguments --- Wrappers/Beatmap/Arc.cs | 2 +- Wrappers/Beatmap/Chain.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Wrappers/Beatmap/Arc.cs b/Wrappers/Beatmap/Arc.cs index a00c806..e6de87c 100644 --- a/Wrappers/Beatmap/Arc.cs +++ b/Wrappers/Beatmap/Arc.cs @@ -13,9 +13,9 @@ public Arc(Engine engine, BaseArc arc) : base(engine, arc) public Arc(Engine engine, ObjectInstance o) : base(engine, BeatmapFactory.Arc( (float)GetJsValue(o, "b"), - (int)GetJsValue(o, "c"), (int)GetJsValue(o, "x"), (int)GetJsValue(o, "y"), + (int)GetJsValue(o, "c"), (int)GetJsValue(o, "d"), 0, (float)GetJsValue(o, "mu"), diff --git a/Wrappers/Beatmap/Chain.cs b/Wrappers/Beatmap/Chain.cs index 2d50240..b8c4fd3 100644 --- a/Wrappers/Beatmap/Chain.cs +++ b/Wrappers/Beatmap/Chain.cs @@ -13,9 +13,9 @@ public Chain(Engine engine, BaseChain chain) : base(engine, chain) public Chain(Engine engine, ObjectInstance o) : base(engine, BeatmapFactory.Chain( (int)GetJsValue(o, "b"), - (int)GetJsValue(o, "c"), (int)GetJsValue(o, "x"), (int)GetJsValue(o, "y"), + (int)GetJsValue(o, "c"), (int)GetJsValue(o, "d"), 0, (float)GetJsValue(o, "tb"), From 96402de4039ed702ca8a10afff2409deeb8768c8 Mon Sep 17 00:00:00 2001 From: Kival Evan <5645391+KivalEvan@users.noreply.github.com> Date: Mon, 6 Mar 2023 00:59:38 +0800 Subject: [PATCH 23/26] Fix type being required for v3 wall --- Wrappers/Beatmap/Wall.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Wrappers/Beatmap/Wall.cs b/Wrappers/Beatmap/Wall.cs index c5c81b1..516556c 100644 --- a/Wrappers/Beatmap/Wall.cs +++ b/Wrappers/Beatmap/Wall.cs @@ -15,7 +15,7 @@ public Wall(Engine engine, ObjectInstance o) : base(engine, BeatmapFactory.Obsta (float)GetJsValue(o, new[] { "b", "_time" }), (int)GetJsValue(o, new[] { "x", "_lineIndex" }), (int)(GetJsExist(o, "y") ? GetJsValue(o, "y") : GetJsValue(o, "_type") == 0 ? 0 : 2), - (int)GetJsValue(o, "_type"), + (int)(GetJsExist(o, "_type") ? GetJsValue(o, "_type") : 0), (float)GetJsValue(o, new[] { "d", "_duration" }), (int)GetJsValue(o, new[] { "w", "_width" }), (int)(GetJsExist(o, "h") ? GetJsValue(o, "h") : GetJsValue(o, "_type") == 0 ? 5 : 3), From 57d65bae619a8a8eec64f09cf4d81c98bb1d7b6f Mon Sep 17 00:00:00 2001 From: Kival Evan <5645391+KivalEvan@users.noreply.github.com> Date: Tue, 7 Mar 2023 05:13:42 -0800 Subject: [PATCH 24/26] Fix exist check --- Wrappers/Wrapper.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Wrappers/Wrapper.cs b/Wrappers/Wrapper.cs index ee544b7..3e55459 100644 --- a/Wrappers/Wrapper.cs +++ b/Wrappers/Wrapper.cs @@ -60,7 +60,7 @@ protected static double GetJsValue(ObjectInstance o, string key) protected static bool GetJsExist(ObjectInstance o, string key) { - return o.IsPrimitive(); + return o.TryGetValue(key, out _); } protected static string GetJsString(ObjectInstance o, string key) From fb8552c161ccc1a28cc3a02181eef6176a0f2470 Mon Sep 17 00:00:00 2001 From: Kival Evan <5645391+KivalEvan@users.noreply.github.com> Date: Fri, 5 May 2023 10:47:17 -0700 Subject: [PATCH 25/26] CM0.8.580 BPM update --- CMJS.cs | 36 +++++------ Checks/Check.cs | 6 +- Checks/CheckResult.cs | 2 +- Checks/ExternalJS.cs | 20 +++--- Checks/StackedNotes.cs | 4 +- Checks/VisionBlocks.cs | 16 ++--- ErrorChecker.csproj | 2 +- Wrappers/Beatmap/Arc.cs | 8 +-- Wrappers/Beatmap/BombNote.cs | 4 +- .../Beatmap/{BpmChange.cs => BpmEvent.cs} | 62 +++---------------- Wrappers/Beatmap/Chain.cs | 8 +-- Wrappers/Beatmap/CustomEvent.cs | 8 +-- Wrappers/Beatmap/Event.cs | 8 +-- Wrappers/Beatmap/Note.cs | 8 +-- Wrappers/Beatmap/Wall.cs | 8 +-- 15 files changed, 79 insertions(+), 121 deletions(-) rename Wrappers/Beatmap/{BpmChange.cs => BpmEvent.cs} (50%) diff --git a/CMJS.cs b/CMJS.cs index bbf1a72..fde69e1 100644 --- a/CMJS.cs +++ b/CMJS.cs @@ -25,7 +25,7 @@ public class CMJS private ObstacleGridContainer wallsContainer; private EventGridContainer eventsContainer; private CustomEventGridContainer customEventsContainer; - private BPMChangeGridContainer bpmChangesContainer; + private BPMChangeGridContainer BpmEventsContainer; private List checks = new List() { new VisionBlocks(), @@ -72,7 +72,7 @@ private void SceneLoaded(Scene arg0, LoadSceneMode arg1) wallsContainer = UnityEngine.Object.FindObjectOfType(); eventsContainer = UnityEngine.Object.FindObjectOfType(); customEventsContainer = UnityEngine.Object.FindObjectOfType(); - bpmChangesContainer = UnityEngine.Object.FindObjectOfType(); + BpmEventsContainer = UnityEngine.Object.FindObjectOfType(); var mapEditorUI = UnityEngine.Object.FindObjectOfType(); atsc = BeatmapObjectContainerCollection.GetCollectionForType(ObjectType.Note).AudioTimeSyncController; @@ -119,23 +119,23 @@ public void CheckErrors(Check check) if (isV3) { // TODO: since containers has multiple different object, check events and notes - var allNotes = notesContainer.LoadedObjects.Where(it => it is V3ColorNote).Cast().OrderBy(it => it.Time).ToList(); - var allBombs = notesContainer.LoadedObjects.Where(it => it is V3BombNote).Cast().OrderBy(it => it.Time).ToList(); - var allArcs = arcsContainer.LoadedObjects.Cast().OrderBy(it => it.Time).ToList(); - var allChains = chainsContainer.LoadedObjects.Cast().OrderBy(it => it.Time).ToList(); - var allWalls = wallsContainer.LoadedObjects.Cast().OrderBy(it => it.Time).ToList(); - var allEvents = eventsContainer.LoadedObjects.Cast().OrderBy(it => it.Time).ToList(); - var allCustomEvents = customEventsContainer.LoadedObjects.Cast().OrderBy(it => it.Time).ToList(); - var allBpmChanges = bpmChangesContainer.LoadedObjects.Cast().OrderBy(it => it.Time).ToList(); - errors = check.PerformCheck(allNotes, allBombs, allArcs, allChains, allEvents, allWalls, allCustomEvents, allBpmChanges, vals).Commit(); + var allNotes = notesContainer.LoadedObjects.Where(it => it is V3ColorNote).Cast().OrderBy(it => it.JsonTime).ToList(); + var allBombs = notesContainer.LoadedObjects.Where(it => it is V3BombNote).Cast().OrderBy(it => it.JsonTime).ToList(); + var allArcs = arcsContainer.LoadedObjects.Cast().OrderBy(it => it.JsonTime).ToList(); + var allChains = chainsContainer.LoadedObjects.Cast().OrderBy(it => it.JsonTime).ToList(); + var allWalls = wallsContainer.LoadedObjects.Cast().OrderBy(it => it.JsonTime).ToList(); + var allEvents = eventsContainer.LoadedObjects.Cast().OrderBy(it => it.JsonTime).ToList(); + var allCustomEvents = customEventsContainer.LoadedObjects.Cast().OrderBy(it => it.JsonTime).ToList(); + var allBpmEvents = BpmEventsContainer.LoadedObjects.Cast().OrderBy(it => it.JsonTime).ToList(); + errors = check.PerformCheck(allNotes, allBombs, allArcs, allChains, allEvents, allWalls, allCustomEvents, allBpmEvents, vals).Commit(); } else { - var allNotes = notesContainer.LoadedObjects.Cast().OrderBy(it => it.Time).ToList(); - var allWalls = wallsContainer.LoadedObjects.Cast().OrderBy(it => it.Time).ToList(); - var allEvents = eventsContainer.LoadedObjects.Cast().OrderBy(it => it.Time).ToList(); - var allCustomEvents = customEventsContainer.LoadedObjects.Cast().OrderBy(it => it.Time).ToList(); - var allBpmChanges = bpmChangesContainer.LoadedObjects.Cast().OrderBy(it => it.Time).ToList(); - errors = check.PerformCheck(allNotes, new List(), new List(), new List(), allEvents, allWalls, allCustomEvents, allBpmChanges, vals).Commit(); + var allNotes = notesContainer.LoadedObjects.Cast().OrderBy(it => it.JsonTime).ToList(); + var allWalls = wallsContainer.LoadedObjects.Cast().OrderBy(it => it.JsonTime).ToList(); + var allEvents = eventsContainer.LoadedObjects.Cast().OrderBy(it => it.JsonTime).ToList(); + var allCustomEvents = customEventsContainer.LoadedObjects.Cast().OrderBy(it => it.JsonTime).ToList(); + var allBpmEvents = BpmEventsContainer.LoadedObjects.Cast().OrderBy(it => it.JsonTime).ToList(); + errors = check.PerformCheck(allNotes, new List(), new List(), new List(), allEvents, allWalls, allCustomEvents, allBpmEvents, vals).Commit(); } // Highlight blocks in loaded containers in case we don't scrub far enough with MoveToTimeInBeats to load them @@ -193,7 +193,7 @@ public void NextBlock(int offset = 1) index += errors.all.Count; } - float? time = errors.all[index]?.note.Time; + float? time = errors.all[index]?.note.JsonTime; if (time != null) { atsc.MoveToTimeInBeats(time ?? 0); diff --git a/Checks/Check.cs b/Checks/Check.cs index 0bc338a..c7c2efc 100644 --- a/Checks/Check.cs +++ b/Checks/Check.cs @@ -20,16 +20,16 @@ protected Check() : this("") } - protected virtual CheckResult PerformCheck(List notes, List bombs, List arcs, List chains, List events, List walls, List customEvents, List bpmChanges) + protected virtual CheckResult PerformCheck(List notes, List bombs, List arcs, List chains, List events, List walls, List customEvents, List BpmEvents) { throw new ArgumentException("Wrong number of parameters"); } - public virtual CheckResult PerformCheck(List notes, List bombs, List arcs, List chains, List events, List walls, List customEvents, List bpmChanges, params KeyValuePair[] vals) + public virtual CheckResult PerformCheck(List notes, List bombs, List arcs, List chains, List events, List walls, List customEvents, List BpmEvents, params KeyValuePair[] vals) { if (vals.Length == 0 && Params.Count == 0) { - return PerformCheck(notes, bombs, arcs, chains, events, walls, customEvents, bpmChanges); + return PerformCheck(notes, bombs, arcs, chains, events, walls, customEvents, BpmEvents); } throw new ArgumentException("Wrong number of parameters"); } diff --git a/Checks/CheckResult.cs b/Checks/CheckResult.cs index 371399c..bfd20cc 100644 --- a/Checks/CheckResult.cs +++ b/Checks/CheckResult.cs @@ -48,7 +48,7 @@ public void AddWarning(BaseNote note, string reason = "") public CheckResult Commit() { - all = errors.Union(warnings).OrderBy(it => it.note.Time).ToList(); + all = errors.Union(warnings).OrderBy(it => it.note.JsonTime).ToList(); return this; } } diff --git a/Checks/ExternalJS.cs b/Checks/ExternalJS.cs index 707a504..9dcad4e 100644 --- a/Checks/ExternalJS.cs +++ b/Checks/ExternalJS.cs @@ -173,7 +173,7 @@ private BaseNote FromDynamic(dynamic note, List notes) int _type = Convert.ChangeType(note._type, typeof(int)); int _cutDirection = Convert.ChangeType(note._cutDirection, typeof(int)); - return notes.Find(it => Mathf.Approximately(_time, it.Time) && + return notes.Find(it => Mathf.Approximately(_time, it.JsonTime) && _lineIndex == it.PosX && _lineLayer == it.PosY && _type == it.Type && @@ -182,7 +182,7 @@ private BaseNote FromDynamic(dynamic note, List notes) public override CheckResult PerformCheck(List notes, List bombs, List arcs, List chains, List events, List walls, List customEvents, - List bpmChanges, params KeyValuePair[] vals) + List BpmEvents, params KeyValuePair[] vals) { result.Clear(); @@ -192,8 +192,8 @@ public override CheckResult PerformCheck(List notes, List bo var collection = BeatmapObjectContainerCollection.GetCollectionForType(ObjectType.BpmChange); - var lastBPMChange = collection.FindLastBpm(atsc.CurrentBeat); - var currentBPM = lastBPMChange?.Bpm ?? atsc.Song.BeatsPerMinute; + var lastBpmEvent = collection.FindLastBpm(atsc.CurrentBeat); + var currentBPM = lastBpmEvent?.Bpm ?? atsc.Song.BeatsPerMinute; var originalNotes = notes.Select(it => new Note(engine, it)).ToArray(); var originalBombs = bombs.Select(it => new BombNote(engine, it)).ToArray(); @@ -202,7 +202,7 @@ public override CheckResult PerformCheck(List notes, List bo var originalWalls = walls.Select(it => new Wall(engine, it)).ToArray(); var originalEvents = events.Select(it => new Event(engine, it)).ToArray(); var originalCustomEvents = customEvents.Select(it => new CustomEvent(engine, it)).ToArray(); - var originalBpmChanges = bpmChanges.Select(it => new BpmChange(engine, it)).ToArray(); + var originalBpmEvents = BpmEvents.Select(it => new BpmEvent(engine, it)).ToArray(); try { @@ -216,7 +216,7 @@ public override CheckResult PerformCheck(List notes, List bo .SetValue("walls", originalWalls) .SetValue("events", originalEvents) .SetValue("customEvents", originalCustomEvents) - .SetValue("bpmChanges", originalBpmChanges) + .SetValue("BpmEvents", originalBpmEvents) .SetValue("data", new MapData( currentBPM, atsc.Song.BeatsPerMinute, @@ -254,7 +254,7 @@ public override CheckResult PerformCheck(List notes, List bo TimeLog("Run"); tmp.Execute("global.params = args;" + - "var output = module.exports.run ? module.exports.run(cursor, notes, events, walls, {}, global, data, customEvents, bpmChanges, bombs, arcs, chains) : module.exports.performCheck({notes: notes}" + + "var output = module.exports.run ? module.exports.run(cursor, notes, events, walls, {}, global, data, customEvents, BpmEvents, bombs, arcs, chains) : module.exports.performCheck({notes: notes}" + (vals.Length > 0 ? ", " + string.Join(",", vals.Select(paramValue => @@ -278,7 +278,7 @@ public override CheckResult PerformCheck(List notes, List bo "if (output && output.chains) { chains = output.chains; };" + "if (output && output.events) { events = output.events; };" + "if (output && output.customEvents) { customEvents = output.customEvents; };" + - "if (output && output.bpmChanges) { bpmChanges = output.bpmChanges; };" + + "if (output && output.BpmEvents) { BpmEvents = output.BpmEvents; };" + "if (output && output.walls) { walls = output.walls; };"); } catch (JavaScriptException jse) @@ -304,8 +304,8 @@ public override CheckResult PerformCheck(List notes, List bo i => new Event(engine, i), ObjectType.Event)); actions.AddRange(Reconcile(originalCustomEvents, engine.GetValue("customEvents").AsArray(), customEvents, i => new CustomEvent(engine, i), ObjectType.CustomEvent)); - actions.AddRange(Reconcile(originalBpmChanges, engine.GetValue("bpmChanges").AsArray(), bpmChanges, - i => new BpmChange(engine, i), ObjectType.BpmChange)); + actions.AddRange(Reconcile(originalBpmEvents, engine.GetValue("BpmEvents").AsArray(), BpmEvents, + i => new BpmEvent(engine, i), ObjectType.BpmChange)); SelectionController.SelectionChangedEvent?.Invoke(); diff --git a/Checks/StackedNotes.cs b/Checks/StackedNotes.cs index 4bf24af..29d31bb 100644 --- a/Checks/StackedNotes.cs +++ b/Checks/StackedNotes.cs @@ -9,7 +9,7 @@ public StackedNotes() : base("Stacked Notes") { } - protected override CheckResult PerformCheck(List notes, List bombs, List arcs, List chains, List events, List walls, List customEvents, List bpmChanges) + protected override CheckResult PerformCheck(List notes, List bombs, List arcs, List chains, List events, List walls, List customEvents, List bpmEvents) { result.Clear(); @@ -20,7 +20,7 @@ protected override CheckResult PerformCheck(List notes, List var noteA = notes[i]; var noteB = notes[j]; - if (noteB.Time - noteA.Time > 0.1) + if (noteB.JsonTime - noteA.JsonTime > 0.1) { break; } diff --git a/Checks/VisionBlocks.cs b/Checks/VisionBlocks.cs index 4ee84c3..8c41907 100644 --- a/Checks/VisionBlocks.cs +++ b/Checks/VisionBlocks.cs @@ -13,7 +13,7 @@ public VisionBlocks() : base("Vision Blocks") public override CheckResult PerformCheck(List notes, List bombs, List arcs, List chains, List events, List walls, List customEvents, - List bpmChanges, params KeyValuePair[] vals) + List BpmEvents, params KeyValuePair[] vals) { if (vals.Length > 1) { @@ -38,9 +38,9 @@ public CheckResult PerformCheck(List notes, float minTime, float maxTi } foreach (var note in notes) { - if (note.Time - visionBlockLeft <= maxTime) + if (note.JsonTime - visionBlockLeft <= maxTime) { - if (note.PosX < 2 && note.Time - visionBlockLeft > minTime) + if (note.PosX < 2 && note.JsonTime - visionBlockLeft > minTime) { result.Add(visionBlockLeftNote, "Blocks vision of upcoming note on the left"); result.AddWarning(note, "Is blocked"); @@ -53,15 +53,15 @@ public CheckResult PerformCheck(List notes, float minTime, float maxTi } } - if (note.Time - visionBlockRight <= maxTime) + if (note.JsonTime - visionBlockRight <= maxTime) { - if (note.PosX > 1 && note.Time - visionBlockRight > minTime) + if (note.PosX > 1 && note.JsonTime - visionBlockRight > minTime) { result.Add(visionBlockRightNote, "Blocks vision of upcoming note on the right"); result.AddWarning(note, "Is blocked"); } - if (note.PosY == 1 && note.PosX == 2 && note.Time - visionBlockLeft <= maxTime) + if (note.PosY == 1 && note.PosX == 2 && note.JsonTime - visionBlockLeft <= maxTime) { result.Add(visionBlockRightNote, "Blocks vision of upcoming note on the right"); result.AddWarning(note, "Is blocked"); @@ -72,12 +72,12 @@ public CheckResult PerformCheck(List notes, float minTime, float maxTi { if (note.PosX == 1) { - visionBlockLeft = note.Time; + visionBlockLeft = note.JsonTime; visionBlockLeftNote = note; } else if (note.PosX == 2) { - visionBlockRight = note.Time; + visionBlockRight = note.JsonTime; visionBlockRightNote = note; } } diff --git a/ErrorChecker.csproj b/ErrorChecker.csproj index 548b518..cb4dada 100644 --- a/ErrorChecker.csproj +++ b/ErrorChecker.csproj @@ -259,7 +259,7 @@ - + diff --git a/Wrappers/Beatmap/Arc.cs b/Wrappers/Beatmap/Arc.cs index e6de87c..0bd7465 100644 --- a/Wrappers/Beatmap/Arc.cs +++ b/Wrappers/Beatmap/Arc.cs @@ -35,11 +35,11 @@ public Arc(Engine engine, ObjectInstance o) : base(engine, BeatmapFactory.Arc( public float b { - get => wrapped.Time; + get => wrapped.JsonTime; set { DeleteObject(); - wrapped.Time = value; + wrapped.JsonTime = value; } } @@ -95,11 +95,11 @@ public float mu public float tb { - get => wrapped.TailTime; + get => wrapped.TailJsonTime; set { DeleteObject(); - wrapped.TailTime = value; + wrapped.TailJsonTime = value; } } diff --git a/Wrappers/Beatmap/BombNote.cs b/Wrappers/Beatmap/BombNote.cs index 8576c8a..7ed33c6 100644 --- a/Wrappers/Beatmap/BombNote.cs +++ b/Wrappers/Beatmap/BombNote.cs @@ -25,11 +25,11 @@ public BombNote(Engine engine, ObjectInstance o) : base(engine, BeatmapFactory.B public float b { - get => wrapped.Time; + get => wrapped.JsonTime; set { DeleteObject(); - wrapped.Time = value; + wrapped.JsonTime = value; } } diff --git a/Wrappers/Beatmap/BpmChange.cs b/Wrappers/Beatmap/BpmEvent.cs similarity index 50% rename from Wrappers/Beatmap/BpmChange.cs rename to Wrappers/Beatmap/BpmEvent.cs index ff4a8a0..4257bc8 100644 --- a/Wrappers/Beatmap/BpmChange.cs +++ b/Wrappers/Beatmap/BpmEvent.cs @@ -1,75 +1,53 @@ -using Beatmap.Base.Customs; +using Beatmap.Base; using Beatmap.Enums; using Beatmap.Helper; using Jint; using Jint.Native.Object; -internal class BpmChange : Wrapper +internal class BpmEvent : Wrapper { - public BpmChange(Engine engine, BaseBpmChange bpmChange) : base(engine, bpmChange) + public BpmEvent(Engine engine, BaseBpmEvent bpmEvent) : base(engine, bpmEvent) { spawned = true; } - public BpmChange(Engine engine, ObjectInstance o) : base(engine, BeatmapFactory.BpmChange( + public BpmEvent(Engine engine, ObjectInstance o) : base(engine, BeatmapFactory.BpmEvent( (float)GetJsValue(o, new[] { "b", "_time" }), (float)GetJsValue(o, new[] { "m", "_BPM" }) ), false, GetJsBool(o, "selected")) { spawned = false; - wrapped.BeatsPerBar = (float)(GetJsValue(o, new[] { "p", "_beatsPerBar" }) ?? 4f); - wrapped.MetronomeOffset = (float)(GetJsValue(o, new[] { "o", "_metronomeOffset" }) ?? 4f); DeleteObject(); } public float _time { - get => wrapped.Time; + get => wrapped.JsonTime; set { DeleteObject(); - wrapped.Time = value; + wrapped.JsonTime = value; } } public float _BPM { - get => wrapped.Bpm; - set - { - DeleteObject(); - wrapped.Bpm = value; - } - } - - public float _beatsPerBar - { - get => wrapped.BeatsPerBar; - set - { - DeleteObject(); - wrapped.BeatsPerBar = value; - } - } - - public float _metronomeOffset - { - get => wrapped.MetronomeOffset; + get => wrapped.FloatValue; set { DeleteObject(); - wrapped.MetronomeOffset = value; + wrapped.FloatValue = value; } } public float b { - get => wrapped.Time; + get => wrapped.JsonTime; set { DeleteObject(); - wrapped.Time = value; + wrapped.JsonTime = value; } } @@ -83,26 +61,6 @@ public float m } } - public float p - { - get => wrapped.BeatsPerBar; - set - { - DeleteObject(); - wrapped.BeatsPerBar = value; - } - } - - public float o - { - get => wrapped.MetronomeOffset; - set - { - DeleteObject(); - wrapped.MetronomeOffset = value; - } - } - public override bool SpawnObject(BeatmapObjectContainerCollection collection) { if (spawned) return false; diff --git a/Wrappers/Beatmap/Chain.cs b/Wrappers/Beatmap/Chain.cs index b8c4fd3..aabfb1a 100644 --- a/Wrappers/Beatmap/Chain.cs +++ b/Wrappers/Beatmap/Chain.cs @@ -33,11 +33,11 @@ public Chain(Engine engine, ObjectInstance o) : base(engine, BeatmapFactory.Chai public float b { - get => wrapped.Time; + get => wrapped.JsonTime; set { DeleteObject(); - wrapped.Time = value; + wrapped.JsonTime = value; } } @@ -83,11 +83,11 @@ public int d public float tb { - get => wrapped.TailTime; + get => wrapped.TailJsonTime; set { DeleteObject(); - wrapped.TailTime = value; + wrapped.TailJsonTime = value; } } diff --git a/Wrappers/Beatmap/CustomEvent.cs b/Wrappers/Beatmap/CustomEvent.cs index 17739f7..d2ea0eb 100644 --- a/Wrappers/Beatmap/CustomEvent.cs +++ b/Wrappers/Beatmap/CustomEvent.cs @@ -30,11 +30,11 @@ public CustomEvent(Engine engine, ObjectInstance o) : base(engine, BeatmapFactor public float _time { - get => wrapped.Time; + get => wrapped.JsonTime; set { DeleteObject(); - wrapped.Time = value; + wrapped.JsonTime = value; } } @@ -61,11 +61,11 @@ public object _data public float b { - get => wrapped.Time; + get => wrapped.JsonTime; set { DeleteObject(); - wrapped.Time = value; + wrapped.JsonTime = value; } } diff --git a/Wrappers/Beatmap/Event.cs b/Wrappers/Beatmap/Event.cs index 12de765..27dca41 100644 --- a/Wrappers/Beatmap/Event.cs +++ b/Wrappers/Beatmap/Event.cs @@ -26,11 +26,11 @@ public Event(Engine engine, ObjectInstance o) : base(engine, BeatmapFactory.Even public float _time { - get => wrapped.Time; + get => wrapped.JsonTime; set { DeleteObject(); - wrapped.Time = value; + wrapped.JsonTime = value; } } @@ -66,11 +66,11 @@ public float _floatValue public float b { - get => wrapped.Time; + get => wrapped.JsonTime; set { DeleteObject(); - wrapped.Time = value; + wrapped.JsonTime = value; } } diff --git a/Wrappers/Beatmap/Note.cs b/Wrappers/Beatmap/Note.cs index 039ba9f..9a02e94 100644 --- a/Wrappers/Beatmap/Note.cs +++ b/Wrappers/Beatmap/Note.cs @@ -28,11 +28,11 @@ public Note(Engine engine, ObjectInstance o) : base(engine, BeatmapFactory.Note( public float _time { - get => wrapped.Time; + get => wrapped.JsonTime; set { DeleteObject(); - wrapped.Time = value; + wrapped.JsonTime = value; } } @@ -78,11 +78,11 @@ public int _type public float b { - get => wrapped.Time; + get => wrapped.JsonTime; set { DeleteObject(); - wrapped.Time = value; + wrapped.JsonTime = value; } } diff --git a/Wrappers/Beatmap/Wall.cs b/Wrappers/Beatmap/Wall.cs index 516556c..985baf0 100644 --- a/Wrappers/Beatmap/Wall.cs +++ b/Wrappers/Beatmap/Wall.cs @@ -28,11 +28,11 @@ public Wall(Engine engine, ObjectInstance o) : base(engine, BeatmapFactory.Obsta public float _time { - get => wrapped.Time; + get => wrapped.JsonTime; set { DeleteObject(); - wrapped.Time = value; + wrapped.JsonTime = value; } } @@ -78,11 +78,11 @@ public int _width public float b { - get => wrapped.Time; + get => wrapped.JsonTime; set { DeleteObject(); - wrapped.Time = value; + wrapped.JsonTime = value; } } From 6a3dabe1241f47d02b4aa08e33823d76197fbcfb Mon Sep 17 00:00:00 2001 From: Bullet <68104413+XAce1337manX@users.noreply.github.com> Date: Sat, 6 May 2023 15:56:02 +1000 Subject: [PATCH 26/26] Fix jump to next object --- CMJS.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMJS.cs b/CMJS.cs index fde69e1..47f8915 100644 --- a/CMJS.cs +++ b/CMJS.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -193,7 +193,7 @@ public void NextBlock(int offset = 1) index += errors.all.Count; } - float? time = errors.all[index]?.note.JsonTime; + float? time = errors.all[index]?.note.SongBpmTime; if (time != null) { atsc.MoveToTimeInBeats(time ?? 0);