Add a .visible attribute to story weeks.

This commit is contained in:
EliteMasterEric 2024-05-02 12:46:24 -04:00
parent dc50a4ba5e
commit a8a2dc83d3
5 changed files with 32 additions and 11 deletions

View File

@ -5,5 +5,8 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [1.1.0]
- Added `visible` attribute.
## [1.0.0]
Initial release.

View File

@ -34,6 +34,14 @@ typedef LevelData =
@:default([])
var props:Array<LevelPropData>;
/**
* Whether this week is visible in the story menu.
* @default `true`
*/
@:default(true)
@:optional
var visible:Bool;
/**
* The list of song IDs included in this level.
*/

View File

@ -12,7 +12,7 @@ class LevelRegistry extends BaseRegistry<Level, LevelData>
* Handle breaking changes by incrementing this value
* and adding migration to the `migrateLevelData()` function.
*/
public static final LEVEL_DATA_VERSION:thx.semver.Version = "1.0.0";
public static final LEVEL_DATA_VERSION:thx.semver.Version = "1.0.1";
public static final LEVEL_DATA_VERSION_RULE:thx.semver.VersionRule = "1.0.x";

View File

@ -111,7 +111,7 @@ class Level implements IRegistryEntry<LevelData>
*/
public function isVisible():Bool
{
return true;
return _data.visible;
}
/**

View File

@ -97,6 +97,11 @@ class StoryMenuState extends MusicBeatState
*/
var difficultySprite:FlxSprite;
/**
* List of available level IDs.
*/
var levelList:Array<String> = [];
var difficultySprites:Map<String, FlxSprite>;
var stickerSubState:StickerSubState;
@ -118,6 +123,15 @@ class StoryMenuState extends MusicBeatState
{
super.create();
levelList = LevelRegistry.instance.listSortedLevelIds();
levelList = levelList.filter(function(id) {
var levelData = LevelRegistry.instance.fetchEntry(id);
if (levelData == null) return false;
return levelData.isVisible();
});
if (levelList.length == 0) levelList = ['tutorial']; // Make sure there's at least one level to display.
difficultySprites = new Map<String, FlxSprite>();
transIn = FlxTransitionableState.defaultTransIn;
@ -273,14 +287,13 @@ class StoryMenuState extends MusicBeatState
{
levelTitles.clear();
var levelIds:Array<String> = LevelRegistry.instance.listSortedLevelIds();
if (levelIds.length == 0) levelIds = ['tutorial']; // Make sure there's at least one level to display.
for (levelIndex in 0...levelIds.length)
for (levelIndex in 0...levelList.length)
{
var levelId:String = levelIds[levelIndex];
var levelId:String = levelList[levelIndex];
var level:Level = LevelRegistry.instance.fetchEntry(levelId);
if (level == null) continue;
if (level == null || !level.isVisible()) continue;
// TODO: Readd lock icon if unlocked is false.
var levelTitleItem:LevelTitle = new LevelTitle(0, Std.int(levelBackground.y + levelBackground.height + 10), level);
levelTitleItem.targetY = ((levelTitleItem.height + 20) * levelIndex);
@ -373,9 +386,6 @@ class StoryMenuState extends MusicBeatState
*/
function changeLevel(change:Int = 0):Void
{
var levelList:Array<String> = LevelRegistry.instance.listSortedLevelIds();
if (levelList.length == 0) levelList = ['tutorial'];
var currentIndex:Int = levelList.indexOf(currentLevelId);
currentIndex += change;