Update FreeplayState.hx (#669)

* Update FreeplayState.hx

* should be good

* pretty print the color

---------

Co-authored-by: ⍚~Nex <87421482+NexIsDumb@users.noreply.github.com>
This commit is contained in:
Nebula S. Nova
2025-07-05 01:06:57 +02:00
committed by GitHub
co-authored by ⍚~Nex
parent bd79dd2e39
commit 7a8f1f0ded
7 changed files with 32 additions and 34 deletions
+14 -12
View File
@@ -96,8 +96,11 @@ class Chart {
var fromMods:Bool = fromMods;
for (path in [metaDiffPath, metaPath]) if (Assets.exists(path)) {
fromMods = Paths.assetsTree.existsSpecific(path, "TEXT", MODS);
try data = Json.parse(Assets.getText(path))
catch(e) Logs.trace('Failed to load song metadata for ${songName} ($path): ${Std.string(e)}', ERROR);
try {
var tempData = Json.parse(Assets.getText(path));
tempData.color = CoolUtil.getColorFromDynamic(tempData.color).getDefault(defaultColor);
data = tempData;
} catch(e) Logs.trace('Failed to load song metadata for ${songName} ($path): ${Std.string(e)}', ERROR);
if (data != null) break;
}
@@ -115,7 +118,6 @@ class Chart {
data.setFieldDefault("coopAllowed", false);
data.setFieldDefault("opponentModeAllowed", false);
data.setFieldDefault("displayName", data.name);
data.setFieldDefault("parsedColor", data.color.getColorFromDynamic().getDefault(defaultColor));
if (data.difficulties.length <= 0) {
data.difficulties = [for(f in Paths.getFolderContent('songs/${songNameLower}/charts/', false, !fromMods)) if (Path.extension(f = f.toUpperCase()) == "JSON") Path.withoutExtension(f)];
@@ -257,33 +259,33 @@ class Chart {
CoolUtil.safeSaveFile(chartPath, Json.stringify(filteredChart, null, saveSettings.prettyPrint == true ? "\t" : null));
// idk how null reacts to it so better be sure
if (saveSettings.overrideExistingMeta == true || !FileSystem.exists(metaPath))
CoolUtil.safeSaveFile(metaPath, Json.stringify(meta, null, saveSettings.prettyPrint == true ? "\t" : null));
CoolUtil.safeSaveFile(metaPath, makeMetaSaveable(meta));
#end
return filteredChart;
}
public static function filterChartForSaving(chart:ChartData, ?saveMetaInChart:Null<Bool>, ?saveEventsInChart:Null<Bool>):ChartData {
var data = Reflect.copy(chart); // make a copy of the chart to leave the OG intact
if (saveMetaInChart != true) {
data.meta = null;
} else {
data.meta = Reflect.copy(chart.meta); // also make a copy of the metadata to leave the OG intact.
if(data.meta != null && Reflect.hasField(data.meta, "parsedColor")) Reflect.deleteField(data.meta, "parsedColor");
}
data.meta = saveMetaInChart != true ? null : data.meta = Reflect.copy(chart.meta); // also make a copy of the metadata to leave the OG intact.
data.events = saveEventsInChart != true ? null : Reflect.copy(chart.events); // same here once again
data.fromMods = null;
var sortedData:Dynamic = {};
for(f in Reflect.fields(data)) {
for (f in Reflect.fields(data)) {
var v = Reflect.field(data, f);
if (v != null)
Reflect.setField(sortedData, f, v);
}
return sortedData;
}
public static inline function makeMetaSaveable(meta:ChartMetaData, prettyPrint:Bool = true):String {
var data:Dynamic = Reflect.copy(meta);
if (data.color != null) data.color = new FlxColor(data.color).toWebString(); // dont even ask me - Nex
return Json.stringify(data, null, prettyPrint ? "\t" : null);
}
}
typedef ChartSaveSettings = {
+1 -4
View File
@@ -22,14 +22,11 @@ typedef ChartMetaData = {
public var ?stepsPerBeat:Float;
public var ?needsVoices:Bool;
public var ?icon:String;
public var ?color:Dynamic;
public var ?color:FlxColor;
public var ?difficulties:Array<String>;
public var ?coopAllowed:Bool;
public var ?opponentModeAllowed:Bool;
public var ?customValues:Dynamic;
// NOT TO BE EXPORTED
public var ?parsedColor:FlxColor;
}
typedef ChartStrumLine = {