Funkin/source/funkin/play/notes/notekind/NoteKind.hx

153 lines
3.3 KiB
Haxe
Raw Normal View History

2024-05-31 08:02:28 -04:00
package funkin.play.notes.notekind;
import funkin.modding.IScriptedClass.INoteScriptedClass;
import funkin.modding.events.ScriptEvent;
2024-06-21 18:20:58 -04:00
import flixel.math.FlxMath;
2024-05-31 08:02:28 -04:00
/**
* Class for note scripts
*/
2024-05-31 10:55:42 -04:00
class NoteKind implements INoteScriptedClass
2024-05-31 08:02:28 -04:00
{
/**
2024-06-01 13:47:45 -04:00
* The name of the note kind
2024-05-31 08:02:28 -04:00
*/
public var noteKind:String;
/**
2024-06-01 13:47:45 -04:00
* Description used in chart editor
2024-05-31 08:02:28 -04:00
*/
2024-06-01 13:47:45 -04:00
public var description:String;
2024-05-31 08:02:28 -04:00
2024-06-01 13:47:45 -04:00
/**
* Custom note style
*/
2024-06-11 17:45:08 -04:00
public var noteStyleId:Null<String>;
2024-06-01 13:47:45 -04:00
/**
* Custom parameters for the chart editor
*/
public var params:Array<NoteKindParam>;
public function new(noteKind:String, description:String = "", ?noteStyleId:String, ?params:Array<NoteKindParam>)
2024-05-31 08:02:28 -04:00
{
this.noteKind = noteKind;
this.description = description;
2024-06-01 13:47:45 -04:00
this.noteStyleId = noteStyleId;
this.params = params ?? [];
2024-05-31 08:02:28 -04:00
}
public function toString():String
{
return noteKind;
}
/**
2024-06-21 18:20:58 -04:00
* 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
2024-06-21 18:20:58 -04:00
* @return Null<Dynamic>
*/
2024-06-21 18:20:58 -04:00
public function getParam(name:String):Null<Dynamic>
{
for (param in params)
{
if (param.name == name)
{
2024-06-21 18:20:58 -04:00
return param.data.value;
}
}
return null;
}
2024-06-21 18:20:58 -04:00
/**
* 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)
{
2024-06-22 04:44:12 -04:00
switch (param.type)
2024-06-21 18:20:58 -04:00
{
2024-06-22 04:44:12 -04:00
case NoteKindParamType.INT | NoteKindParamType.FLOAT:
param.data.value = FlxMath.bound(value, param.data.min, param.data.max);
default:
param.data.value = value;
2024-06-21 18:20:58 -04:00
}
break;
}
}
}
2024-05-31 14:28:56 -04:00
/**
* Retrieve all notes of this kind
* @return Array<NoteSprite>
*/
function getNotes():Array<NoteSprite>
{
var allNotes:Array<NoteSprite> = PlayState.instance.playerStrumline.notes.members.concat(PlayState.instance.opponentStrumline.notes.members);
return allNotes.filter(function(note:NoteSprite) {
return note != null && note.noteData.kind == this.noteKind;
});
}
2024-05-31 08:02:28 -04:00
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 {}
}
/**
* Abstract for setting the type of the `NoteKindParam`
* This was supposed to be an enum but polymod kept being annoying
*/
2024-06-21 18:20:58 -04:00
abstract NoteKindParamType(String) to String
{
public static var STRING:String = "String";
public static var INT:String = "Int";
public static var FLOAT:String = "Float";
}
typedef NoteKindParamData =
{
/**
2024-06-21 18:20:58 -04:00
* If `min` is null, there is no minimum
*/
var min:Null<Float>;
/**
2024-06-21 18:20:58 -04:00
* If `max` is null, there is no maximum
*/
var max:Null<Float>;
var value:Dynamic;
}
/**
* Typedef for creating custom parameters in the chart editor
*/
typedef NoteKindParam =
{
var name:String;
var description:String;
var type:NoteKindParamType;
var data:NoteKindParamData;
}