2023-01-22 19:55:30 -05:00
|
|
|
package funkin.ui.debug.charting;
|
|
|
|
|
2023-07-19 01:29:13 -04:00
|
|
|
import funkin.play.event.SongEventData.SongEventParser;
|
|
|
|
import flixel.graphics.frames.FlxAtlasFrames;
|
2023-01-22 19:55:30 -05:00
|
|
|
import openfl.display.BitmapData;
|
|
|
|
import openfl.utils.Assets;
|
|
|
|
import flixel.FlxObject;
|
|
|
|
import flixel.FlxBasic;
|
|
|
|
import flixel.FlxSprite;
|
|
|
|
import flixel.graphics.frames.FlxFramesCollection;
|
|
|
|
import flixel.graphics.frames.FlxTileFrames;
|
|
|
|
import flixel.math.FlxPoint;
|
|
|
|
import funkin.play.song.SongData.SongEventData;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A event sprite that can be used to display a song event in a chart.
|
|
|
|
* Designed to be used and reused efficiently. Has no gameplay functionality.
|
|
|
|
*/
|
|
|
|
class ChartEditorEventSprite extends FlxSprite
|
|
|
|
{
|
2023-07-19 01:29:13 -04:00
|
|
|
public static final DEFAULT_EVENT = 'Default';
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
public var eventData(default, set):SongEventData;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The image used for all song events. Cached for performance.
|
|
|
|
*/
|
|
|
|
var eventGraphic:BitmapData;
|
|
|
|
|
|
|
|
public function new(parent:ChartEditorState)
|
|
|
|
{
|
|
|
|
super();
|
|
|
|
|
|
|
|
this.parentState = parent;
|
|
|
|
|
2023-07-19 01:29:13 -04:00
|
|
|
this.frames = buildFrames();
|
|
|
|
|
|
|
|
buildAnimations();
|
|
|
|
refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Build a set of animations to allow displaying different types of chart events.
|
|
|
|
* @param force `true` to force rebuilding the frames.
|
|
|
|
*/
|
|
|
|
static function buildFrames(?force:Bool = false):FlxFramesCollection
|
|
|
|
{
|
|
|
|
static var eventFrames:FlxFramesCollection = null;
|
|
|
|
|
|
|
|
if (eventFrames != null && !force) return eventFrames;
|
|
|
|
eventFrames = new FlxAtlasFrames(null);
|
|
|
|
|
|
|
|
// Push the default event as a frame.
|
|
|
|
var defaultFrames:FlxAtlasFrames = Paths.getSparrowAtlas('ui/chart-editor/events/$DEFAULT_EVENT');
|
|
|
|
defaultFrames.parent.persist = true;
|
|
|
|
for (frame in defaultFrames.frames)
|
|
|
|
{
|
|
|
|
eventFrames.pushFrame(frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Push all the other events as frames.
|
|
|
|
for (eventName in SongEventParser.listEventIds())
|
|
|
|
{
|
|
|
|
var frames:FlxAtlasFrames = Paths.getSparrowAtlas('ui/chart-editor/events/$eventName');
|
|
|
|
if (frames == null) continue; // No graphic for this event.
|
|
|
|
frames.parent.persist = true;
|
|
|
|
for (frame in frames.frames)
|
|
|
|
{
|
|
|
|
eventFrames.pushFrame(frame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return eventFrames;
|
2023-01-22 22:25:45 -05:00
|
|
|
}
|
|
|
|
|
2023-07-19 01:29:13 -04:00
|
|
|
function buildAnimations():Void
|
2023-01-22 22:25:45 -05:00
|
|
|
{
|
2023-07-19 01:29:13 -04:00
|
|
|
var eventNames:Array<String> = [DEFAULT_EVENT].concat(SongEventParser.listEventIds());
|
|
|
|
for (eventName in eventNames)
|
2023-01-22 22:25:45 -05:00
|
|
|
{
|
2023-07-19 01:29:13 -04:00
|
|
|
this.animation.addByPrefix(eventName, '${eventName}0', 24, false);
|
2023-01-22 22:25:45 -05:00
|
|
|
}
|
2023-07-19 01:29:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function correctAnimationName(name:String):String
|
|
|
|
{
|
|
|
|
if (this.animation.exists(name)) return name;
|
|
|
|
trace('Warning: Invalid animation name "' + name + '" for song event. Using "${DEFAULT_EVENT}"');
|
|
|
|
return DEFAULT_EVENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function playAnimation(name:String):Void
|
|
|
|
{
|
|
|
|
var correctedName = correctAnimationName(name);
|
|
|
|
this.animation.play(correctedName);
|
|
|
|
refresh();
|
|
|
|
}
|
2023-01-22 22:25:45 -05:00
|
|
|
|
2023-07-19 01:29:13 -04:00
|
|
|
function refresh():Void
|
|
|
|
{
|
2023-01-22 22:25:45 -05:00
|
|
|
setGraphicSize(ChartEditorState.GRID_SIZE);
|
|
|
|
this.updateHitbox();
|
|
|
|
}
|
|
|
|
|
|
|
|
function set_eventData(value:SongEventData):SongEventData
|
|
|
|
{
|
|
|
|
this.eventData = value;
|
|
|
|
|
|
|
|
if (this.eventData == null)
|
|
|
|
{
|
2023-07-19 01:29:13 -04:00
|
|
|
// Disown parent. MAKE SURE TO REVIVE BEFORE REUSING
|
2023-01-22 22:25:45 -05:00
|
|
|
this.kill();
|
|
|
|
return this.eventData;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.visible = true;
|
2023-07-19 01:29:13 -04:00
|
|
|
playAnimation(this.eventData.event);
|
2023-01-22 22:25:45 -05:00
|
|
|
// Update the position to match the note data.
|
|
|
|
updateEventPosition();
|
|
|
|
|
|
|
|
return this.eventData;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function updateEventPosition(?origin:FlxObject)
|
|
|
|
{
|
|
|
|
this.x = (ChartEditorState.STRUMLINE_SIZE * 2 + 1 - 1) * ChartEditorState.GRID_SIZE;
|
|
|
|
if (this.eventData.stepTime >= 0) this.y = this.eventData.stepTime * ChartEditorState.GRID_SIZE;
|
|
|
|
|
|
|
|
if (origin != null)
|
|
|
|
{
|
|
|
|
this.x += origin.x;
|
|
|
|
this.y += origin.y;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return whether this note (or its parent) is currently visible.
|
|
|
|
*/
|
|
|
|
public function isEventVisible(viewAreaBottom:Float, viewAreaTop:Float):Bool
|
|
|
|
{
|
|
|
|
var outsideViewArea = (this.y + this.height < viewAreaTop || this.y > viewAreaBottom);
|
|
|
|
|
|
|
|
if (!outsideViewArea)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Check if this note's parent or child is visible.
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2023-01-22 19:55:30 -05:00
|
|
|
}
|