2022-10-07 00:37:21 -04:00
|
|
|
package funkin.ui.debug.charting;
|
|
|
|
|
2022-12-14 15:33:30 -05:00
|
|
|
import flixel.FlxObject;
|
2022-10-07 00:37:21 -04:00
|
|
|
import flixel.FlxSprite;
|
|
|
|
import flixel.graphics.frames.FlxFramesCollection;
|
2023-08-31 18:47:23 -04:00
|
|
|
import flixel.graphics.frames.FlxAtlasFrames;
|
|
|
|
import flixel.graphics.frames.FlxFrame;
|
2022-10-07 00:37:21 -04:00
|
|
|
import flixel.graphics.frames.FlxTileFrames;
|
|
|
|
import flixel.math.FlxPoint;
|
2023-09-08 17:46:44 -04:00
|
|
|
import funkin.data.song.SongData.SongNoteData;
|
2022-10-07 00:37:21 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A note sprite that can be used to display a note in a chart.
|
|
|
|
* Designed to be used and reused efficiently. Has no gameplay functionality.
|
|
|
|
*/
|
2023-08-30 02:24:35 -04:00
|
|
|
@:nullSafety
|
2022-10-07 00:37:21 -04:00
|
|
|
class ChartEditorNoteSprite extends FlxSprite
|
|
|
|
{
|
2023-02-28 13:17:28 -05:00
|
|
|
/**
|
|
|
|
* The list of available note skin to validate against.
|
|
|
|
*/
|
|
|
|
public static final NOTE_STYLES:Array<String> = ['Normal', 'Pixel'];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The ChartEditorState this note belongs to.
|
|
|
|
*/
|
2023-01-22 22:25:45 -05: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 15:03:29 -04:00
|
|
|
public var noteData(default, set):Null<SongNoteData>;
|
2023-01-22 22:25:45 -05:00
|
|
|
|
2023-02-28 13:17:28 -05:00
|
|
|
/**
|
|
|
|
* The name of the note style currently in use.
|
|
|
|
*/
|
2023-08-31 18:47:23 -04:00
|
|
|
public var noteStyle(get, never):String;
|
2023-02-28 13:17:28 -05:00
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
public function new(parent:ChartEditorState)
|
|
|
|
{
|
|
|
|
super();
|
|
|
|
|
|
|
|
this.parentState = parent;
|
|
|
|
|
|
|
|
if (noteFrameCollection == null)
|
|
|
|
{
|
|
|
|
initFrameCollection();
|
|
|
|
}
|
|
|
|
|
2023-08-31 18:47:23 -04:00
|
|
|
if (noteFrameCollection == null) throw 'ERROR: Could not initialize note sprite animations.';
|
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
this.frames = noteFrameCollection;
|
|
|
|
|
|
|
|
// Initialize all the animations, not just the one we're going to use immediately,
|
|
|
|
// so that later we can reuse the sprite without having to initialize more animations during scrolling.
|
|
|
|
this.animation.addByPrefix('tapLeftNormal', 'purple instance');
|
|
|
|
this.animation.addByPrefix('tapDownNormal', 'blue instance');
|
|
|
|
this.animation.addByPrefix('tapUpNormal', 'green instance');
|
|
|
|
this.animation.addByPrefix('tapRightNormal', 'red instance');
|
|
|
|
|
|
|
|
this.animation.addByPrefix('holdLeftNormal', 'LeftHoldPiece');
|
|
|
|
this.animation.addByPrefix('holdDownNormal', 'DownHoldPiece');
|
|
|
|
this.animation.addByPrefix('holdUpNormal', 'UpHoldPiece');
|
|
|
|
this.animation.addByPrefix('holdRightNormal', 'RightHoldPiece');
|
|
|
|
|
|
|
|
this.animation.addByPrefix('holdEndLeftNormal', 'LeftHoldEnd');
|
|
|
|
this.animation.addByPrefix('holdEndDownNormal', 'DownHoldEnd');
|
|
|
|
this.animation.addByPrefix('holdEndUpNormal', 'UpHoldEnd');
|
|
|
|
this.animation.addByPrefix('holdEndRightNormal', 'RightHoldEnd');
|
|
|
|
|
|
|
|
this.animation.addByPrefix('tapLeftPixel', 'pixel4');
|
|
|
|
this.animation.addByPrefix('tapDownPixel', 'pixel5');
|
|
|
|
this.animation.addByPrefix('tapUpPixel', 'pixel6');
|
|
|
|
this.animation.addByPrefix('tapRightPixel', 'pixel7');
|
|
|
|
}
|
|
|
|
|
2023-08-28 15:03:29 -04:00
|
|
|
static var noteFrameCollection:Null<FlxFramesCollection> = null;
|
2023-01-22 22:25:45 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* We load all the note frames once, then reuse them.
|
|
|
|
*/
|
|
|
|
static function initFrameCollection():Void
|
|
|
|
{
|
2023-08-31 18:47:23 -04:00
|
|
|
buildEmptyFrameCollection();
|
|
|
|
if (noteFrameCollection == null) return;
|
2023-01-22 22:25:45 -05:00
|
|
|
|
|
|
|
// TODO: Automatically iterate over the list of note skins.
|
|
|
|
|
|
|
|
// Normal notes
|
2023-08-31 18:47:23 -04:00
|
|
|
var frameCollectionNormal:FlxAtlasFrames = Paths.getSparrowAtlas('NOTE_assets');
|
2023-01-22 22:25:45 -05:00
|
|
|
|
|
|
|
for (frame in frameCollectionNormal.frames)
|
|
|
|
{
|
|
|
|
noteFrameCollection.pushFrame(frame);
|
|
|
|
}
|
2023-08-31 18:47:23 -04:00
|
|
|
var frameCollectionNormal2:FlxAtlasFrames = Paths.getSparrowAtlas('NoteHoldNormal');
|
2023-01-22 22:25:45 -05:00
|
|
|
|
|
|
|
for (frame in frameCollectionNormal2.frames)
|
|
|
|
{
|
|
|
|
noteFrameCollection.pushFrame(frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pixel notes
|
|
|
|
var graphicPixel = FlxG.bitmap.add(Paths.image('weeb/pixelUI/arrows-pixels', 'week6'), false, null);
|
|
|
|
if (graphicPixel == null) trace('ERROR: Could not load graphic: ' + Paths.image('weeb/pixelUI/arrows-pixels', 'week6'));
|
|
|
|
var frameCollectionPixel = FlxTileFrames.fromGraphic(graphicPixel, new FlxPoint(17, 17));
|
|
|
|
for (i in 0...frameCollectionPixel.frames.length)
|
|
|
|
{
|
2023-08-31 18:47:23 -04:00
|
|
|
var frame:Null<FlxFrame> = frameCollectionPixel.frames[i];
|
|
|
|
if (frame == null) continue;
|
2023-01-22 22:25:45 -05:00
|
|
|
|
|
|
|
frame.name = 'pixel' + i;
|
|
|
|
noteFrameCollection.pushFrame(frame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-31 18:47:23 -04:00
|
|
|
@:nullSafety(Off)
|
|
|
|
static function buildEmptyFrameCollection():Void
|
|
|
|
{
|
|
|
|
noteFrameCollection = new FlxFramesCollection(null, ATLAS, null);
|
|
|
|
}
|
|
|
|
|
2023-08-28 15:03:29 -04:00
|
|
|
function set_noteData(value:Null<SongNoteData>):Null<SongNoteData>
|
2023-01-22 22:25:45 -05: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-08-31 23:48:15 -04:00
|
|
|
public function updateNotePosition(?origin:FlxObject):Void
|
2023-01-22 22:25:45 -05:00
|
|
|
{
|
2023-08-31 18:47:23 -04:00
|
|
|
if (this.noteData == null) return;
|
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
var cursorColumn:Int = this.noteData.data;
|
|
|
|
|
|
|
|
if (cursorColumn < 0) cursorColumn = 0;
|
|
|
|
if (cursorColumn >= (ChartEditorState.STRUMLINE_SIZE * 2 + 1))
|
|
|
|
{
|
|
|
|
cursorColumn = (ChartEditorState.STRUMLINE_SIZE * 2 + 1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Invert player and opponent columns.
|
|
|
|
if (cursorColumn >= ChartEditorState.STRUMLINE_SIZE)
|
|
|
|
{
|
|
|
|
cursorColumn -= ChartEditorState.STRUMLINE_SIZE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cursorColumn += ChartEditorState.STRUMLINE_SIZE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-19 21:16:39 -04:00
|
|
|
this.x = cursorColumn * ChartEditorState.GRID_SIZE;
|
2023-01-22 22:25:45 -05:00
|
|
|
|
2023-07-19 21:16:39 -04: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 14:51:12 -04:00
|
|
|
// noteData.getStepTime() returns a calculated value which accounts for BPM changes
|
|
|
|
var stepTime:Float =
|
|
|
|
inline this.noteData.getStepTime();
|
|
|
|
if (stepTime >= 0)
|
2023-01-22 22:25:45 -05:00
|
|
|
{
|
2023-09-13 14:51:12 -04:00
|
|
|
this.y = stepTime * ChartEditorState.GRID_SIZE;
|
2023-01-22 22:25:45 -05:00
|
|
|
}
|
|
|
|
|
2023-07-19 21:16:39 -04:00
|
|
|
if (origin != null)
|
2023-01-22 22:25:45 -05:00
|
|
|
{
|
2023-07-19 21:16:39 -04:00
|
|
|
this.x += origin.x;
|
|
|
|
this.y += origin.y;
|
2023-01-22 22:25:45 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-28 13:17:28 -05:00
|
|
|
function get_noteStyle():String
|
|
|
|
{
|
|
|
|
// Fall back to 'Normal' if it's not a valid note style.
|
|
|
|
return if (NOTE_STYLES.contains(this.parentState.currentSongNoteSkin)) this.parentState.currentSongNoteSkin else 'Normal';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function playNoteAnimation():Void
|
2023-01-22 22:25:45 -05:00
|
|
|
{
|
2023-08-31 18:47:23 -04:00
|
|
|
if (this.noteData == null) return;
|
|
|
|
|
2023-01-22 22:25:45 -05: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-02-28 13:17:28 -05:00
|
|
|
var animationName:String = '${baseAnimationName}${this.noteData.getDirectionName()}${this.noteStyle}';
|
2023-01-22 22:25:45 -05:00
|
|
|
|
|
|
|
this.animation.play(animationName);
|
|
|
|
|
|
|
|
// Resize note.
|
|
|
|
|
|
|
|
switch (baseAnimationName)
|
|
|
|
{
|
|
|
|
case 'tap':
|
|
|
|
this.setGraphicSize(0, ChartEditorState.GRID_SIZE);
|
|
|
|
}
|
|
|
|
this.updateHitbox();
|
|
|
|
|
|
|
|
// TODO: Make this an attribute of the note skin.
|
|
|
|
this.antialiasing = (this.parentState.currentSongNoteSkin != 'Pixel');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return whether this note (or its parent) is currently visible.
|
|
|
|
*/
|
|
|
|
public function isNoteVisible(viewAreaBottom:Float, viewAreaTop:Float):Bool
|
|
|
|
{
|
2023-07-22 20:16:43 -04:00
|
|
|
// True if the note is above the view area.
|
|
|
|
var aboveViewArea = (this.y + this.height < viewAreaTop);
|
2023-01-22 22:25:45 -05:00
|
|
|
|
2023-07-22 20:16:43 -04: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 14:51:12 -04:00
|
|
|
* This function should be made HYPER EFFICIENT because it's called a lot.
|
2023-07-22 20:16:43 -04:00
|
|
|
*/
|
|
|
|
public static function wouldNoteBeVisible(viewAreaBottom:Float, viewAreaTop:Float, noteData:SongNoteData, ?origin:FlxObject):Bool
|
|
|
|
{
|
|
|
|
var noteHeight:Float = ChartEditorState.GRID_SIZE;
|
2023-09-13 14:51:12 -04:00
|
|
|
var stepTime:Float = inline noteData.getStepTime();
|
|
|
|
var notePosY:Float = stepTime * ChartEditorState.GRID_SIZE;
|
2023-07-22 20:16:43 -04:00
|
|
|
if (origin != null) notePosY += origin.y;
|
|
|
|
|
|
|
|
// True if the note is above the view area.
|
|
|
|
var aboveViewArea = (notePosY + noteHeight < viewAreaTop);
|
2023-01-22 22:25:45 -05:00
|
|
|
|
2023-07-22 20:16:43 -04:00
|
|
|
// True if the note is below the view area.
|
|
|
|
var belowViewArea = (notePosY > viewAreaBottom);
|
2023-01-22 22:25:45 -05:00
|
|
|
|
2023-07-22 20:16:43 -04:00
|
|
|
return !aboveViewArea && !belowViewArea;
|
2023-01-22 22:25:45 -05:00
|
|
|
}
|
2022-10-07 00:37:21 -04:00
|
|
|
}
|