1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2025-01-26 06:37:23 +00:00

add note kind scripts

This commit is contained in:
lemz 2024-05-31 14:02:28 +02:00 committed by EliteMasterEric
parent 50b587e3b8
commit a7482410b9
6 changed files with 111 additions and 2 deletions

View file

@ -27,6 +27,7 @@ import funkin.data.dialogue.speaker.SpeakerRegistry;
import funkin.data.freeplay.album.AlbumRegistry;
import funkin.data.song.SongRegistry;
import funkin.play.character.CharacterData.CharacterDataParser;
import funkin.play.notes.notekind.NoteKindScriptManager;
import funkin.modding.module.ModuleHandler;
import funkin.ui.title.TitleState;
import funkin.util.CLIUtil;
@ -176,6 +177,8 @@ class InitState extends FlxState
// Move it to use a BaseRegistry.
CharacterDataParser.loadCharacterCache();
NoteKindScriptManager.loadScripts();
ModuleHandler.buildModuleCallbacks();
ModuleHandler.loadModuleCache();
ModuleHandler.callOnCreate();

View file

@ -49,6 +49,7 @@ import funkin.play.notes.NoteSprite;
import funkin.play.notes.notestyle.NoteStyle;
import funkin.play.notes.Strumline;
import funkin.play.notes.SustainTrail;
import funkin.play.notes.notekind.NoteKindScriptManager;
import funkin.play.scoring.Scoring;
import funkin.play.song.Song;
import funkin.play.stage.Stage;
@ -1177,7 +1178,12 @@ class PlayState extends MusicBeatSubState
// Dispatch event to conversation script.
ScriptEventDispatcher.callEvent(currentConversation, event);
// TODO: Dispatch event to note scripts
// Dispatch event to note script
if (Std.isOfType(event, NoteScriptEvent))
{
var noteEvent:NoteScriptEvent = cast(event, NoteScriptEvent);
NoteKindScriptManager.callEvent(noteEvent.note.noteData.kind, noteEvent);
}
}
/**

View file

@ -0,0 +1,45 @@
package funkin.play.notes.notekind;
import funkin.modding.IScriptedClass.INoteScriptedClass;
import funkin.modding.events.ScriptEvent;
/**
* Class for note scripts
*/
class NoteKindScript implements INoteScriptedClass
{
/**
* the name of the note kind
*/
public var noteKind:String;
/**
* description used in chart editor
*/
public var description:String = "";
public function new(noteKind:String, description:String = "")
{
this.noteKind = noteKind;
this.description = description;
}
public function toString():String
{
return noteKind;
}
public function onScriptEvent(event:ScriptEvent):Void {}
public function onCreate(event:ScriptEvent):Void {}
public function onDestroy(event:ScriptEvent):Void {}
public function onUpdate(event:UpdateScriptEvent):Void {}
public function onNoteIncoming(event:NoteScriptEvent):Void {}
public function onNoteHit(event:HitNoteScriptEvent):Void {}
public function onNoteMiss(event:NoteScriptEvent):Void {}
}

View file

@ -0,0 +1,46 @@
package funkin.play.notes.notekind;
import funkin.modding.events.ScriptEventDispatcher;
import funkin.modding.events.ScriptEvent;
import funkin.ui.debug.charting.util.ChartEditorDropdowns;
class NoteKindScriptManager
{
static var noteKindScripts:Map<String, NoteKindScript> = [];
public static function loadScripts():Void
{
var scriptedClassName:Array<String> = ScriptedNoteKindScript.listScriptClasses();
if (scriptedClassName.length > 0)
{
trace('Instantiating ${scriptedClassName.length} scripted note kind...');
for (scriptedClass in scriptedClassName)
{
try
{
var script:NoteKindScript = ScriptedNoteKindScript.init(scriptedClass, "unknown");
trace(' Initialized scripted note kind: ${script.noteKind}');
noteKindScripts.set(script.noteKind, script);
ChartEditorDropdowns.NOTE_KINDS.set(script.noteKind, script.description);
}
catch (e)
{
trace(' FAILED to instantiate scripted note kind: ${scriptedClass}');
trace(e);
}
}
}
}
public static function callEvent(noteKind:String, event:ScriptEvent):Void
{
var noteKindScript:NoteKindScript = noteKindScripts.get(noteKind);
if (noteKindScript == null)
{
return;
}
ScriptEventDispatcher.callEvent(noteKindScript, event);
}
}

View file

@ -0,0 +1,9 @@
package funkin.play.notes.notekind;
/**
* A script that can be tied to a NoteKindScript.
* Create a scripted class that extends NoteKindScript,
* then call `super('noteKind')` in the constructor to use this.
*/
@:hscriptClass
class ScriptedNoteKindScript extends NoteKindScript implements polymod.hscript.HScriptedClass {}

View file

@ -146,7 +146,7 @@ class ChartEditorDropdowns
return returnValue;
}
static final NOTE_KINDS:Map<String, String> = [
public static final NOTE_KINDS:Map<String, String> = [
// Base
"" => "Default",
"~CUSTOM~" => "Custom",