store params in chart

chart editor still doesnt fully work
This commit is contained in:
lemz 2024-06-22 20:49:30 +02:00 committed by EliteMasterEric
parent 764cdee63d
commit c41d846df5
5 changed files with 111 additions and 12 deletions
source/funkin

View file

@ -951,12 +951,18 @@ class SongNoteDataRaw implements ICloneable<SongNoteDataRaw>
return this.kind = value; return this.kind = value;
} }
public function new(time:Float, data:Int, length:Float = 0, kind:String = '') @:alias("p")
@:default([])
@:optional
public var params:Array<NoteParamData>;
public function new(time:Float, data:Int, length:Float = 0, kind:String = '', ?params:Array<NoteParamData>)
{ {
this.time = time; this.time = time;
this.data = data; this.data = data;
this.length = length; this.length = length;
this.kind = kind; this.kind = kind;
this.params = params ?? [];
} }
/** /**
@ -1053,7 +1059,7 @@ class SongNoteDataRaw implements ICloneable<SongNoteDataRaw>
public function clone():SongNoteDataRaw public function clone():SongNoteDataRaw
{ {
return new SongNoteDataRaw(this.time, this.data, this.length, this.kind); return new SongNoteDataRaw(this.time, this.data, this.length, this.kind, this.params);
} }
public function toString():String public function toString():String
@ -1069,9 +1075,9 @@ class SongNoteDataRaw implements ICloneable<SongNoteDataRaw>
@:forward @:forward
abstract SongNoteData(SongNoteDataRaw) from SongNoteDataRaw to SongNoteDataRaw abstract SongNoteData(SongNoteDataRaw) from SongNoteDataRaw to SongNoteDataRaw
{ {
public function new(time:Float, data:Int, length:Float = 0, kind:String = '') public function new(time:Float, data:Int, length:Float = 0, kind:String = '', ?params:Array<NoteParamData>)
{ {
this = new SongNoteDataRaw(time, data, length, kind); this = new SongNoteDataRaw(time, data, length, kind, params);
} }
public static function buildDirectionName(data:Int, strumlineSize:Int = 4):String public static function buildDirectionName(data:Int, strumlineSize:Int = 4):String
@ -1183,3 +1189,30 @@ abstract SongNoteData(SongNoteDataRaw) from SongNoteDataRaw to SongNoteDataRaw
+ (this.kind != '' ? ' [kind: ${this.kind}])' : ')'); + (this.kind != '' ? ' [kind: ${this.kind}])' : ')');
} }
} }
class NoteParamData implements ICloneable<NoteParamData>
{
@:alias("n")
public var name:String;
@:alias("v")
@:jcustomparse(funkin.data.DataParse.dynamicValue)
@:jcustomwrite(funkin.data.DataWrite.dynamicValue)
public var value:Dynamic;
public function new(name:String, value:Dynamic)
{
this.name = name;
this.value = value;
}
public function clone():NoteParamData
{
return new NoteParamData(this.name, this.value);
}
public function toString():String
{
return 'NoteParamData(${this.name}, ${this.value})';
}
}

View file

@ -1,6 +1,7 @@
package funkin.play.notes; package funkin.play.notes;
import funkin.data.song.SongData.SongNoteData; import funkin.data.song.SongData.SongNoteData;
import funkin.data.song.SongData.NoteParamData;
import funkin.play.notes.notestyle.NoteStyle; import funkin.play.notes.notestyle.NoteStyle;
import flixel.graphics.frames.FlxAtlasFrames; import flixel.graphics.frames.FlxAtlasFrames;
import flixel.FlxSprite; import flixel.FlxSprite;
@ -65,6 +66,22 @@ class NoteSprite extends FunkinSprite
return this.noteData.kind = value; return this.noteData.kind = value;
} }
/**
* An array of custom parameters for this note
*/
public var params(get, set):Array<NoteParamData>;
function get_params():Array<NoteParamData>
{
return this.noteData?.params ?? [];
}
function set_params(value:Array<NoteParamData>):Array<NoteParamData>
{
if (this.noteData == null) return value;
return this.noteData.params = value;
}
/** /**
* The data of the note (i.e. the direction.) * The data of the note (i.e. the direction.)
*/ */
@ -154,6 +171,23 @@ class NoteSprite extends FunkinSprite
this.shader = hsvShader; this.shader = hsvShader;
} }
/**
* Retrieve the value of the param with the given name
* @param name Name of the param
* @return Null<Dynamic>
*/
public function getParam(name:String):Null<Dynamic>
{
for (param in params)
{
if (param.name == name)
{
return param.value;
}
}
return null;
}
#if FLX_DEBUG #if FLX_DEBUG
/** /**
* Call this to override how debug bounding boxes are drawn for this sprite. * Call this to override how debug bounding boxes are drawn for this sprite.

View file

@ -5,6 +5,7 @@ import funkin.modding.events.ScriptEvent;
import funkin.ui.debug.charting.util.ChartEditorDropdowns; import funkin.ui.debug.charting.util.ChartEditorDropdowns;
import funkin.data.notestyle.NoteStyleRegistry; import funkin.data.notestyle.NoteStyleRegistry;
import funkin.play.notes.notestyle.NoteStyle; import funkin.play.notes.notestyle.NoteStyle;
import funkin.play.notes.notekind.NoteKind.NoteKindParam;
class NoteKindManager class NoteKindManager
{ {
@ -100,9 +101,9 @@ class NoteKindManager
/** /**
* Retrive custom params of the given note kind * Retrive custom params of the given note kind
* @param noteKind Name of the note kind * @param noteKind Name of the note kind
* @return Array<NoteKind.NoteKindParam> * @return Array<NoteKindParam>
*/ */
public static function getParams(noteKind:String):Array<NoteKind.NoteKindParam> public static function getParams(noteKind:String):Array<NoteKindParam>
{ {
return noteKinds.get(noteKind)?.params ?? []; return noteKinds.get(noteKind)?.params ?? [];
} }

View file

@ -35,6 +35,7 @@ import funkin.data.song.SongData.SongEventData;
import funkin.data.song.SongData.SongMetadata; import funkin.data.song.SongData.SongMetadata;
import funkin.data.song.SongData.SongNoteData; import funkin.data.song.SongData.SongNoteData;
import funkin.data.song.SongData.SongOffsets; import funkin.data.song.SongData.SongOffsets;
import funkin.data.song.SongData.NoteParamData;
import funkin.data.song.SongDataUtils; import funkin.data.song.SongDataUtils;
import funkin.data.song.SongRegistry; import funkin.data.song.SongRegistry;
import funkin.data.stage.StageData; import funkin.data.stage.StageData;
@ -539,6 +540,11 @@ class ChartEditorState extends UIState // UIState derives from MusicBeatState
*/ */
var noteKindToPlace:Null<String> = null; var noteKindToPlace:Null<String> = null;
/**
* The note params to use for notes being placed in the chart. Defaults to `[]`.
*/
var noteParamsToPlace:Array<NoteParamData> = [];
/** /**
* The event type to use for events being placed in the chart. Defaults to `''`. * The event type to use for events being placed in the chart. Defaults to `''`.
*/ */
@ -2437,7 +2443,7 @@ class ChartEditorState extends UIState // UIState derives from MusicBeatState
gridGhostNote = new ChartEditorNoteSprite(this); gridGhostNote = new ChartEditorNoteSprite(this);
gridGhostNote.alpha = 0.6; gridGhostNote.alpha = 0.6;
gridGhostNote.noteData = new SongNoteData(0, 0, 0, ""); gridGhostNote.noteData = new SongNoteData(0, 0, 0, "", []);
gridGhostNote.visible = false; gridGhostNote.visible = false;
add(gridGhostNote); add(gridGhostNote);
gridGhostNote.zIndex = 11; gridGhostNote.zIndex = 11;
@ -4731,7 +4737,7 @@ class ChartEditorState extends UIState // UIState derives from MusicBeatState
else else
{ {
// Create a note and place it in the chart. // Create a note and place it in the chart.
var newNoteData:SongNoteData = new SongNoteData(cursorSnappedMs, cursorColumn, 0, noteKindToPlace); var newNoteData:SongNoteData = new SongNoteData(cursorSnappedMs, cursorColumn, 0, noteKindToPlace, noteParamsToPlace.clone());
performCommand(new AddNotesCommand([newNoteData], FlxG.keys.pressed.CONTROL)); performCommand(new AddNotesCommand([newNoteData], FlxG.keys.pressed.CONTROL));
@ -4890,11 +4896,13 @@ class ChartEditorState extends UIState // UIState derives from MusicBeatState
if (gridGhostNote == null) throw "ERROR: Tried to handle cursor, but gridGhostNote is null! Check ChartEditorState.buildGrid()"; if (gridGhostNote == null) throw "ERROR: Tried to handle cursor, but gridGhostNote is null! Check ChartEditorState.buildGrid()";
var noteData:SongNoteData = gridGhostNote.noteData != null ? gridGhostNote.noteData : new SongNoteData(cursorMs, cursorColumn, 0, noteKindToPlace); var noteData:SongNoteData = gridGhostNote.noteData != null ? gridGhostNote.noteData : new SongNoteData(cursorMs, cursorColumn, 0, noteKindToPlace,
noteParamsToPlace.clone());
if (cursorColumn != noteData.data || noteKindToPlace != noteData.kind) if (cursorColumn != noteData.data || noteKindToPlace != noteData.kind || noteParamsToPlace != noteData.params)
{ {
noteData.kind = noteKindToPlace; noteData.kind = noteKindToPlace;
noteData.params = noteParamsToPlace;
noteData.data = cursorColumn; noteData.data = cursorColumn;
gridGhostNote.noteStyle = NoteKindManager.getNoteStyleId(noteData.kind, isPixelStyle()) ?? currentSongNoteStyle; gridGhostNote.noteStyle = NoteKindManager.getNoteStyleId(noteData.kind, isPixelStyle()) ?? currentSongNoteStyle;
gridGhostNote.playNoteAnimation(); gridGhostNote.playNoteAnimation();
@ -5202,7 +5210,7 @@ class ChartEditorState extends UIState // UIState derives from MusicBeatState
if (notesAtPos.length == 0 && !removeNoteInstead) if (notesAtPos.length == 0 && !removeNoteInstead)
{ {
trace('Placing note. ${column}'); trace('Placing note. ${column}');
var newNoteData:SongNoteData = new SongNoteData(playheadPosSnappedMs, column, 0, noteKindToPlace); var newNoteData:SongNoteData = new SongNoteData(playheadPosSnappedMs, column, 0, noteKindToPlace, noteParamsToPlace.clone());
performCommand(new AddNotesCommand([newNoteData], FlxG.keys.pressed.CONTROL)); performCommand(new AddNotesCommand([newNoteData], FlxG.keys.pressed.CONTROL));
currentLiveInputPlaceNoteData[column] = newNoteData; currentLiveInputPlaceNoteData[column] = newNoteData;
} }
@ -5655,6 +5663,7 @@ class ChartEditorState extends UIState // UIState derives from MusicBeatState
FlxG.watch.addQuick('musicTime', audioInstTrack?.time ?? 0.0); FlxG.watch.addQuick('musicTime', audioInstTrack?.time ?? 0.0);
FlxG.watch.addQuick('noteKindToPlace', noteKindToPlace); FlxG.watch.addQuick('noteKindToPlace', noteKindToPlace);
FlxG.watch.addQuick('noteParamsToPlace', noteParamsToPlace);
FlxG.watch.addQuick('eventKindToPlace', eventKindToPlace); FlxG.watch.addQuick('eventKindToPlace', eventKindToPlace);
FlxG.watch.addQuick('scrollPosInPixels', scrollPositionInPixels); FlxG.watch.addQuick('scrollPosInPixels', scrollPositionInPixels);

View file

@ -9,6 +9,8 @@ import haxe.ui.core.Component;
import haxe.ui.events.UIEvent; import haxe.ui.events.UIEvent;
import funkin.ui.debug.charting.util.ChartEditorDropdowns; import funkin.ui.debug.charting.util.ChartEditorDropdowns;
import funkin.play.notes.notekind.NoteKindManager; import funkin.play.notes.notekind.NoteKindManager;
import funkin.play.notes.notekind.NoteKind.NoteKindParam;
import funkin.data.song.SongData.NoteParamData;
/** /**
* The toolbox which allows modifying information like Note Kind. * The toolbox which allows modifying information like Note Kind.
@ -60,6 +62,13 @@ class ChartEditorNoteDataToolbox extends ChartEditorBaseToolbox
trace('ChartEditorToolboxHandler.buildToolboxNoteDataLayout() - Note kind changed: $noteKind'); trace('ChartEditorToolboxHandler.buildToolboxNoteDataLayout() - Note kind changed: $noteKind');
var noteKindParams:Array<NoteKindParam> = NoteKindManager.getParams(noteKind);
var noteParamData:Array<NoteParamData> = [];
for (noteKindParam in noteKindParams)
{
noteParamData.push(new NoteParamData(noteKindParam.name, noteKindParam.data.defaultValue));
}
// Edit the note data to place. // Edit the note data to place.
if (noteKind == '~CUSTOM~') if (noteKind == '~CUSTOM~')
{ {
@ -71,10 +80,11 @@ class ChartEditorNoteDataToolbox extends ChartEditorBaseToolbox
{ {
hideCustom(); hideCustom();
chartEditorState.noteKindToPlace = noteKind; chartEditorState.noteKindToPlace = noteKind;
chartEditorState.noteParamsToPlace = noteParamData;
toolboxNotesCustomKind.value = chartEditorState.noteKindToPlace; toolboxNotesCustomKind.value = chartEditorState.noteKindToPlace;
clearNoteKindParams(); clearNoteKindParams();
for (param in NoteKindManager.getParams(noteKind)) for (param in noteKindParams)
{ {
var paramLabel:Label = new Label(); var paramLabel:Label = new Label();
paramLabel.value = param.description; paramLabel.value = param.description;
@ -107,10 +117,22 @@ class ChartEditorNoteDataToolbox extends ChartEditorBaseToolbox
if (!_initializing && chartEditorState.currentNoteSelection.length > 0) if (!_initializing && chartEditorState.currentNoteSelection.length > 0)
{ {
for (i in 0...toolboxNotesParams.length)
{
var toolboxComponent:Component = toolboxNotesParams[i].component;
toolboxComponent.onChange = function(event:UIEvent) {
for (note in chartEditorState.currentNoteSelection)
{
note.params[i].value = toolboxComponent.value;
}
}
}
for (note in chartEditorState.currentNoteSelection) for (note in chartEditorState.currentNoteSelection)
{ {
// Edit the note data of any selected notes. // Edit the note data of any selected notes.
note.kind = chartEditorState.noteKindToPlace; note.kind = chartEditorState.noteKindToPlace;
note.params = noteParamData.clone();
// update note sprites // update note sprites
for (noteSprite in chartEditorState.renderedNotes.members) for (noteSprite in chartEditorState.renderedNotes.members)