2023-10-26 09:46:22 +00:00
|
|
|
package funkin.ui.debug.charting.components;
|
2022-10-07 04:37:21 +00:00
|
|
|
|
2022-12-14 20:33:30 +00:00
|
|
|
import flixel.FlxObject;
|
2022-10-07 04:37:21 +00:00
|
|
|
import flixel.FlxSprite;
|
|
|
|
import flixel.graphics.frames.FlxFramesCollection;
|
2023-08-31 22:47:23 +00:00
|
|
|
import flixel.graphics.frames.FlxAtlasFrames;
|
|
|
|
import flixel.graphics.frames.FlxFrame;
|
2022-10-07 04:37:21 +00:00
|
|
|
import flixel.graphics.frames.FlxTileFrames;
|
|
|
|
import flixel.math.FlxPoint;
|
2024-06-02 00:44:16 +00:00
|
|
|
import funkin.data.animation.AnimationData;
|
2023-09-08 21:46:44 +00:00
|
|
|
import funkin.data.song.SongData.SongNoteData;
|
2024-06-02 00:44:16 +00:00
|
|
|
import funkin.data.notestyle.NoteStyleRegistry;
|
|
|
|
import funkin.play.notes.notestyle.NoteStyle;
|
|
|
|
import funkin.play.notes.NoteDirection;
|
2022-10-07 04:37:21 +00:00
|
|
|
|
|
|
|
/**
|
2023-10-26 09:46:22 +00:00
|
|
|
* A sprite that can be used to display a note in a chart.
|
2022-10-07 04:37:21 +00:00
|
|
|
* Designed to be used and reused efficiently. Has no gameplay functionality.
|
|
|
|
*/
|
2023-08-30 06:24:35 +00:00
|
|
|
@:nullSafety
|
2023-10-26 09:46:22 +00:00
|
|
|
@:access(funkin.ui.debug.charting.ChartEditorState)
|
2022-10-07 04:37:21 +00:00
|
|
|
class ChartEditorNoteSprite extends FlxSprite
|
|
|
|
{
|
2023-02-28 18:17:28 +00:00
|
|
|
/**
|
|
|
|
* The list of available note skin to validate against.
|
|
|
|
*/
|
2023-09-26 03:24:07 +00:00
|
|
|
public static final NOTE_STYLES:Array<String> = ['funkin', 'pixel'];
|
2023-02-28 18:17:28 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The ChartEditorState this note belongs to.
|
|
|
|
*/
|
2023-01-23 03:25:45 +00:00
|
|
|
public var parentState:ChartEditorState;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The note data that this sprite represents.
|
|
|
|
* You can set this to null to kill the sprite and flag it for recycling.
|
|
|
|
*/
|
2023-08-28 19:03:29 +00:00
|
|
|
public var noteData(default, set):Null<SongNoteData>;
|
2023-01-23 03:25:45 +00:00
|
|
|
|
2023-02-28 18:17:28 +00:00
|
|
|
/**
|
|
|
|
* The name of the note style currently in use.
|
|
|
|
*/
|
2024-06-02 20:11:17 +00:00
|
|
|
@:isVar
|
|
|
|
public var noteStyle(get, set):Null<String>;
|
2023-02-28 18:17:28 +00:00
|
|
|
|
2023-10-26 09:46:22 +00:00
|
|
|
public var overrideStepTime(default, set):Null<Float> = null;
|
|
|
|
|
|
|
|
function set_overrideStepTime(value:Null<Float>):Null<Float>
|
|
|
|
{
|
|
|
|
if (overrideStepTime == value) return overrideStepTime;
|
|
|
|
|
|
|
|
overrideStepTime = value;
|
|
|
|
updateNotePosition();
|
|
|
|
return overrideStepTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
public var overrideData(default, set):Null<Int> = null;
|
|
|
|
|
|
|
|
function set_overrideData(value:Null<Int>):Null<Int>
|
|
|
|
{
|
|
|
|
if (overrideData == value) return overrideData;
|
|
|
|
|
|
|
|
overrideData = value;
|
|
|
|
playNoteAnimation();
|
|
|
|
return overrideData;
|
|
|
|
}
|
|
|
|
|
2023-01-23 03:25:45 +00:00
|
|
|
public function new(parent:ChartEditorState)
|
|
|
|
{
|
|
|
|
super();
|
|
|
|
|
|
|
|
this.parentState = parent;
|
|
|
|
|
2024-06-02 00:58:56 +00:00
|
|
|
var entries:Array<String> = NoteStyleRegistry.instance.listEntryIds();
|
|
|
|
|
2023-01-23 03:25:45 +00:00
|
|
|
if (noteFrameCollection == null)
|
|
|
|
{
|
2024-06-02 00:44:16 +00:00
|
|
|
buildEmptyFrameCollection();
|
|
|
|
|
2024-06-02 00:58:56 +00:00
|
|
|
for (entry in entries)
|
|
|
|
{
|
|
|
|
addNoteStyleFrames(fetchNoteStyle(entry));
|
|
|
|
}
|
2023-01-23 03:25:45 +00:00
|
|
|
}
|
|
|
|
|
2023-08-31 22:47:23 +00:00
|
|
|
if (noteFrameCollection == null) throw 'ERROR: Could not initialize note sprite animations.';
|
|
|
|
|
2023-01-23 03:25:45 +00:00
|
|
|
this.frames = noteFrameCollection;
|
|
|
|
|
2024-06-02 00:58:56 +00:00
|
|
|
for (entry in entries)
|
|
|
|
{
|
|
|
|
addNoteStyleAnimations(fetchNoteStyle(entry));
|
|
|
|
}
|
2023-01-23 03:25:45 +00:00
|
|
|
}
|
|
|
|
|
2023-08-28 19:03:29 +00:00
|
|
|
static var noteFrameCollection:Null<FlxFramesCollection> = null;
|
2023-01-23 03:25:45 +00:00
|
|
|
|
2024-06-02 00:44:16 +00:00
|
|
|
function fetchNoteStyle(noteStyleId:String):NoteStyle
|
2023-01-23 03:25:45 +00:00
|
|
|
{
|
2024-07-12 20:39:42 +00:00
|
|
|
var result = NoteStyleRegistry.instance.fetchEntry(noteStyleId);
|
|
|
|
if (result != null) return result;
|
|
|
|
return NoteStyleRegistry.instance.fetchDefault();
|
2024-06-02 00:44:16 +00:00
|
|
|
}
|
2023-01-23 03:25:45 +00:00
|
|
|
|
2024-06-02 00:44:16 +00:00
|
|
|
@:access(funkin.play.notes.notestyle.NoteStyle)
|
|
|
|
@:nullSafety(Off)
|
|
|
|
static function addNoteStyleFrames(noteStyle:NoteStyle):Void
|
|
|
|
{
|
|
|
|
var prefix:String = noteStyle.id.toTitleCase();
|
2023-01-23 03:25:45 +00:00
|
|
|
|
2024-06-02 00:44:16 +00:00
|
|
|
var frameCollection:FlxAtlasFrames = Paths.getSparrowAtlas(noteStyle.getNoteAssetPath(), noteStyle.getNoteAssetLibrary());
|
2024-07-12 08:13:20 +00:00
|
|
|
if (frameCollection == null)
|
|
|
|
{
|
|
|
|
trace('Could not retrieve frame collection for ${noteStyle}: ${Paths.image(noteStyle.getNoteAssetPath(), noteStyle.getNoteAssetLibrary())}');
|
|
|
|
FlxG.log.error('Could not retrieve frame collection for ${noteStyle}: ${Paths.image(noteStyle.getNoteAssetPath(), noteStyle.getNoteAssetLibrary())}');
|
|
|
|
return;
|
|
|
|
}
|
2024-06-02 00:44:16 +00:00
|
|
|
for (frame in frameCollection.frames)
|
2023-01-23 03:25:45 +00:00
|
|
|
{
|
2024-06-02 00:44:16 +00:00
|
|
|
// cloning the frame because else
|
|
|
|
// we will fuck up the frame data used in game
|
|
|
|
var clonedFrame:FlxFrame = frame.copyTo();
|
|
|
|
clonedFrame.name = '$prefix${clonedFrame.name}';
|
|
|
|
noteFrameCollection.pushFrame(clonedFrame);
|
2023-01-23 03:25:45 +00:00
|
|
|
}
|
2024-06-02 00:44:16 +00:00
|
|
|
}
|
2023-01-23 03:25:45 +00:00
|
|
|
|
2024-06-02 00:44:16 +00:00
|
|
|
@:access(funkin.play.notes.notestyle.NoteStyle)
|
|
|
|
@:nullSafety(Off)
|
|
|
|
function addNoteStyleAnimations(noteStyle:NoteStyle):Void
|
|
|
|
{
|
|
|
|
var prefix:String = noteStyle.id.toTitleCase();
|
|
|
|
var suffix:String = noteStyle.id.toTitleCase();
|
2023-01-23 03:25:45 +00:00
|
|
|
|
2024-06-02 00:44:16 +00:00
|
|
|
var leftData:AnimationData = noteStyle.fetchNoteAnimationData(NoteDirection.LEFT);
|
|
|
|
this.animation.addByPrefix('tapLeft$suffix', '$prefix${leftData.prefix}', leftData.frameRate, leftData.looped, leftData.flipX, leftData.flipY);
|
|
|
|
|
|
|
|
var downData:AnimationData = noteStyle.fetchNoteAnimationData(NoteDirection.DOWN);
|
|
|
|
this.animation.addByPrefix('tapDown$suffix', '$prefix${downData.prefix}', downData.frameRate, downData.looped, downData.flipX, downData.flipY);
|
|
|
|
|
|
|
|
var upData:AnimationData = noteStyle.fetchNoteAnimationData(NoteDirection.UP);
|
|
|
|
this.animation.addByPrefix('tapUp$suffix', '$prefix${upData.prefix}', upData.frameRate, upData.looped, upData.flipX, upData.flipY);
|
|
|
|
|
|
|
|
var rightData:AnimationData = noteStyle.fetchNoteAnimationData(NoteDirection.RIGHT);
|
|
|
|
this.animation.addByPrefix('tapRight$suffix', '$prefix${rightData.prefix}', rightData.frameRate, rightData.looped, rightData.flipX, rightData.flipY);
|
2023-01-23 03:25:45 +00:00
|
|
|
}
|
|
|
|
|
2023-08-31 22:47:23 +00:00
|
|
|
@:nullSafety(Off)
|
|
|
|
static function buildEmptyFrameCollection():Void
|
|
|
|
{
|
|
|
|
noteFrameCollection = new FlxFramesCollection(null, ATLAS, null);
|
|
|
|
}
|
|
|
|
|
2023-08-28 19:03:29 +00:00
|
|
|
function set_noteData(value:Null<SongNoteData>):Null<SongNoteData>
|
2023-01-23 03:25:45 +00:00
|
|
|
{
|
|
|
|
this.noteData = value;
|
|
|
|
|
|
|
|
if (this.noteData == null)
|
|
|
|
{
|
|
|
|
this.kill();
|
|
|
|
return this.noteData;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.visible = true;
|
|
|
|
|
|
|
|
// Update the animation to match the note data.
|
|
|
|
// Animation is updated first so size is correct before updating position.
|
|
|
|
playNoteAnimation();
|
|
|
|
|
|
|
|
// Update the position to match the note data.
|
|
|
|
updateNotePosition();
|
|
|
|
|
|
|
|
return this.noteData;
|
|
|
|
}
|
|
|
|
|
2023-09-01 03:48:15 +00:00
|
|
|
public function updateNotePosition(?origin:FlxObject):Void
|
2023-01-23 03:25:45 +00:00
|
|
|
{
|
2023-08-31 22:47:23 +00:00
|
|
|
if (this.noteData == null) return;
|
|
|
|
|
2023-10-26 09:46:22 +00:00
|
|
|
var cursorColumn:Int = (overrideData != null) ? overrideData : this.noteData.data;
|
2023-01-23 03:25:45 +00:00
|
|
|
|
2023-10-26 09:46:22 +00:00
|
|
|
cursorColumn = ChartEditorState.noteDataToGridColumn(cursorColumn);
|
2023-01-23 03:25:45 +00:00
|
|
|
|
2023-07-20 01:16:39 +00:00
|
|
|
this.x = cursorColumn * ChartEditorState.GRID_SIZE;
|
2023-01-23 03:25:45 +00:00
|
|
|
|
2023-07-20 01:16:39 +00:00
|
|
|
// Notes far in the song will start far down, but the group they belong to will have a high negative offset.
|
2023-09-13 18:51:12 +00:00
|
|
|
// noteData.getStepTime() returns a calculated value which accounts for BPM changes
|
2023-10-26 09:46:22 +00:00
|
|
|
var stepTime:Float = (overrideStepTime != null) ? overrideStepTime : noteData.getStepTime();
|
2023-09-13 18:51:12 +00:00
|
|
|
if (stepTime >= 0)
|
2023-01-23 03:25:45 +00:00
|
|
|
{
|
2023-09-13 18:51:12 +00:00
|
|
|
this.y = stepTime * ChartEditorState.GRID_SIZE;
|
2023-01-23 03:25:45 +00:00
|
|
|
}
|
|
|
|
|
2023-07-20 01:16:39 +00:00
|
|
|
if (origin != null)
|
2023-01-23 03:25:45 +00:00
|
|
|
{
|
2023-07-20 01:16:39 +00:00
|
|
|
this.x += origin.x;
|
|
|
|
this.y += origin.y;
|
2023-01-23 03:25:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-02 20:11:17 +00:00
|
|
|
function get_noteStyle():Null<String>
|
2023-02-28 18:17:28 +00:00
|
|
|
{
|
2024-07-12 20:39:42 +00:00
|
|
|
if (this.noteStyle == null)
|
|
|
|
{
|
|
|
|
var result = this.parentState.currentSongNoteStyle;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
return this.noteStyle;
|
2024-06-02 20:11:17 +00:00
|
|
|
}
|
2024-06-02 00:44:16 +00:00
|
|
|
|
2024-06-02 20:11:17 +00:00
|
|
|
function set_noteStyle(value:Null<String>):Null<String>
|
|
|
|
{
|
|
|
|
this.noteStyle = value;
|
|
|
|
this.playNoteAnimation();
|
|
|
|
return value;
|
2023-02-28 18:17:28 +00:00
|
|
|
}
|
|
|
|
|
2024-06-02 00:44:16 +00:00
|
|
|
@:nullSafety(Off)
|
2023-02-28 18:17:28 +00:00
|
|
|
public function playNoteAnimation():Void
|
2023-01-23 03:25:45 +00:00
|
|
|
{
|
2023-08-31 22:47:23 +00:00
|
|
|
if (this.noteData == null) return;
|
|
|
|
|
2023-01-23 03:25:45 +00:00
|
|
|
// Decide whether to display a note or a sustain.
|
|
|
|
var baseAnimationName:String = 'tap';
|
|
|
|
|
|
|
|
// Play the appropriate animation for the type, direction, and skin.
|
2023-10-26 09:46:22 +00:00
|
|
|
var dirName:String = overrideData != null ? SongNoteData.buildDirectionName(overrideData) : this.noteData.getDirectionName();
|
2024-07-12 20:39:42 +00:00
|
|
|
var noteStyleSuffix:String = this.noteStyle?.toTitleCase() ?? Constants.DEFAULT_NOTE_STYLE.toTitleCase();
|
2023-10-26 09:46:22 +00:00
|
|
|
var animationName:String = '${baseAnimationName}${dirName}${this.noteStyle.toTitleCase()}';
|
2023-01-23 03:25:45 +00:00
|
|
|
|
|
|
|
this.animation.play(animationName);
|
|
|
|
|
|
|
|
// Resize note.
|
|
|
|
|
|
|
|
switch (baseAnimationName)
|
|
|
|
{
|
|
|
|
case 'tap':
|
2024-07-12 08:13:20 +00:00
|
|
|
this.setGraphicSize(ChartEditorState.GRID_SIZE, 0);
|
|
|
|
this.updateHitbox();
|
2023-01-23 03:25:45 +00:00
|
|
|
}
|
|
|
|
|
2024-06-02 00:44:16 +00:00
|
|
|
var bruhStyle:NoteStyle = fetchNoteStyle(this.noteStyle);
|
|
|
|
this.antialiasing = !bruhStyle._data?.assets?.note?.isPixel ?? true;
|
2023-01-23 03:25:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return whether this note (or its parent) is currently visible.
|
|
|
|
*/
|
|
|
|
public function isNoteVisible(viewAreaBottom:Float, viewAreaTop:Float):Bool
|
|
|
|
{
|
2023-07-23 00:16:43 +00:00
|
|
|
// True if the note is above the view area.
|
|
|
|
var aboveViewArea = (this.y + this.height < viewAreaTop);
|
2023-01-23 03:25:45 +00:00
|
|
|
|
2023-07-23 00:16:43 +00:00
|
|
|
// True if the note is below the view area.
|
|
|
|
var belowViewArea = (this.y > viewAreaBottom);
|
|
|
|
|
|
|
|
return !aboveViewArea && !belowViewArea;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return whether a note, if placed in the scene, would be visible.
|
2023-09-13 18:51:12 +00:00
|
|
|
* This function should be made HYPER EFFICIENT because it's called a lot.
|
2023-07-23 00:16:43 +00:00
|
|
|
*/
|
|
|
|
public static function wouldNoteBeVisible(viewAreaBottom:Float, viewAreaTop:Float, noteData:SongNoteData, ?origin:FlxObject):Bool
|
|
|
|
{
|
|
|
|
var noteHeight:Float = ChartEditorState.GRID_SIZE;
|
2023-09-13 18:51:12 +00:00
|
|
|
var stepTime:Float = inline noteData.getStepTime();
|
|
|
|
var notePosY:Float = stepTime * ChartEditorState.GRID_SIZE;
|
2023-07-23 00:16:43 +00:00
|
|
|
if (origin != null) notePosY += origin.y;
|
|
|
|
|
|
|
|
// True if the note is above the view area.
|
|
|
|
var aboveViewArea = (notePosY + noteHeight < viewAreaTop);
|
2023-01-23 03:25:45 +00:00
|
|
|
|
2023-07-23 00:16:43 +00:00
|
|
|
// True if the note is below the view area.
|
|
|
|
var belowViewArea = (notePosY > viewAreaBottom);
|
2023-01-23 03:25:45 +00:00
|
|
|
|
2023-07-23 00:16:43 +00:00
|
|
|
return !aboveViewArea && !belowViewArea;
|
2023-01-23 03:25:45 +00:00
|
|
|
}
|
2022-10-07 04:37:21 +00:00
|
|
|
}
|