From a8a2dc83d3af6854e9db00eae8e1887f9d5cda9f Mon Sep 17 00:00:00 2001 From: EliteMasterEric Date: Thu, 2 May 2024 12:46:24 -0400 Subject: [PATCH] Add a .visible attribute to story weeks. --- source/funkin/data/story/level/CHANGELOG.md | 3 ++ source/funkin/data/story/level/LevelData.hx | 8 ++++++ .../funkin/data/story/level/LevelRegistry.hx | 2 +- source/funkin/ui/story/Level.hx | 2 +- source/funkin/ui/story/StoryMenuState.hx | 28 +++++++++++++------ 5 files changed, 32 insertions(+), 11 deletions(-) diff --git a/source/funkin/data/story/level/CHANGELOG.md b/source/funkin/data/story/level/CHANGELOG.md index 75d1fe4c0..27ef923a5 100644 --- a/source/funkin/data/story/level/CHANGELOG.md +++ b/source/funkin/data/story/level/CHANGELOG.md @@ -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. diff --git a/source/funkin/data/story/level/LevelData.hx b/source/funkin/data/story/level/LevelData.hx index 957a9f66f..ceb2cc054 100644 --- a/source/funkin/data/story/level/LevelData.hx +++ b/source/funkin/data/story/level/LevelData.hx @@ -34,6 +34,14 @@ typedef LevelData = @:default([]) var props:Array; + /** + * 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. */ diff --git a/source/funkin/data/story/level/LevelRegistry.hx b/source/funkin/data/story/level/LevelRegistry.hx index ad580953e..7ddccce08 100644 --- a/source/funkin/data/story/level/LevelRegistry.hx +++ b/source/funkin/data/story/level/LevelRegistry.hx @@ -12,7 +12,7 @@ class LevelRegistry extends BaseRegistry * 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"; diff --git a/source/funkin/ui/story/Level.hx b/source/funkin/ui/story/Level.hx index e56fdc7dc..683e94815 100644 --- a/source/funkin/ui/story/Level.hx +++ b/source/funkin/ui/story/Level.hx @@ -111,7 +111,7 @@ class Level implements IRegistryEntry */ public function isVisible():Bool { - return true; + return _data.visible; } /** diff --git a/source/funkin/ui/story/StoryMenuState.hx b/source/funkin/ui/story/StoryMenuState.hx index daab5aef8..a17e6e3a2 100644 --- a/source/funkin/ui/story/StoryMenuState.hx +++ b/source/funkin/ui/story/StoryMenuState.hx @@ -97,6 +97,11 @@ class StoryMenuState extends MusicBeatState */ var difficultySprite:FlxSprite; + /** + * List of available level IDs. + */ + var levelList:Array = []; + var difficultySprites:Map; 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(); transIn = FlxTransitionableState.defaultTransIn; @@ -273,14 +287,13 @@ class StoryMenuState extends MusicBeatState { levelTitles.clear(); - var levelIds:Array = 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 = LevelRegistry.instance.listSortedLevelIds(); - if (levelList.length == 0) levelList = ['tutorial']; - var currentIndex:Int = levelList.indexOf(currentLevelId); currentIndex += change;