diff --git a/source/funkin/backend/chart/Chart.hx b/source/funkin/backend/chart/Chart.hx index 15f732ca6..d7bbed6d3 100644 --- a/source/funkin/backend/chart/Chart.hx +++ b/source/funkin/backend/chart/Chart.hx @@ -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, ?saveEventsInChart:Null):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 = { diff --git a/source/funkin/backend/chart/ChartData.hx b/source/funkin/backend/chart/ChartData.hx index c46164f54..bc69d4bd3 100644 --- a/source/funkin/backend/chart/ChartData.hx +++ b/source/funkin/backend/chart/ChartData.hx @@ -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; public var ?coopAllowed:Bool; public var ?opponentModeAllowed:Bool; public var ?customValues:Dynamic; - - // NOT TO BE EXPORTED - public var ?parsedColor:FlxColor; } typedef ChartStrumLine = { diff --git a/source/funkin/editors/charter/Charter.hx b/source/funkin/editors/charter/Charter.hx index daf7aad2d..839853708 100644 --- a/source/funkin/editors/charter/Charter.hx +++ b/source/funkin/editors/charter/Charter.hx @@ -1338,7 +1338,7 @@ class Charter extends UIState { #if sys CoolUtil.safeSaveFile( '${Paths.getAssetsRoot()}/songs/${__song.toLowerCase()}/meta.json', - Json.stringify(PlayState.SONG.meta == null ? {} : PlayState.SONG.meta, null, "\t") + PlayState.SONG.meta == null ? null : Chart.makeMetaSaveable(PlayState.SONG.meta) ); #else _file_meta_saveas(_); @@ -1346,7 +1346,7 @@ class Charter extends UIState { } function _file_meta_saveas(_) { - openSubState(new SaveSubstate(Json.stringify(PlayState.SONG.meta == null ? {} : PlayState.SONG.meta, null, "\t"), { // always pretty print meta + openSubState(new SaveSubstate(PlayState.SONG.meta == null ? null : Chart.makeMetaSaveable(PlayState.SONG.meta), { // always pretty print meta defaultSaveFile: 'meta.json' })); } diff --git a/source/funkin/editors/charter/CharterMetaDataScreen.hx b/source/funkin/editors/charter/CharterMetaDataScreen.hx index e58898c08..ddb7e3220 100644 --- a/source/funkin/editors/charter/CharterMetaDataScreen.hx +++ b/source/funkin/editors/charter/CharterMetaDataScreen.hx @@ -91,7 +91,7 @@ class CharterMetaDataScreen extends UISubstateWindow { coopAllowedCheckbox = new UICheckbox(opponentModeCheckbox.x + 150 + 26, opponentModeCheckbox.y, "Co-op Mode", metadata.coopAllowed); add(coopAllowedCheckbox); - colorWheel = new UIColorwheel(iconTextBox.x, coopAllowedCheckbox.y, metadata.parsedColor); + colorWheel = new UIColorwheel(iconTextBox.x, coopAllowedCheckbox.y, metadata.color); add(colorWheel); addLabelOn(colorWheel, "Color"); @@ -158,8 +158,7 @@ class CharterMetaDataScreen extends UISubstateWindow { needsVoices: needsVoicesCheckbox.checked, displayName: displayNameTextBox.label.text, icon: iconTextBox.label.text, - color: colorWheel.curColorString, - parsedColor: colorWheel.curColor, + color: colorWheel.curColor, opponentModeAllowed: opponentModeCheckbox.checked, coopAllowed: coopAllowedCheckbox.checked, difficulties: [for (diff in difficulitesTextBox.label.text.split(",")) diff.trim()], diff --git a/source/funkin/editors/charter/CharterSelection.hx b/source/funkin/editors/charter/CharterSelection.hx index 6fd97bdcd..e630c9317 100644 --- a/source/funkin/editors/charter/CharterSelection.hx +++ b/source/funkin/editors/charter/CharterSelection.hx @@ -1,15 +1,16 @@ package funkin.editors.charter; -import funkin.backend.chart.ChartData; +import funkin.backend.chart.Chart; import funkin.backend.chart.ChartData.ChartMetaData; -import haxe.Json; -import funkin.editors.charter.SongCreationScreen.SongCreationData; -import funkin.options.type.NewOption; +import funkin.backend.chart.ChartData; import funkin.backend.system.framerate.Framerate; -import funkin.menus.FreeplayState.FreeplaySonglist; import funkin.editors.EditorTreeMenu; +import funkin.editors.charter.SongCreationScreen.SongCreationData; +import funkin.menus.FreeplayState.FreeplaySonglist; import funkin.options.*; import funkin.options.type.*; +import funkin.options.type.NewOption; +import haxe.Json; using StringTools; @@ -38,7 +39,7 @@ class CharterSelection extends EditorTreeMenu { FlxG.state.openSubState(new ChartCreationScreen(saveChart)); })); optionsTree.add(new OptionsScreen(s.name, "Select a difficulty to continue.", list)); - }, s.parsedColor.getDefault(0xFFFFFFFF)) + }, s.color.getDefault(0xFFFFFFFF)) ]; list.insert(0, new NewOption("New Song", "New Song", function() { @@ -109,7 +110,7 @@ class CharterSelection extends EditorTreeMenu { sys.FileSystem.createDirectory('$songFolder/charts'); // Save Files - CoolUtil.safeSaveFile('$songFolder/meta.json', Json.stringify(creation.meta, "\t")); + CoolUtil.safeSaveFile('$songFolder/meta.json', Chart.makeMetaSaveable(creation.meta)); if (creation.instBytes != null) sys.io.File.saveBytes('$songFolder/song/Inst.${Paths.SOUND_EXT}', creation.instBytes); if (creation.voicesBytes != null) sys.io.File.saveBytes('$songFolder/song/Voices.${Paths.SOUND_EXT}', creation.voicesBytes); #end @@ -126,7 +127,7 @@ class CharterSelection extends EditorTreeMenu { FlxG.state.openSubState(new ChartCreationScreen(saveChart)); })); optionsTree.insert(1, new OptionsScreen(creation.meta.name, "Select a difficulty to continue.", list)); - }, creation.meta.parsedColor.getDefault(0xFFFFFFFF)); + }, creation.meta.color.getDefault(0xFFFFFFFF)); // Add to List freeplayList.songs.insert(0, creation.meta); @@ -160,7 +161,7 @@ class CharterSelection extends EditorTreeMenu { var meta = Json.parse(sys.io.File.getContent('$songFolder/meta.json')); if (meta.difficulties != null && !meta.difficulties.contains(name)) { meta.difficulties.push(name); - CoolUtil.safeSaveFile('$songFolder/meta.json', Json.stringify(meta)); + CoolUtil.safeSaveFile('$songFolder/meta.json', Chart.makeMetaSaveable(meta)); } } } \ No newline at end of file diff --git a/source/funkin/editors/charter/SongCreationScreen.hx b/source/funkin/editors/charter/SongCreationScreen.hx index 007c8f6c0..d752f42d0 100644 --- a/source/funkin/editors/charter/SongCreationScreen.hx +++ b/source/funkin/editors/charter/SongCreationScreen.hx @@ -254,8 +254,7 @@ class SongCreationScreen extends UISubstateWindow { needsVoices: needsVoicesCheckbox.checked, displayName: displayNameTextBox.label.text, icon: iconTextBox.label.text, - color: colorWheel.curColorString, - parsedColor: colorWheel.curColor, + color: colorWheel.curColor, opponentModeAllowed: opponentModeCheckbox.checked, coopAllowed: coopAllowedCheckbox.checked, difficulties: [for (diff in difficulitesTextBox.label.text.split(",")) diff.trim()], diff --git a/source/funkin/menus/FreeplayState.hx b/source/funkin/menus/FreeplayState.hx index fc56054ae..2a7cf8f5e 100644 --- a/source/funkin/menus/FreeplayState.hx +++ b/source/funkin/menus/FreeplayState.hx @@ -234,7 +234,7 @@ class FreeplayState extends MusicBeatState scoreText.x = coopText.x = scoreBG.x + 4; diffText.x = Std.int(scoreBG.x + ((scoreBG.width - diffText.width) / 2)); - interpColor.fpsLerpTo(songs[curSelected].parsedColor, 0.0625); + interpColor.fpsLerpTo(songs[curSelected].color, 0.0625); bg.color = interpColor.color; #if PRELOAD_ALL @@ -456,4 +456,4 @@ class FreeplaySonglist { return songList; } -} \ No newline at end of file +}