2024-03-20 14:37:24 -04:00
|
|
|
package funkin.ui.freeplay;
|
|
|
|
|
2024-03-21 00:38:52 -04:00
|
|
|
import flixel.FlxSprite;
|
2024-03-20 14:37:24 -04:00
|
|
|
import flixel.group.FlxSpriteGroup;
|
|
|
|
import flixel.util.FlxSort;
|
2024-03-21 00:38:52 -04:00
|
|
|
import flixel.tweens.FlxTween;
|
|
|
|
import flixel.util.FlxTimer;
|
|
|
|
import flixel.tweens.FlxEase;
|
2024-03-20 14:37:24 -04:00
|
|
|
import funkin.data.freeplay.AlbumRegistry;
|
|
|
|
import funkin.graphics.FunkinSprite;
|
|
|
|
import funkin.util.SortUtil;
|
2024-03-21 00:38:52 -04:00
|
|
|
import openfl.utils.Assets;
|
2024-03-20 14:37:24 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The graphic for the album roll in the FreeplayState.
|
|
|
|
* Simply set `albumID` to fetch the required data and update the textures.
|
|
|
|
*/
|
|
|
|
class AlbumRoll extends FlxSpriteGroup
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The ID of the album to display.
|
|
|
|
* Modify this value to automatically update the album art and title.
|
|
|
|
*/
|
|
|
|
public var albumId(default, set):String;
|
|
|
|
|
|
|
|
function set_albumId(value:String):String
|
|
|
|
{
|
|
|
|
if (this.albumId != value)
|
|
|
|
{
|
|
|
|
this.albumId = value;
|
|
|
|
updateAlbum();
|
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2024-03-21 00:38:52 -04:00
|
|
|
var albumArt:FunkinSprite;
|
2024-03-20 14:37:24 -04:00
|
|
|
var albumTitle:FunkinSprite;
|
|
|
|
var difficultyStars:DifficultyStars;
|
|
|
|
|
2024-03-21 00:38:52 -04:00
|
|
|
var _exitMovers:Null<FreeplayState.ExitMoverData>;
|
|
|
|
|
2024-03-20 14:37:24 -04:00
|
|
|
var albumData:Album;
|
|
|
|
|
|
|
|
public function new()
|
|
|
|
{
|
|
|
|
super();
|
|
|
|
|
|
|
|
albumTitle = new FunkinSprite(947, 491);
|
2024-03-21 00:38:52 -04:00
|
|
|
albumTitle.visible = true;
|
2024-03-20 14:37:24 -04:00
|
|
|
albumTitle.zIndex = 200;
|
|
|
|
add(albumTitle);
|
|
|
|
|
|
|
|
difficultyStars = new DifficultyStars(140, 39);
|
|
|
|
|
|
|
|
difficultyStars.stars.visible = true;
|
|
|
|
albumTitle.visible = false;
|
|
|
|
// albumArtist.visible = false;
|
|
|
|
|
|
|
|
// var albumArtist:FlxSprite = new FlxSprite(1010, 607).loadGraphic(Paths.image('freeplay/albumArtist-kawaisprite'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Load the album data by ID and update the textures.
|
|
|
|
*/
|
|
|
|
function updateAlbum():Void
|
|
|
|
{
|
|
|
|
albumData = AlbumRegistry.instance.fetchEntry(albumId);
|
|
|
|
|
|
|
|
if (albumData == null)
|
|
|
|
{
|
|
|
|
FlxG.log.warn('Could not find album data for album ID: ${albumId}');
|
|
|
|
|
|
|
|
return;
|
|
|
|
};
|
|
|
|
|
|
|
|
if (albumArt != null)
|
|
|
|
{
|
2024-03-21 00:38:52 -04:00
|
|
|
FlxTween.cancelTweensOf(albumArt);
|
2024-03-20 14:37:24 -04:00
|
|
|
albumArt.visible = false;
|
|
|
|
albumArt.destroy();
|
|
|
|
remove(albumArt);
|
|
|
|
}
|
|
|
|
|
2024-03-21 00:38:52 -04:00
|
|
|
// Paths.animateAtlas('freeplay/albumRoll'),
|
|
|
|
albumArt = FunkinSprite.create(1500, 360, albumData.getAlbumArtAssetKey());
|
|
|
|
albumArt.setGraphicSize(262, 262); // Magic number for size IG
|
2024-03-20 14:37:24 -04:00
|
|
|
albumArt.zIndex = 100;
|
|
|
|
|
|
|
|
playIntro();
|
|
|
|
add(albumArt);
|
|
|
|
|
2024-03-21 00:38:52 -04:00
|
|
|
applyExitMovers();
|
|
|
|
|
|
|
|
if (Assets.exists(Paths.image(albumData.getAlbumTitleAssetKey())))
|
|
|
|
{
|
|
|
|
albumTitle.loadGraphic(Paths.image(albumData.getAlbumTitleAssetKey()));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
albumTitle.visible = false;
|
|
|
|
}
|
2024-03-20 14:37:24 -04:00
|
|
|
|
|
|
|
refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function refresh():Void
|
|
|
|
{
|
|
|
|
sort(SortUtil.byZIndex, FlxSort.ASCENDING);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Apply exit movers for the album roll.
|
|
|
|
* @param exitMovers The exit movers to apply.
|
|
|
|
*/
|
2024-03-21 00:38:52 -04:00
|
|
|
public function applyExitMovers(?exitMovers:FreeplayState.ExitMoverData):Void
|
2024-03-20 14:37:24 -04:00
|
|
|
{
|
2024-03-21 00:38:52 -04:00
|
|
|
if (exitMovers == null)
|
|
|
|
{
|
|
|
|
exitMovers = _exitMovers;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_exitMovers = exitMovers;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (exitMovers == null) return;
|
|
|
|
|
2024-03-20 14:37:24 -04:00
|
|
|
exitMovers.set([albumArt],
|
|
|
|
{
|
|
|
|
x: FlxG.width,
|
|
|
|
speed: 0.4,
|
|
|
|
wait: 0
|
|
|
|
});
|
|
|
|
exitMovers.set([albumTitle],
|
|
|
|
{
|
|
|
|
x: FlxG.width,
|
|
|
|
speed: 0.2,
|
|
|
|
wait: 0.1
|
|
|
|
});
|
|
|
|
|
|
|
|
/*
|
|
|
|
exitMovers.set([albumArtist],
|
|
|
|
{
|
|
|
|
x: FlxG.width * 1.1,
|
|
|
|
speed: 0.2,
|
|
|
|
wait: 0.2
|
|
|
|
});
|
|
|
|
*/
|
|
|
|
exitMovers.set([difficultyStars],
|
|
|
|
{
|
|
|
|
x: FlxG.width * 1.2,
|
|
|
|
speed: 0.2,
|
|
|
|
wait: 0.3
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Play the intro animation on the album art.
|
|
|
|
*/
|
|
|
|
public function playIntro():Void
|
|
|
|
{
|
|
|
|
albumArt.visible = true;
|
2024-03-21 00:38:52 -04:00
|
|
|
FlxTween.tween(albumArt, {x: 950, y: 320, angle: -340}, 0.5, {ease: FlxEase.quintOut});
|
|
|
|
|
|
|
|
albumTitle.visible = false;
|
|
|
|
new FlxTimer().start(0.75, function(_) {
|
|
|
|
showTitle();
|
|
|
|
});
|
2024-03-20 14:37:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function setDifficultyStars(?difficulty:Int):Void
|
|
|
|
{
|
|
|
|
if (difficulty == null) return;
|
|
|
|
|
|
|
|
difficultyStars.difficulty = difficulty;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function showTitle():Void
|
|
|
|
{
|
|
|
|
albumTitle.visible = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Make the album stars visible.
|
|
|
|
*/
|
|
|
|
public function showStars():Void
|
|
|
|
{
|
|
|
|
// albumArtist.visible = false;
|
|
|
|
difficultyStars.stars.visible = false;
|
|
|
|
}
|
|
|
|
}
|