1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2024-09-21 01:28:55 +00:00
Funkin/source/funkin/ui/freeplay/AlbumRoll.hx

174 lines
3.7 KiB
Haxe
Raw Normal View History

package funkin.ui.freeplay;
import flixel.graphics.FlxGraphic;
import flixel.group.FlxSpriteGroup;
import flixel.util.FlxSort;
import funkin.data.freeplay.AlbumRegistry;
import funkin.graphics.adobeanimate.FlxAtlasSprite;
import funkin.graphics.FunkinSprite;
import funkin.util.SortUtil;
/**
* 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;
}
var albumArt:FlxAtlasSprite;
var albumTitle:FunkinSprite;
var difficultyStars:DifficultyStars;
var albumData:Album;
public function new()
{
super();
albumTitle = new FunkinSprite(947, 491);
albumTitle.visible = false;
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;
};
var albumArtGraphics:Array<FlxGraphic> = [null, albumData.getAlbumArtGraphic()];
if (albumArt != null)
{
albumArt.visible = false;
albumArt.anim.stop();
albumArt.destroy();
remove(albumArt);
}
// I wasn't able to get replacing to work properly on an existing object,
// so I just throw the old one in the trash and make a new one.
albumArt = new FlxAtlasSprite(640, 360, Paths.animateAtlas('freeplay/albumRoll'),
{
OverrideGraphics: albumArtGraphics,
});
albumArt.zIndex = 100;
playIntro();
add(albumArt);
albumTitle.loadGraphic(Paths.image(albumData.getAlbumTitleAssetKey()));
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
{
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;
albumArt.anim.play('');
albumArt.anim.onComplete = function() {
albumArt.anim.pause();
};
}
public function setDifficultyStars(?difficulty:Int):Void
{
if (difficulty == null) return;
difficultyStars.difficulty = difficulty;
}
/**
* Make the album title graphic visible.
*/
public function showTitle():Void
{
albumTitle.visible = true;
}
/**
* Make the album stars visible.
*/
public function showStars():Void
{
// albumArtist.visible = false;
difficultyStars.stars.visible = false;
}
}