1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2024-11-16 03:43:36 +00:00
Funkin/source/funkin/ui/freeplay/AlbumRoll.hx

172 lines
4 KiB
Haxe
Raw Normal View History

package funkin.ui.freeplay;
2024-03-30 04:54:07 +00:00
import funkin.graphics.adobeanimate.FlxAtlasSprite;
import flixel.FlxSprite;
import flixel.group.FlxSpriteGroup;
import flixel.util.FlxSort;
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;
import funkin.util.assets.FlxAnimationUtil;
import funkin.graphics.FunkinSprite;
import funkin.util.SortUtil;
import openfl.utils.Assets;
/**
* 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):Null<String>;
function set_albumId(value:Null<String>):Null<String>
{
if (this.albumId != value)
{
this.albumId = value;
updateAlbum();
}
return value;
}
2024-03-30 04:54:07 +00:00
var newAlbumArt:FlxAtlasSprite;
2024-04-05 23:47:33 +00:00
// var difficultyStars:DifficultyStars;
var _exitMovers:Null<FreeplayState.ExitMoverData>;
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",
];
public function new()
{
super();
2024-03-30 04:54:07 +00:00
newAlbumArt = new FlxAtlasSprite(0, 0, Paths.animateAtlas("freeplay/albumRoll/freeplayAlbum"));
newAlbumArt.visible = false;
newAlbumArt.onAnimationFinish.add(onAlbumFinish);
2024-03-30 04:54:07 +00:00
add(newAlbumArt);
2024-04-05 23:47:33 +00:00
// difficultyStars = new DifficultyStars(140, 39);
// difficultyStars.stars.visible = false;
// add(difficultyStars);
2024-03-30 04:54:07 +00:00
}
2024-03-30 04:54:07 +00:00
function onAlbumFinish(animName:String):Void
{
// Play the idle animation for the current album.
newAlbumArt.playAnimation(animNames.get('$albumId-idle'), false, false, true);
2024-03-30 04:54:07 +00:00
// End on the last frame and don't continue until playAnimation is called again.
// newAlbumArt.anim.pause();
}
/**
* Load the album data by ID and update the textures.
*/
function updateAlbum():Void
{
if (albumId == null)
{
2024-04-05 23:47:33 +00:00
// difficultyStars.stars.visible = false;
2024-03-30 04:54:07 +00:00
return;
}
albumData = AlbumRegistry.instance.fetchEntry(albumId);
if (albumData == null)
{
FlxG.log.warn('Could not find album data for album ID: ${albumId}');
return;
};
applyExitMovers();
refresh();
}
public function refresh():Void
{
sort(SortUtil.byZIndex, FlxSort.ASCENDING);
}
/**
* Apply exit movers for the album roll.
* @param exitMovers The exit movers to apply.
*/
public function applyExitMovers(?exitMovers:FreeplayState.ExitMoverData):Void
{
if (exitMovers == null)
{
exitMovers = _exitMovers;
}
else
{
_exitMovers = exitMovers;
}
if (exitMovers == null) return;
2024-03-30 04:54:07 +00:00
exitMovers.set([newAlbumArt],
{
x: FlxG.width,
speed: 0.4,
wait: 0
});
}
var titleTimer:Null<FlxTimer> = null;
/**
* Play the intro animation on the album art.
*/
public function playIntro():Void
{
2024-03-30 04:54:07 +00:00
newAlbumArt.visible = true;
newAlbumArt.playAnimation(animNames.get('$albumId-active'), false, false, false);
2024-04-05 23:47:33 +00:00
// difficultyStars.stars.visible = false;
2024-03-30 04:54:07 +00:00
new FlxTimer().start(0.75, function(_) {
// showTitle();
2024-04-05 23:47:33 +00:00
// showStars();
});
}
2024-03-30 04:54:07 +00:00
public function skipIntro():Void
{
2024-03-30 04:54:07 +00:00
newAlbumArt.playAnimation(animNames.get('$albumId-trans'), false, false, false);
}
2024-04-05 23:47:33 +00:00
// public function setDifficultyStars(?difficulty:Int):Void
// {
// if (difficulty == null) return;
// difficultyStars.difficulty = difficulty;
// }
// /**
// * Make the album stars visible.
// */
// public function showStars():Void
// {
// difficultyStars.stars.visible = false; // true;
// }
}