2024-03-20 18:37:24 +00:00
|
|
|
package funkin.ui.freeplay;
|
|
|
|
|
2024-03-30 04:54:07 +00:00
|
|
|
import funkin.graphics.adobeanimate.FlxAtlasSprite;
|
2024-03-21 04:38:52 +00:00
|
|
|
import flixel.FlxSprite;
|
2024-03-20 18:37:24 +00:00
|
|
|
import flixel.group.FlxSpriteGroup;
|
|
|
|
import flixel.util.FlxSort;
|
2024-03-21 04:38:52 +00:00
|
|
|
import flixel.tweens.FlxTween;
|
|
|
|
import flixel.util.FlxTimer;
|
|
|
|
import flixel.tweens.FlxEase;
|
2024-03-23 19:34:37 +00:00
|
|
|
import funkin.data.freeplay.album.AlbumRegistry;
|
2024-03-28 05:46:50 +00:00
|
|
|
import funkin.util.assets.FlxAnimationUtil;
|
2024-03-20 18:37:24 +00:00
|
|
|
import funkin.graphics.FunkinSprite;
|
|
|
|
import funkin.util.SortUtil;
|
2024-03-21 04:38:52 +00:00
|
|
|
import openfl.utils.Assets;
|
2024-03-20 18:37:24 +00: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.
|
|
|
|
*/
|
2024-03-28 05:46:50 +00:00
|
|
|
public var albumId(default, set):Null<String>;
|
2024-03-20 18:37:24 +00:00
|
|
|
|
2024-03-28 05:46:50 +00:00
|
|
|
function set_albumId(value:Null<String>):Null<String>
|
2024-03-20 18:37:24 +00:00
|
|
|
{
|
|
|
|
if (this.albumId != value)
|
|
|
|
{
|
|
|
|
this.albumId = value;
|
|
|
|
updateAlbum();
|
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2024-03-30 04:54:07 +00:00
|
|
|
var newAlbumArt:FlxAtlasSprite;
|
2024-07-10 21:25:52 +00:00
|
|
|
var albumTitle:FunkinSprite;
|
2024-03-20 18:37:24 +00:00
|
|
|
|
2024-05-11 05:05:51 +00:00
|
|
|
var difficultyStars:DifficultyStars;
|
2024-03-21 04:38:52 +00:00
|
|
|
var _exitMovers:Null<FreeplayState.ExitMoverData>;
|
|
|
|
|
2024-03-20 18:37:24 +00:00
|
|
|
var albumData:Album;
|
|
|
|
|
2024-03-30 04:54:07 +00:00
|
|
|
final animNames:Map<String, String> = [
|
|
|
|
"volume1-active" => "ENTRANCE",
|
|
|
|
"volume2-active" => "ENTRANCE VOL2",
|
|
|
|
"volume3-active" => "ENTRANCE VOL3",
|
|
|
|
"volume1-trans" => "VOL1 TRANS",
|
|
|
|
"volume2-trans" => "VOL2 TRANS",
|
|
|
|
"volume3-trans" => "VOL3 TRANS",
|
|
|
|
"volume1-idle" => "VOL1 STILL",
|
|
|
|
"volume2-idle" => "VOL2 STILL",
|
|
|
|
"volume3-idle" => "VOL3 STILL",
|
|
|
|
];
|
|
|
|
|
2024-03-20 18:37:24 +00:00
|
|
|
public function new()
|
|
|
|
{
|
|
|
|
super();
|
|
|
|
|
2024-07-10 21:25:52 +00:00
|
|
|
newAlbumArt = new FlxAtlasSprite(640, 350, Paths.animateAtlas("freeplay/albumRoll/freeplayAlbum"));
|
2024-03-30 04:54:07 +00:00
|
|
|
newAlbumArt.visible = false;
|
2024-07-10 21:25:52 +00:00
|
|
|
newAlbumArt.onAnimationComplete.add(onAlbumFinish);
|
2024-03-20 18:37:24 +00:00
|
|
|
|
2024-03-30 04:54:07 +00:00
|
|
|
add(newAlbumArt);
|
2024-03-20 18:37:24 +00:00
|
|
|
|
2024-05-11 05:05:51 +00:00
|
|
|
difficultyStars = new DifficultyStars(140, 39);
|
2024-06-04 20:38:21 +00:00
|
|
|
difficultyStars.visible = false;
|
2024-05-11 05:05:51 +00:00
|
|
|
add(difficultyStars);
|
2024-07-10 21:25:52 +00:00
|
|
|
|
|
|
|
buildAlbumTitle("freeplay/albumRoll/volume1-text");
|
|
|
|
albumTitle.visible = false;
|
2024-03-30 04:54:07 +00:00
|
|
|
}
|
2024-03-20 18:37:24 +00:00
|
|
|
|
2024-03-30 04:54:07 +00:00
|
|
|
function onAlbumFinish(animName:String):Void
|
|
|
|
{
|
|
|
|
// Play the idle animation for the current album.
|
2024-07-10 21:25:52 +00:00
|
|
|
if (animName != "idle")
|
|
|
|
{
|
|
|
|
// newAlbumArt.playAnimation('idle', true);
|
|
|
|
}
|
2024-03-20 18:37:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Load the album data by ID and update the textures.
|
|
|
|
*/
|
|
|
|
function updateAlbum():Void
|
|
|
|
{
|
2024-03-28 05:46:50 +00:00
|
|
|
if (albumId == null)
|
|
|
|
{
|
2024-05-11 05:05:51 +00:00
|
|
|
this.visible = false;
|
|
|
|
difficultyStars.stars.visible = false;
|
2024-03-30 04:54:07 +00:00
|
|
|
return;
|
2024-03-28 05:46:50 +00:00
|
|
|
}
|
2024-05-11 05:05:51 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
this.visible = true;
|
|
|
|
}
|
2024-03-28 05:46:50 +00:00
|
|
|
|
2024-03-20 18:37:24 +00:00
|
|
|
albumData = AlbumRegistry.instance.fetchEntry(albumId);
|
|
|
|
|
|
|
|
if (albumData == null)
|
|
|
|
{
|
|
|
|
FlxG.log.warn('Could not find album data for album ID: ${albumId}');
|
|
|
|
|
|
|
|
return;
|
|
|
|
};
|
|
|
|
|
2024-07-10 21:25:52 +00:00
|
|
|
// Update the album art.
|
|
|
|
var albumGraphic = Paths.image(albumData.getAlbumArtAssetKey());
|
|
|
|
newAlbumArt.replaceFrameGraphic(0, albumGraphic);
|
|
|
|
|
|
|
|
buildAlbumTitle(albumData.getAlbumTitleAssetKey());
|
|
|
|
|
2024-03-21 04:38:52 +00:00
|
|
|
applyExitMovers();
|
|
|
|
|
2024-03-20 18:37:24 +00: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 04:38:52 +00:00
|
|
|
public function applyExitMovers(?exitMovers:FreeplayState.ExitMoverData):Void
|
2024-03-20 18:37:24 +00:00
|
|
|
{
|
2024-03-21 04:38:52 +00:00
|
|
|
if (exitMovers == null)
|
|
|
|
{
|
|
|
|
exitMovers = _exitMovers;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_exitMovers = exitMovers;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (exitMovers == null) return;
|
|
|
|
|
2024-05-31 09:39:53 +00:00
|
|
|
exitMovers.set([newAlbumArt, difficultyStars],
|
2024-03-20 18:37:24 +00:00
|
|
|
{
|
|
|
|
x: FlxG.width,
|
|
|
|
speed: 0.4,
|
|
|
|
wait: 0
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-03-28 05:46:50 +00:00
|
|
|
var titleTimer:Null<FlxTimer> = null;
|
|
|
|
|
2024-03-20 18:37:24 +00:00
|
|
|
/**
|
|
|
|
* Play the intro animation on the album art.
|
|
|
|
*/
|
|
|
|
public function playIntro():Void
|
|
|
|
{
|
2024-07-10 21:25:52 +00:00
|
|
|
albumTitle.visible = false;
|
2024-03-30 04:54:07 +00:00
|
|
|
newAlbumArt.visible = true;
|
2024-07-10 21:25:52 +00:00
|
|
|
newAlbumArt.playAnimation('intro', true);
|
2024-03-28 05:46:50 +00:00
|
|
|
|
2024-06-04 20:38:21 +00:00
|
|
|
difficultyStars.visible = false;
|
2024-03-30 04:54:07 +00:00
|
|
|
new FlxTimer().start(0.75, function(_) {
|
2024-07-10 21:25:52 +00:00
|
|
|
showTitle();
|
2024-05-11 05:05:51 +00:00
|
|
|
showStars();
|
2024-07-10 21:25:52 +00:00
|
|
|
albumTitle.animation.play('switch');
|
2024-03-21 04:38:52 +00:00
|
|
|
});
|
2024-03-20 18:37:24 +00:00
|
|
|
}
|
|
|
|
|
2024-03-30 04:54:07 +00:00
|
|
|
public function skipIntro():Void
|
2024-03-20 18:37:24 +00:00
|
|
|
{
|
2024-07-10 21:25:52 +00:00
|
|
|
// Weird workaround
|
|
|
|
newAlbumArt.playAnimation('switch', true);
|
|
|
|
albumTitle.animation.play('switch');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function showTitle():Void
|
|
|
|
{
|
|
|
|
albumTitle.visible = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function buildAlbumTitle(assetKey:String):Void
|
|
|
|
{
|
|
|
|
if (albumTitle != null)
|
|
|
|
{
|
|
|
|
remove(albumTitle);
|
|
|
|
albumTitle = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
albumTitle = FunkinSprite.createSparrow(925, 500, assetKey);
|
|
|
|
albumTitle.visible = albumTitle.frames != null && newAlbumArt.visible;
|
|
|
|
albumTitle.animation.addByPrefix('idle', 'idle0', 24, true);
|
|
|
|
albumTitle.animation.addByPrefix('switch', 'switch0', 24, false);
|
|
|
|
add(albumTitle);
|
|
|
|
|
|
|
|
albumTitle.animation.finishCallback = (function(name) {
|
|
|
|
if (name == 'switch') albumTitle.animation.play('idle');
|
|
|
|
});
|
|
|
|
albumTitle.animation.play('idle');
|
|
|
|
|
|
|
|
albumTitle.zIndex = 1000;
|
|
|
|
|
|
|
|
if (_exitMovers != null) _exitMovers.set([albumTitle],
|
|
|
|
{
|
|
|
|
x: FlxG.width,
|
|
|
|
speed: 0.4,
|
|
|
|
wait: 0
|
|
|
|
});
|
2024-03-20 18:37:24 +00:00
|
|
|
}
|
|
|
|
|
2024-05-11 05:05:51 +00:00
|
|
|
public function setDifficultyStars(?difficulty:Int):Void
|
|
|
|
{
|
|
|
|
if (difficulty == null) return;
|
|
|
|
difficultyStars.difficulty = difficulty;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Make the album stars visible.
|
|
|
|
*/
|
|
|
|
public function showStars():Void
|
|
|
|
{
|
2024-06-04 20:38:21 +00:00
|
|
|
difficultyStars.visible = true; // true;
|
|
|
|
difficultyStars.flameCheck();
|
2024-05-11 05:05:51 +00:00
|
|
|
}
|
2024-03-20 18:37:24 +00:00
|
|
|
}
|