new weeks format

This commit is contained in:
Yoshman29
2023-02-22 02:15:15 +01:00
parent 2158da173a
commit 242860628b
23 changed files with 196 additions and 140 deletions
+1 -1
View File
@@ -399,7 +399,7 @@ class FreeplaySonglist {
var songsFound:Array<String> = [];
if (Paths.assetsTree.existsSpecific(path, "TEXT", source)) {
var trim = "";
songsFound = [for(line in Assets.getText(path).split("\n")) if ((trim = line.trim()) != "" && !trim.startsWith("#")) trim];
songsFound = CoolUtil.coolTextFile(Paths.txt('freeplaySonglist'));
} else {
songsFound = Paths.getFolderDirectories('songs', false, source);
}
+114 -65
View File
@@ -1,5 +1,6 @@
package funkin.menus;
import haxe.io.Path;
import funkin.scripting.events.*;
import flixel.util.FlxTimer;
import flixel.math.FlxPoint;
@@ -122,6 +123,7 @@ class StoryMenuState extends MusicBeatState {
changeWeek(0, true);
DiscordUtil.changePresence("In the Menus", null);
CoolUtil.playMenuSong();
}
var __lastDifficultyTween:FlxTween;
@@ -204,7 +206,116 @@ class StoryMenuState extends MusicBeatState {
}
public function loadXMLs() {
loadXML(Paths.xml('weeks'));
// CoolUtil.coolTextFile(Paths.txt('freeplaySonglist'));
var weeks:Array<String> = [];
if (getWeeksFromSource(weeks, MODS))
getWeeksFromSource(weeks, SOURCE);
for(k=>weekName in weeks) {
var week:Access = null;
try {
week = new Access(Xml.parse(Assets.getText(Paths.xml('weeks/weeks/$weekName'))).firstElement());
} catch(e) {
Logs.trace('Cannot parse week "$weekName.xml": ${Std.string(e)}`', ERROR);
}
if (week == null) continue;
if (!week.has.name) {
Logs.trace('Story Menu: Week at index ${k} has no name. Skipping...', WARNING);
continue;
}
var weekObj:WeekData = {
name: week.att.name,
sprite: week.getAtt('sprite').getDefault(weekName),
chars: [null, null, null],
songs: [],
difficulties: ['easy', 'normal', 'hard']
};
var diffNodes = week.nodes.difficulty;
if (diffNodes.length > 0) {
var diffs:Array<String> = [];
for(e in diffNodes) {
if (e.has.name) diffs.push(e.att.name);
}
if (diffs.length > 0)
weekObj.difficulties = diffs;
}
if (week.has.chars) {
for(k=>e in week.att.chars.split(",")) {
if (e.trim() == "" || e == "none" || e == "null")
weekObj.chars[k] = null;
else {
addCharacter(weekObj.chars[k] = e.trim());
}
}
}
for(k2=>song in week.nodes.song) {
if (song == null) continue;
try {
var name = song.innerData.trim();
if (name == "") {
Logs.trace('Story Menu: Song at index ${k2} in week ${weekObj.name} has no name. Skipping...', WARNING);
continue;
}
weekObj.songs.push({
name: name,
hide: song.getAtt('hide').getDefault('false') == "true"
});
} catch(e) {
Logs.trace('Story Menu: Song at index ${k2} in week ${weekObj.name} cannot contain any other XML nodes in its name.', WARNING);
continue;
}
}
if (weekObj.songs.length <= 0) {
Logs.trace('Story Menu: Week ${weekObj.name} has no songs. Skipping...', WARNING);
continue;
}
this.weeks.push(weekObj);
}
}
public function addCharacter(charName:String) {
var char:Access = null;
try {
char = new Access(Xml.parse(Assets.getText(Paths.xml('weeks/characters/$charName'))).firstElement());
} catch(e) {
Logs.trace('Story Menu: Cannot parse character "$charName.xml": ${Std.string(e)}`', ERROR);
}
if (char == null) return;
if (characters[charName] != null) return;
var charObj:MenuCharacter = {
spritePath: Paths.image(char.getAtt('sprite').getDefault('menus/storymenu/characters/${charName}')),
scale: Std.parseFloat(char.getAtt('scale')).getDefault(1),
xml: char,
offset: FlxPoint.get(
Std.parseFloat(char.getAtt('x')).getDefault(0),
Std.parseFloat(char.getAtt('y')).getDefault(0)
)
};
characters[charName] = charObj;
}
public function getWeeksFromSource(weeks:Array<String>, source:funkin.system.AssetsLibraryList.AssetSource) {
var path:String = Paths.txt('freeplaySonglist');
var weeksFound:Array<String> = [];
if (Paths.assetsTree.existsSpecific(path, "TEXT", source)) {
var trim = "";
weeksFound = CoolUtil.coolTextFile(Paths.txt('weeks/weeks'));
} else {
weeksFound = [for(c in Paths.getFolderContent('data/weeks/weeks/', false, source)) if (Path.extension(c).toLowerCase() == "xml") Path.withoutExtension(c)];
}
if (weeksFound.length > 0) {
for(s in weeksFound)
weeks.push(s);
return false;
}
return true;
}
public override function destroy() {
@@ -241,71 +352,9 @@ class StoryMenuState extends MusicBeatState {
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('sprite').getDefault('menus/storymenu/characters/${char.att.name}')),
scale: Std.parseFloat(char.getAtt('scale')).getDefault(1),
xml: char,
offset: FlxPoint.get(
Std.parseFloat(char.getAtt('x')).getDefault(0),
Std.parseFloat(char.getAtt('y')).getDefault(0)
)
};
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: [],
difficulties: ['easy', 'normal', 'hard']
};
var diffNodes = week.nodes.difficulty;
if (diffNodes.length > 0) {
var diffs:Array<String> = [];
for(e in diffNodes) {
if (e.has.name) diffs.push(e.att.name);
}
if (diffs.length > 0)
weekObj.difficulties = diffs;
}
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: song.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);
}
}
}
} catch(e) {
+2 -1
View File
@@ -204,7 +204,8 @@ class CoolUtil
public static function coolTextFile(path:String):Array<String>
{
return [for(e in Assets.getText(path).trim().split('\n')) e.trim()];
var trim:String;
return [for(line in Assets.getText(path).split("\n")) if ((trim = line.trim()) != "" && !trim.startsWith("#")) trim];
}
public static inline function numberArray(max:Int, ?min:Int = 0):Array<Int>