From 23a27dd36ed171e974e2e04fc1f32586b37a994d Mon Sep 17 00:00:00 2001 From: EliteMasterEric Date: Thu, 2 May 2024 04:11:27 -0400 Subject: [PATCH] Implement onSongLoaded script event (with access to notes and events) --- source/funkin/modding/events/ScriptEvent.hx | 12 +++++++++++- source/funkin/play/PlayState.hx | 12 +++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/source/funkin/modding/events/ScriptEvent.hx b/source/funkin/modding/events/ScriptEvent.hx index 0d424a281..8d625290d 100644 --- a/source/funkin/modding/events/ScriptEvent.hx +++ b/source/funkin/modding/events/ScriptEvent.hx @@ -1,6 +1,7 @@ package funkin.modding.events; import funkin.data.song.SongData.SongNoteData; +import funkin.data.song.SongData.SongEventData; import flixel.FlxState; import flixel.FlxSubState; import funkin.play.notes.NoteSprite; @@ -358,6 +359,8 @@ class SongLoadScriptEvent extends ScriptEvent */ public var notes(default, set):Array; + public var events(default, set):Array; + public var id(default, null):String; public var difficulty(default, null):String; @@ -368,12 +371,19 @@ class SongLoadScriptEvent extends ScriptEvent return this.notes; } - public function new(id:String, difficulty:String, notes:Array):Void + function set_events(events:Array):Array + { + this.events = events; + return this.events; + } + + public function new(id:String, difficulty:String, notes:Array, events:Array):Void { super(SONG_LOADED, false); this.id = id; this.difficulty = difficulty; this.notes = notes; + this.events = events; } public override function toString():String diff --git a/source/funkin/play/PlayState.hx b/source/funkin/play/PlayState.hx index 58767d267..a61612032 100644 --- a/source/funkin/play/PlayState.hx +++ b/source/funkin/play/PlayState.hx @@ -1831,15 +1831,21 @@ class PlayState extends MusicBeatSubState Highscore.tallies.combo = 0; Highscore.tallies = new Tallies(); - // Reset song events. - songEvents = currentChart.getEvents(); + var event:SongLoadScriptEvent = new SongLoadScriptEvent(currentChart.song.id, currentChart.difficulty, currentChart.notes.copy(), currentChart.getEvents()); + + dispatchEvent(event); + + var builtNoteData = event.notes; + var builtEventData = event.events; + + songEvents = builtEventData; SongEventRegistry.resetEvents(songEvents); // Reset the notes on each strumline. var playerNoteData:Array = []; var opponentNoteData:Array = []; - for (songNote in currentChart.notes) + for (songNote in builtNoteData) { var strumTime:Float = songNote.time; if (strumTime < startTime) continue; // Skip notes that are before the start time.