From c8d019da2fdcc22627dbfb78c587a5374273f6b6 Mon Sep 17 00:00:00 2001 From: lemz Date: Sat, 22 Jun 2024 00:20:58 +0200 Subject: [PATCH] Update NoteKind.hx --- source/funkin/play/notes/notekind/NoteKind.hx | 38 ++++++++++++++++--- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/source/funkin/play/notes/notekind/NoteKind.hx b/source/funkin/play/notes/notekind/NoteKind.hx index 6d7ddcd1b..3aa02088b 100644 --- a/source/funkin/play/notes/notekind/NoteKind.hx +++ b/source/funkin/play/notes/notekind/NoteKind.hx @@ -2,6 +2,7 @@ package funkin.play.notes.notekind; import funkin.modding.IScriptedClass.INoteScriptedClass; import funkin.modding.events.ScriptEvent; +import flixel.math.FlxMath; /** * Class for note scripts @@ -42,24 +43,49 @@ class NoteKind implements INoteScriptedClass } /** - * Retrieve the param with the given name + * Retrieve the value of the param with the given name * If there exists no param with the given name then `null` is returned * @param name Name of the param - * @return Null + * @return Null */ - public function getParam(name:String):Null + public function getParam(name:String):Null { for (param in params) { if (param.name == name) { - return param; + return param.data.value; } } return null; } + /** + * Set the value of the param with the given name + * @param name Name of the param + * @param value New value + */ + public function setParam(name:String, value:Dynamic):Void + { + for (param in params) + { + if (param.name == name) + { + if (param.type == NoteKindParamType.RANGED_INT || param.type == NoteKindParamType.RANGED_FLOAT) + { + param.data.value = FlxMath.bound(value, param.data.min, param.data.max); + } + else + { + param.data.value = value; + } + + break; + } + } + } + /** * Retrieve all notes of this kind * @return Array @@ -91,7 +117,7 @@ class NoteKind implements INoteScriptedClass * Abstract for setting the type of the `NoteKindParam` * This was supposed to be an enum but polymod kept being annoying */ -abstract NoteKindParamType(String) +abstract NoteKindParamType(String) to String { public static var STRING:String = "String"; @@ -108,11 +134,13 @@ typedef NoteKindParamData = { /** * Only used for `RangedInt` and `RangedFloat` + * If `min` is null, there is no minimum */ var min:Null; /** * Only used for `RangedInt` and `RangedFloat` + * If `max` is null, there is no maximum */ var max:Null;