1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2024-12-25 14:46:43 +00:00
Funkin/source/funkin/play/notes/notekind/NoteKindManager.hx

122 lines
3.3 KiB
Haxe
Raw Normal View History

2024-05-31 12:02:28 +00:00
package funkin.play.notes.notekind;
import funkin.modding.events.ScriptEventDispatcher;
import funkin.modding.events.ScriptEvent;
import funkin.ui.debug.charting.util.ChartEditorDropdowns;
2024-06-01 17:47:45 +00:00
import funkin.data.notestyle.NoteStyleRegistry;
import funkin.play.notes.notestyle.NoteStyle;
2024-07-13 01:40:46 +00:00
import funkin.play.notes.notekind.ScriptedNoteKind;
import funkin.play.notes.notekind.NoteKind.NoteKindParam;
2024-05-31 12:02:28 +00:00
2024-05-31 14:55:42 +00:00
class NoteKindManager
2024-05-31 12:02:28 +00:00
{
2024-05-31 14:55:42 +00:00
static var noteKinds:Map<String, NoteKind> = [];
2024-05-31 12:02:28 +00:00
public static function loadScripts():Void
{
2024-05-31 14:55:42 +00:00
var scriptedClassName:Array<String> = ScriptedNoteKind.listScriptClasses();
2024-05-31 12:02:28 +00:00
if (scriptedClassName.length > 0)
{
2024-05-31 15:24:51 +00:00
trace('Instantiating ${scriptedClassName.length} scripted note kind(s)...');
2024-05-31 12:02:28 +00:00
for (scriptedClass in scriptedClassName)
{
try
{
2024-05-31 14:55:42 +00:00
var script:NoteKind = ScriptedNoteKind.init(scriptedClass, "unknown");
2024-05-31 12:02:28 +00:00
trace(' Initialized scripted note kind: ${script.noteKind}');
2024-05-31 14:55:42 +00:00
noteKinds.set(script.noteKind, script);
2024-05-31 12:02:28 +00:00
ChartEditorDropdowns.NOTE_KINDS.set(script.noteKind, script.description);
}
catch (e)
{
trace(' FAILED to instantiate scripted note kind: ${scriptedClass}');
trace(e);
}
}
}
}
2024-06-01 16:25:46 +00:00
/**
* Calls the given event for note kind scripts
* @param event The event
*/
public static function callEvent(event:ScriptEvent):Void
2024-05-31 12:02:28 +00:00
{
2024-06-01 16:25:46 +00:00
// if it is a note script event,
// then only call the event for the specific note kind script
if (Std.isOfType(event, NoteScriptEvent))
2024-05-31 12:02:28 +00:00
{
2024-06-01 16:25:46 +00:00
var noteEvent:NoteScriptEvent = cast(event, NoteScriptEvent);
2024-05-31 12:02:28 +00:00
2024-06-01 17:47:45 +00:00
var noteKind:NoteKind = noteKinds.get(noteEvent.note.kind);
2024-05-31 15:49:25 +00:00
2024-06-01 16:25:46 +00:00
if (noteKind != null)
{
ScriptEventDispatcher.callEvent(noteKind, event);
}
}
else // call the event for all note kind scripts
2024-05-31 15:49:25 +00:00
{
2024-06-01 16:25:46 +00:00
for (noteKind in noteKinds.iterator())
{
ScriptEventDispatcher.callEvent(noteKind, event);
}
2024-05-31 15:49:25 +00:00
}
}
2024-06-01 17:47:45 +00:00
/**
* Retrieve the note style from the given note kind
* @param noteKind note kind name
2024-06-24 19:45:58 +00:00
* @param suffix Used for song note styles
2024-06-01 17:47:45 +00:00
* @return NoteStyle
*/
2024-06-24 19:45:58 +00:00
public static function getNoteStyle(noteKind:String, ?suffix:String):Null<NoteStyle>
2024-06-01 17:47:45 +00:00
{
2024-06-24 19:45:58 +00:00
var noteStyleId:Null<String> = getNoteStyleId(noteKind, suffix);
2024-06-11 21:45:08 +00:00
if (noteStyleId == null)
{
return null;
}
2024-06-01 17:47:45 +00:00
return NoteStyleRegistry.instance.fetchEntry(noteStyleId);
}
/**
* Retrieve the note style id from the given note kind
2024-06-24 19:45:58 +00:00
* @param noteKind Note kind name
* @param suffix Used for song note styles
* @return Null<String>
*/
2024-06-24 19:45:58 +00:00
public static function getNoteStyleId(noteKind:String, ?suffix:String):Null<String>
{
2024-06-24 19:48:09 +00:00
if (suffix == '')
2024-06-24 19:45:58 +00:00
{
2024-06-24 19:48:09 +00:00
suffix = null;
2024-06-24 19:45:58 +00:00
}
2024-06-11 21:45:08 +00:00
var noteStyleId:Null<String> = noteKinds.get(noteKind)?.noteStyleId;
2024-06-24 19:48:09 +00:00
if (noteStyleId != null && suffix != null)
2024-06-11 21:45:08 +00:00
{
2024-06-24 19:45:58 +00:00
noteStyleId = NoteStyleRegistry.instance.hasEntry('$noteStyleId-$suffix') ? '$noteStyleId-$suffix' : noteStyleId;
2024-06-11 21:45:08 +00:00
}
return noteStyleId;
}
/**
* Retrive custom params of the given note kind
* @param noteKind Name of the note kind
* @return Array<NoteKindParam>
*/
public static function getParams(noteKind:Null<String>):Array<NoteKindParam>
{
if (noteKind == null)
{
return [];
}
return noteKinds.get(noteKind)?.params ?? [];
}
2024-05-31 12:02:28 +00:00
}