package funkin.ui.freeplay; import flixel.FlxSprite; import flixel.group.FlxSpriteGroup; import flixel.util.FlxSort; import flixel.tweens.FlxTween; import flixel.util.FlxTimer; import flixel.tweens.FlxEase; 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; function set_albumId(value:Null):Null { if (this.albumId != value) { this.albumId = value; updateAlbum(); } return value; } var albumArt:FunkinSprite; var albumTitle:FunkinSprite; var difficultyStars:DifficultyStars; var _exitMovers:Null; var albumData:Album; public function new() { super(); albumTitle = new FunkinSprite(947, 491); albumTitle.visible = true; 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 { if (albumId == null) { albumArt.visible = false; albumTitle.visible = false; if (titleTimer != null) { titleTimer.cancel(); titleTimer = null; } } albumData = AlbumRegistry.instance.fetchEntry(albumId); if (albumData == null) { FlxG.log.warn('Could not find album data for album ID: ${albumId}'); return; }; if (albumArt != null) { FlxTween.cancelTweensOf(albumArt); albumArt.visible = false; albumArt.destroy(); remove(albumArt); } // Paths.animateAtlas('freeplay/albumRoll'), albumArt = FunkinSprite.create(1500, 360, albumData.getAlbumArtAssetKey()); albumArt.setGraphicSize(262, 262); // Magic number for size IG albumArt.zIndex = 100; // playIntro(); add(albumArt); applyExitMovers(); if (Assets.exists(Paths.image(albumData.getAlbumTitleAssetKey()))) { if (albumData.hasAlbumTitleAnimations()) { albumTitle.loadSparrow(albumData.getAlbumTitleAssetKey()); FlxAnimationUtil.addAtlasAnimations(albumTitle, albumData.getAlbumTitleAnimations()); } else { albumTitle.loadGraphic(Paths.image(albumData.getAlbumTitleAssetKey())); } } else { albumTitle.visible = false; } 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; 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 }); } var titleTimer:Null = null; /** * Play the intro animation on the album art. */ public function playIntro():Void { albumArt.visible = true; FlxTween.tween(albumArt, {x: 950, y: 320, angle: -340}, 0.5, {ease: FlxEase.elasticOut}); albumTitle.visible = false; if (titleTimer != null) { titleTimer.cancel(); titleTimer = null; } titleTimer = new FlxTimer().start(0.75, function(_) { showTitle(); }); } public function setDifficultyStars(?difficulty:Int):Void { if (difficulty == null) return; difficultyStars.difficulty = difficulty; } public function showTitle():Void { albumTitle.visible = true; albumTitle.animation.play('active'); albumTitle.animation.finishCallback = (_) -> albumTitle.animation.play('idle'); } /** * Make the album stars visible. */ public function showStars():Void { // albumArtist.visible = false; difficultyStars.stars.visible = false; } }