diff --git a/assets/data/weeks.xml b/assets/data/weeks.xml index 468de93b..b7009bc7 100644 --- a/assets/data/weeks.xml +++ b/assets/data/weeks.xml @@ -22,7 +22,7 @@ - + diff --git a/buildnumber.txt b/buildnumber.txt index 7ccfcb14..cf5106d7 100644 --- a/buildnumber.txt +++ b/buildnumber.txt @@ -1 +1 @@ -997 \ No newline at end of file +999 \ No newline at end of file diff --git a/source/funkin/menus/StoryMenuState.hx b/source/funkin/menus/StoryMenuState.hx index 86af29ee..1729b08a 100644 --- a/source/funkin/menus/StoryMenuState.hx +++ b/source/funkin/menus/StoryMenuState.hx @@ -1,5 +1,6 @@ package funkin.menus; +import openfl.utils.Assets; import flixel.FlxG; import flixel.util.FlxColor; import funkin.ui.FunkinText; @@ -11,6 +12,7 @@ class StoryMenuState extends MusicBeatState { public var weekData:Array = []; public var characters:Map = []; + public var weeks:Array = []; public var scoreText:FlxText; public var tracklist:FlxText; @@ -24,7 +26,6 @@ class StoryMenuState extends MusicBeatState { public var leftArrow:FlxSprite; public var rightArrow:FlxSprite; - public override function create() { super.create(); loadXMLs(); @@ -52,9 +53,67 @@ class StoryMenuState extends MusicBeatState { } public function loadXML(xmlPath:String) { - // try { - - // } + try { + var xml = new Access(Xml.parse(Assets.getText(xmlPath)).firstElement()); + + for(el in xml.elements) { + switch(el.name) { + case 'characters': + for(k=>char in el.nodes.char) { + if (!char.has.name) { + Logs.trace('weeks.xml: Character at index ${k} has no name. Skipping...', WARNING); + continue; + } + if (characters[char.att.name] != null) continue; + var charObj:MenuCharacter = { + spritePath: Paths.image(char.getAtt('scale').getDefault('menus/storymenu/characters/${char.att.name}')), + scale: Std.parseFloat(char.getAtt('scale')).getDefault(1), + xml: char + }; + characters[char.att.name] = charObj; + } + case 'weeks': + for(k=>week in el.nodes.week) { + if (!week.has.name) { + Logs.trace('weeks.xml: Week at index ${k} has no name. Skipping...', WARNING); + continue; + } + var weekObj:WeekData = { + name: week.att.name, + sprite: week.getAtt('sprite').getDefault('week${k}'), + chars: [null, null, null], + songs: [] + }; + if (week.has.chars) { + for(k=>e in week.att.chars.split(",")) { + if (e.trim() == "" || e == "none" || e == "null") + weekObj.chars[k] = null; + else + weekObj.chars[k] = e.trim(); + } + } + for(k2=>song in week.nodes.song) { + if (!song.has.name) { + Logs.trace('weeks.xml: Song at index ${k2} in week ${weekObj.name} has no name. Skipping...', WARNING); + continue; + } + weekObj.songs.push({ + name: song.att.name, + hide: week.getAtt('hide').getDefault('false') == "true" + }); + } + if (weekObj.songs.length <= 0) { + Logs.trace('weeks.xml: Week ${weekObj.name} has no songs. Skipping...', WARNING); + continue; + } + weeks.push(weekObj); + } + } + } + trace(weeks); + } catch(e) { + + } } } @@ -70,8 +129,8 @@ typedef WeekSong = { var hide:Bool; } -class MenuCharacter extends FlxSprite { - public function new(xml:Access) { - super(); - } +typedef MenuCharacter = { + var spritePath:String; + var xml:Access; + var scale:Float; } \ No newline at end of file diff --git a/source/funkin/system/CoolUtil.hx b/source/funkin/system/CoolUtil.hx index f0f3650e..3472921a 100644 --- a/source/funkin/system/CoolUtil.hx +++ b/source/funkin/system/CoolUtil.hx @@ -1,5 +1,6 @@ package funkin.system; +import haxe.xml.Access; import flixel.input.keyboard.FlxKey; import lime.utils.Assets; import flixel.animation.FlxAnimation; @@ -211,6 +212,11 @@ class CoolUtil sprite.updateHitbox(); } + public static function getAtt(xml:Access, name:String) { + if (!xml.has.resolve(name)) return null; + return xml.att.resolve(name); + } + /** * Returns last member of array */