Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
624def8
Updated packages.
KivalEvan Sep 24, 2022
72ae811
Add optional float value to event.
KivalEvan Sep 24, 2022
d79a33e
Add getter/setter for float value.
KivalEvan Sep 24, 2022
f68a59b
Add placeholder v3 beatmap object.
KivalEvan Sep 24, 2022
70b81a6
Fix typo.
KivalEvan Sep 24, 2022
521db61
Add more map data.
KivalEvan Sep 24, 2022
e25369f
Somewhat working v3 map script.
KivalEvan Sep 24, 2022
e615c29
Add v3 and v2 compatibility.
KivalEvan Sep 24, 2022
1370970
Fixed v3 wall, arc, and chain not getting custom data.
KivalEvan Sep 24, 2022
40aaa93
Update for experimental v3 build
KivalEvan Oct 14, 2022
6845c4e
Refresh custom data on modify
KivalEvan Jan 8, 2023
930ef64
Update Jint
KivalEvan Jan 8, 2023
d81286e
Utilise beatmap factory
KivalEvan Jan 28, 2023
73599ee
Add LiteNetLib to reference
KivalEvan Jan 28, 2023
ba8aff6
Fix built in script and remove redundant method
KivalEvan Jan 28, 2023
70a7d71
Change params to JS object for string indexing
KivalEvan Jan 28, 2023
1fb45b4
Clean-up wrappers
KivalEvan Jan 29, 2023
8980660
Do C# magic
KivalEvan Jan 29, 2023
b7f0edf
oops, invalid params string join
KivalEvan Jan 29, 2023
3bb41f1
A small bit of optimisation
KivalEvan Jan 29, 2023
3ea8930
Update README.md
KivalEvan Jan 30, 2023
6e4a643
Fixed arc and chain arguments
KivalEvan Feb 9, 2023
96402de
Fix type being required for v3 wall
KivalEvan Mar 5, 2023
57d65ba
Fix exist check
KivalEvan Mar 7, 2023
fb8552c
CM0.8.580 BPM update
KivalEvan May 5, 2023
6a3dabe
Fix jump to next object
XAce1337manX May 6, 2023
df41c4b
Merge pull request #1 from XAce1337manX/master
KivalEvan May 6, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 56 additions & 27 deletions CMJS.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
using System;
using System;
using System.Collections.Generic;
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;
Expand All @@ -11,11 +19,13 @@
[Plugin("CM JS")]
public class CMJS
{
private NotesContainer notesContainer;
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 BpmEventsContainer;
private List<Check> checks = new List<Check>()
{
new VisionBlocks(),
Expand Down Expand Up @@ -56,14 +66,16 @@ private void SceneLoaded(Scene arg0, LoadSceneMode arg1)
{
if (arg0.buildIndex == 3) // Mapper scene
{
notesContainer = UnityEngine.Object.FindObjectOfType<NotesContainer>();
wallsContainer = UnityEngine.Object.FindObjectOfType<ObstaclesContainer>();
eventsContainer = UnityEngine.Object.FindObjectOfType<EventsContainer>();
customEventsContainer = UnityEngine.Object.FindObjectOfType<CustomEventsContainer>();
bpmChangesContainer = UnityEngine.Object.FindObjectOfType<BPMChangesContainer>();
notesContainer = UnityEngine.Object.FindObjectOfType<NoteGridContainer>();
arcsContainer = UnityEngine.Object.FindObjectOfType<ArcGridContainer>();
chainsContainer = UnityEngine.Object.FindObjectOfType<ChainGridContainer>();
wallsContainer = UnityEngine.Object.FindObjectOfType<ObstacleGridContainer>();
eventsContainer = UnityEngine.Object.FindObjectOfType<EventGridContainer>();
customEventsContainer = UnityEngine.Object.FindObjectOfType<CustomEventGridContainer>();
BpmEventsContainer = UnityEngine.Object.FindObjectOfType<BPMChangeGridContainer>();
var mapEditorUI = UnityEngine.Object.FindObjectOfType<MapEditorUI>();

atsc = BeatmapObjectContainerCollection.GetCollectionForType(BeatmapObject.ObjectType.Note).AudioTimeSyncController;
atsc = BeatmapObjectContainerCollection.GetCollectionForType(ObjectType.Note).AudioTimeSyncController;

// Add button to UI
ui.AddButton(mapEditorUI);
Expand All @@ -72,18 +84,14 @@ private void SceneLoaded(Scene arg0, LoadSceneMode arg1)

public void CheckErrors(Check check)
{
var allNotes = notesContainer.LoadedObjects.Cast<BeatmapNote>().OrderBy(it => it.Time).ToList();
var allWalls = wallsContainer.LoadedObjects.Cast<BeatmapObstacle>().OrderBy(it => it.Time).ToList();
var allEvents = eventsContainer.LoadedObjects.Cast<MapEvent>().OrderBy(it => it.Time).ToList();
var allCustomEvents = customEventsContainer.LoadedObjects.Cast<BeatmapCustomEvent>().OrderBy(it => it.Time).ToList();
var allBpmChanges = bpmChangesContainer.LoadedObjects.Cast<BeatmapBPMChange>().OrderBy(it => it.Time).ToList();
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);
Expand All @@ -98,29 +106,50 @@ public void CheckErrors(Check check)
switch (it)
{
case UITextInput textInput:
return check.Params[idx].Parse(textInput.InputField.text);
return new KeyValuePair<string, IParamValue>(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<string, IParamValue>(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<string, IParamValue>(check.Params[idx].name, check.Params[idx].Parse(toggle.isOn.ToString()));
default:
return new ParamValue<string>(null); // IDK
return new KeyValuePair<string, IParamValue>(check.Params[idx].name, new ParamValue<string>(null)); // IDK
}
}).ToArray();
errors = check.PerformCheck(allNotes, allEvents, allWalls, allCustomEvents, allBpmChanges, vals).Commit();

if (isV3)
{
// TODO: since containers has multiple different object, check events and notes
var allNotes = notesContainer.LoadedObjects.Where(it => it is V3ColorNote).Cast<BaseNote>().OrderBy(it => it.JsonTime).ToList();
var allBombs = notesContainer.LoadedObjects.Where(it => it is V3BombNote).Cast<BaseNote>().OrderBy(it => it.JsonTime).ToList();
var allArcs = arcsContainer.LoadedObjects.Cast<BaseArc>().OrderBy(it => it.JsonTime).ToList();
var allChains = chainsContainer.LoadedObjects.Cast<BaseChain>().OrderBy(it => it.JsonTime).ToList();
var allWalls = wallsContainer.LoadedObjects.Cast<BaseObstacle>().OrderBy(it => it.JsonTime).ToList();
var allEvents = eventsContainer.LoadedObjects.Cast<BaseEvent>().OrderBy(it => it.JsonTime).ToList();
var allCustomEvents = customEventsContainer.LoadedObjects.Cast<BaseCustomEvent>().OrderBy(it => it.JsonTime).ToList();
var allBpmEvents = BpmEventsContainer.LoadedObjects.Cast<BaseBpmEvent>().OrderBy(it => it.JsonTime).ToList();
errors = check.PerformCheck(allNotes, allBombs, allArcs, allChains, allEvents, allWalls, allCustomEvents, allBpmEvents, vals).Commit();
} else
{
var allNotes = notesContainer.LoadedObjects.Cast<BaseNote>().OrderBy(it => it.JsonTime).ToList();
var allWalls = wallsContainer.LoadedObjects.Cast<BaseObstacle>().OrderBy(it => it.JsonTime).ToList();
var allEvents = eventsContainer.LoadedObjects.Cast<BaseEvent>().OrderBy(it => it.JsonTime).ToList();
var allCustomEvents = customEventsContainer.LoadedObjects.Cast<BaseCustomEvent>().OrderBy(it => it.JsonTime).ToList();
var allBpmEvents = BpmEventsContainer.LoadedObjects.Cast<BaseBpmEvent>().OrderBy(it => it.JsonTime).ToList();
errors = check.PerformCheck(allNotes, new List<BaseNote>(), new List<BaseArc>(), new List<BaseChain>(), allEvents, allWalls, allCustomEvents, allBpmEvents, 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);
}
}

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);
}
Expand Down Expand Up @@ -164,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.SongBpmTime;
if (time != null)
{
atsc.MoveToTimeInBeats(time ?? 0);
Expand All @@ -179,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;

Expand Down
8 changes: 5 additions & 3 deletions Checks/Check.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
using Beatmap.Base;
using Beatmap.Base.Customs;

public abstract class Check
{
Expand All @@ -18,16 +20,16 @@ protected Check() : this("")

}

protected virtual CheckResult PerformCheck(List<BeatmapNote> notes, List<MapEvent> events, List<BeatmapObstacle> walls, List<BeatmapCustomEvent> customEvents, List<BeatmapBPMChange> bpmChanges)
protected virtual CheckResult PerformCheck(List<BaseNote> notes, List<BaseNote> bombs, List<BaseArc> arcs, List<BaseChain> chains, List<BaseEvent> events, List<BaseObstacle> walls, List<BaseCustomEvent> customEvents, List<BaseBpmEvent> BpmEvents)
{
throw new ArgumentException("Wrong number of parameters");
}

public virtual CheckResult PerformCheck(List<BeatmapNote> notes, List<MapEvent> events, List<BeatmapObstacle> walls, List<BeatmapCustomEvent> customEvents, List<BeatmapBPMChange> bpmChanges, params IParamValue[] vals)
public virtual CheckResult PerformCheck(List<BaseNote> notes, List<BaseNote> bombs, List<BaseArc> arcs, List<BaseChain> chains, List<BaseEvent> events, List<BaseObstacle> walls, List<BaseCustomEvent> customEvents, List<BaseBpmEvent> BpmEvents, params KeyValuePair<string, IParamValue>[] vals)
{
if (vals.Length == 0 && Params.Count == 0)
{
return PerformCheck(notes, events, walls, customEvents, bpmChanges);
return PerformCheck(notes, bombs, arcs, chains, events, walls, customEvents, BpmEvents);
}
throw new ArgumentException("Wrong number of parameters");
}
Expand Down
13 changes: 7 additions & 6 deletions Checks/CheckResult.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -30,24 +31,24 @@ 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));
}

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;
}
}
Loading