From 17e177a69554f4d798f5acdd3799687dc9f01a93 Mon Sep 17 00:00:00 2001 From: lunarcleint <88809950+lunarcleint@users.noreply.github.com> Date: Sun, 20 Aug 2023 15:28:00 -0700 Subject: [PATCH] Note types use strings instead of ints --- source/funkin/backend/chart/BaseGameParser.hx | 16 ++--- source/funkin/backend/chart/Chart.hx | 65 ++++++++++--------- source/funkin/backend/chart/ChartData.hx | 5 +- .../scripting/events/NoteCreationEvent.hx | 7 +- source/funkin/editors/charter/Charter.hx | 16 ++--- source/funkin/editors/charter/CharterNote.hx | 4 +- source/funkin/game/Note.hx | 13 +--- source/funkin/game/PlayState.hx | 7 +- 8 files changed, 60 insertions(+), 73 deletions(-) diff --git a/source/funkin/backend/chart/BaseGameParser.hx b/source/funkin/backend/chart/BaseGameParser.hx index b8d2d6b9..cb900764 100644 --- a/source/funkin/backend/chart/BaseGameParser.hx +++ b/source/funkin/backend/chart/BaseGameParser.hx @@ -65,22 +65,22 @@ class BaseGameParser { var daStrumTime:Float = note[0]; var daNoteData:Int = Std.int(note[1] % 8); - var daNoteType:Int = Std.int(note[1] / 8); var gottaHitNote:Bool = daNoteData >= 4 ? !section.mustHitSection : section.mustHitSection; + var noteTypeStr:String = null; + if (note.length > 2) { - if (note[3] is Int) - daNoteType = Chart.addNoteType(result, data.noteTypes[Std.int(note[3])-1]); - else if (note[3] is String) - daNoteType = Chart.addNoteType(result, note[3]); - } else { - daNoteType = Chart.addNoteType(result, data.noteTypes[daNoteType-1]); + if (note[3] is Int) noteTypeStr = data.noteTypes[Std.int(((note[3])-1) > 0 ? ((note[3])-1) : 0)]; + else if (note[3] is String) noteTypeStr = note[3].trim(); } + if (noteTypeStr == "Default Note" || noteTypeStr == "") + noteTypeStr = null; + result.strumLines[gottaHitNote ? 1 : 0].notes.push({ time: daStrumTime, id: daNoteData % 4, - type: daNoteType, + type: noteTypeStr, sLen: note[2] }); } diff --git a/source/funkin/backend/chart/Chart.hx b/source/funkin/backend/chart/Chart.hx index e8692241..08010536 100644 --- a/source/funkin/backend/chart/Chart.hx +++ b/source/funkin/backend/chart/Chart.hx @@ -78,7 +78,6 @@ class Chart { var chartPath = Paths.chart(songName, difficulty); var base:ChartData = { strumLines: [], - noteTypes: [], events: [], meta: { name: null @@ -108,24 +107,8 @@ class Chart { */ #if REGION if (Reflect.hasField(data, "codenameChart") && Reflect.field(data, "codenameChart") == true) { - // backward compat on events since its caused problems - var eventTypesToString:Map = [ - -1 => "HScript Call", - 0 => "Unknown", - 1 => "Camera Movement", - 2 => "BPM Change", - 3 => "Alt Animation Toggle", - ]; - - for (event in cast(data.events, Array)) { - if (Reflect.hasField(event, "type")) { - if(event.type != null) - event.name = eventTypesToString[event.type]; - Reflect.deleteField(event, "type"); - } - } - - // codename chart + // cne chart + backwardCompatCNEChart(cast data); // remove this when the engine comes out base = data; } else { // base game chart @@ -148,17 +131,15 @@ class Chart { return base; } - public static function addNoteType(chart:ChartData, noteTypeName:String):Int { - switch(noteTypeName.trim()) { - case "Default Note" | null | "": - return 0; - default: - var index = chart.noteTypes.indexOf(noteTypeName); - if (index > -1) - return index+1; - chart.noteTypes.push(noteTypeName); - return chart.noteTypes.length; - } + public static function getChartNoteTypes(chart:ChartData):Array { + var types:Array = [null]; + + for (strL in chart.strumLines) + for (note in strL.notes) + if (note.type != null && !types.contains(note.type)) + types.push(note.type); + + return types; } /** @@ -210,6 +191,30 @@ class Chart { } return sortedData; } + + public static function backwardCompatCNEChart(data:Dynamic) { + // Events + var eventTypesToString:Map = [ + -1 => "HScript Call", + 0 => "Unknown", + 1 => "Camera Movement", + 2 => "BPM Change", + 3 => "Alt Animation Toggle", + ]; + + for (event in cast(data.events, Array)) { + if (Reflect.hasField(event, "type")) { + if(event.type != null) + event.name = eventTypesToString[event.type]; + Reflect.deleteField(event, "type"); + } + } + + // Notes + for (strL in cast(data.strumLines, Array)) + for (note in cast(strL.notes, Array)) + if (note.type is Int) note.type = note.type == 0 ? null : data.noteTypes[note.type]; + } } typedef ChartSaveSettings = { diff --git a/source/funkin/backend/chart/ChartData.hx b/source/funkin/backend/chart/ChartData.hx index c142c2a1..e6b6c73f 100644 --- a/source/funkin/backend/chart/ChartData.hx +++ b/source/funkin/backend/chart/ChartData.hx @@ -9,8 +9,7 @@ typedef ChartData = { public var codenameChart:Bool; public var stage:String; public var scrollSpeed:Float; - public var noteTypes:Array; - + public var ?fromMods:Bool; } @@ -47,7 +46,7 @@ typedef ChartStrumLine = { typedef ChartNote = { var time:Float; // time at which the note will be hit (ms) var id:Int; // strum id of the note - var type:Int; // type (int) of the note + var type:Null; // type of the note (deafult is null) var sLen:Float; // sustain length of the note (ms) } diff --git a/source/funkin/backend/scripting/events/NoteCreationEvent.hx b/source/funkin/backend/scripting/events/NoteCreationEvent.hx index 3f7d1890..b499ee5a 100644 --- a/source/funkin/backend/scripting/events/NoteCreationEvent.hx +++ b/source/funkin/backend/scripting/events/NoteCreationEvent.hx @@ -14,15 +14,10 @@ final class NoteCreationEvent extends CancellableEvent { public var strumID:Int; /** - * Note Type (ex: "My Super Cool Note", or "Mine") + * Note Type (ex: "My Super Cool Note", or "Mine", null as default) */ public var noteType:String; - /** - * ID of the note type. - */ - public var noteTypeID:Int; - /** * ID of the player. */ diff --git a/source/funkin/editors/charter/Charter.hx b/source/funkin/editors/charter/Charter.hx index 20c8c05d..0d539590 100644 --- a/source/funkin/editors/charter/Charter.hx +++ b/source/funkin/editors/charter/Charter.hx @@ -639,7 +639,7 @@ class Charter extends UIState { var id = Math.floor(mousePos.x / 40); if (id >= 0 && id < 4 * gridBackdrop.strumlinesAmount && mousePos.y >= 0) { var note = new CharterNote(); - note.updatePos(FlxG.keys.pressed.SHIFT ? (mousePos.y / 40) : Math.floor(mousePos.y / 40), id, 0, 0); + note.updatePos(FlxG.keys.pressed.SHIFT ? (mousePos.y / 40) : Math.floor(mousePos.y / 40), id, 0, null); notesGroup.add(note); selection = [note]; sortNotes(); @@ -1061,12 +1061,12 @@ class Charter extends UIState { clipboard = [ for (s in selection) if (s is CharterNote) { - var note:CharterNote = cast(s, CharterNote); - CNote(note.step - minStep, note.id, note.susLength, note.type); - } else if (s is CharterEvent) { - var event = cast(s,CharterEvent); - CEvent(event.step - minStep, event.events); - } + var note:CharterNote = cast(s, CharterNote); + CNote(note.step - minStep, note.id, note.susLength, note.type); + } else if (s is CharterEvent) { + var event = cast(s,CharterEvent); + CEvent(event.step - minStep, event.events); + } ]; } function _edit_paste(_) { @@ -1334,7 +1334,7 @@ enum CharterChange { } enum CharterCopyboardObject { - CNote(step:Float, id:Int, susLength:Float, type:Int); + CNote(step:Float, id:Int, susLength:Float, type:String); CEvent(step:Float, events:Array); } diff --git a/source/funkin/editors/charter/CharterNote.hx b/source/funkin/editors/charter/CharterNote.hx index 9a3359f4..6c35d13d 100644 --- a/source/funkin/editors/charter/CharterNote.hx +++ b/source/funkin/editors/charter/CharterNote.hx @@ -54,9 +54,9 @@ class CharterNote extends UISprite implements ICharterSelectable { public var step:Float; public var id:Int; public var susLength:Float; - public var type:Int; + public var type:String; - public function updatePos(step:Float, id:Int, susLength:Float = 0, type:Int = 0) { + public function updatePos(step:Float, id:Int, susLength:Float = 0, type:String = null) { this.step = step; this.id = id; this.susLength = susLength; diff --git a/source/funkin/game/Note.hx b/source/funkin/game/Note.hx index 38afb5c6..d284cf4b 100644 --- a/source/funkin/game/Note.hx +++ b/source/funkin/game/Note.hx @@ -72,23 +72,16 @@ class Note extends FlxSprite public var isSustainNote:Bool = false; public var flipSustain:Bool = true; - public var noteTypeID:Int = 0; - // TO APPLY THOSE ON A SINGLE NOTE public var scrollSpeed:Null = null; public var noteAngle:Null = null; - public var noteType(get, null):String; + public var noteType:Null = null; @:dox(hide) public var __strumCameras:Array = null; @:dox(hide) public var __strum:Strum = null; @:dox(hide) public var __noteAngle:Float = 0; - private function get_noteType() { - if (PlayState.instance == null) return null; - return PlayState.instance.getNoteType(noteTypeID); - } - public static var swagWidth:Float = 160 * 0.7; private static var __customNoteTypeExists:Map = []; @@ -111,9 +104,9 @@ class Note extends FlxSprite this.prevNote = prev; else this.prevNote = strumLine.notes.members.last(); - this.noteTypeID = noteData.type.getDefault(0); this.isSustainNote = sustain; this.sustainLength = sustainLength; + this.noteType = noteData.type; this.strumLine = strumLine; x += 50; @@ -124,7 +117,7 @@ class Note extends FlxSprite this.noteData = noteData.id.getDefault(0); var customType = Paths.image('game/notes/${this.noteType}'); - var event = EventManager.get(NoteCreationEvent).recycle(this, strumID, this.noteType, noteTypeID, PlayState.instance.strumLines.members.indexOf(strumLine), mustPress, + var event = EventManager.get(NoteCreationEvent).recycle(this, strumID, this.noteType, PlayState.instance.strumLines.members.indexOf(strumLine), mustPress, (this.noteType != null && customTypePathExists(customType)) ? 'game/notes/${this.noteType}' : 'game/notes/default', 0.7, animSuffix); if (PlayState.instance != null) diff --git a/source/funkin/game/PlayState.hx b/source/funkin/game/PlayState.hx index 18d3f193..5a28abe3 100644 --- a/source/funkin/game/PlayState.hx +++ b/source/funkin/game/PlayState.hx @@ -593,7 +593,7 @@ class PlayState extends MusicBeatState generateSong(SONG); - for(noteType in SONG.noteTypes) { + for(noteType in Chart.getChartNoteTypes(SONG)) { var scriptPath = Paths.script('data/notes/${noteType}'); if (Assets.exists(scriptPath) && !scripts.contains(scriptPath)) { var script = Script.create(scriptPath); @@ -1414,11 +1414,6 @@ class PlayState extends MusicBeatState strumLine.deleteNote(note); } - @:dox(hide) - public function getNoteType(id:Int):String { - return SONG.noteTypes[id-1]; - } - /** * Hits a note * @param note Note to hit.