Make sure JSON data uses latest version/generatedBy when writing.

This commit is contained in:
EliteMasterEric 2024-05-31 19:21:21 -04:00
parent 06daa9d402
commit 9088570b92
5 changed files with 44 additions and 2 deletions

View file

@ -117,6 +117,9 @@ class SongMetadata implements ICloneable<SongMetadata>
*/ */
public function serialize(pretty:Bool = true):String public function serialize(pretty:Bool = true):String
{ {
// Update generatedBy and version before writing.
updateVersionToLatest();
var ignoreNullOptionals = true; var ignoreNullOptionals = true;
var writer = new json2object.JsonWriter<SongMetadata>(ignoreNullOptionals); var writer = new json2object.JsonWriter<SongMetadata>(ignoreNullOptionals);
// I believe @:jignored should be ignored by the writer? // I believe @:jignored should be ignored by the writer?
@ -125,6 +128,12 @@ class SongMetadata implements ICloneable<SongMetadata>
return writer.write(this, pretty ? ' ' : null); return writer.write(this, pretty ? ' ' : null);
} }
public function updateVersionToLatest():Void
{
this.version = SongRegistry.SONG_METADATA_VERSION;
this.generatedBy = SongRegistry.DEFAULT_GENERATEDBY;
}
/** /**
* Produces a string representation suitable for debugging. * Produces a string representation suitable for debugging.
*/ */
@ -373,6 +382,12 @@ class SongMusicData implements ICloneable<SongMusicData>
this.variation = variation == null ? Constants.DEFAULT_VARIATION : variation; this.variation = variation == null ? Constants.DEFAULT_VARIATION : variation;
} }
public function updateVersionToLatest():Void
{
this.version = SongRegistry.SONG_MUSIC_DATA_VERSION;
this.generatedBy = SongRegistry.DEFAULT_GENERATEDBY;
}
public function clone():SongMusicData public function clone():SongMusicData
{ {
var result:SongMusicData = new SongMusicData(this.songName, this.artist, this.variation); var result:SongMusicData = new SongMusicData(this.songName, this.artist, this.variation);
@ -605,11 +620,20 @@ class SongChartData implements ICloneable<SongChartData>
*/ */
public function serialize(pretty:Bool = true):String public function serialize(pretty:Bool = true):String
{ {
// Update generatedBy and version before writing.
updateVersionToLatest();
var ignoreNullOptionals = true; var ignoreNullOptionals = true;
var writer = new json2object.JsonWriter<SongChartData>(ignoreNullOptionals); var writer = new json2object.JsonWriter<SongChartData>(ignoreNullOptionals);
return writer.write(this, pretty ? ' ' : null); return writer.write(this, pretty ? ' ' : null);
} }
public function updateVersionToLatest():Void
{
this.version = SongRegistry.SONG_CHART_DATA_VERSION;
this.generatedBy = SongRegistry.DEFAULT_GENERATEDBY;
}
public function clone():SongChartData public function clone():SongChartData
{ {
// We have to manually perform the deep clone here because Map.deepClone() doesn't work. // We have to manually perform the deep clone here because Map.deepClone() doesn't work.

View file

@ -61,10 +61,18 @@ class ChartManifestData
*/ */
public function serialize(pretty:Bool = true):String public function serialize(pretty:Bool = true):String
{ {
// Update generatedBy and version before writing.
updateVersionToLatest();
var writer = new json2object.JsonWriter<ChartManifestData>(); var writer = new json2object.JsonWriter<ChartManifestData>();
return writer.write(this, pretty ? ' ' : null); return writer.write(this, pretty ? ' ' : null);
} }
public function updateVersionToLatest():Void
{
this.version = CHART_MANIFEST_DATA_VERSION;
}
public static function deserialize(contents:String):Null<ChartManifestData> public static function deserialize(contents:String):Null<ChartManifestData>
{ {
var parser = new json2object.JsonParser<ChartManifestData>(); var parser = new json2object.JsonParser<ChartManifestData>();

View file

@ -58,9 +58,17 @@ class StageData
*/ */
public function serialize(pretty:Bool = true):String public function serialize(pretty:Bool = true):String
{ {
// Update generatedBy and version before writing.
updateVersionToLatest();
var writer = new json2object.JsonWriter<StageData>(); var writer = new json2object.JsonWriter<StageData>();
return writer.write(this, pretty ? ' ' : null); return writer.write(this, pretty ? ' ' : null);
} }
public function updateVersionToLatest():Void
{
this.version = StageRegistry.STAGE_DATA_VERSION;
}
} }
typedef StageDataCharacters = typedef StageDataCharacters =

View file

@ -54,7 +54,7 @@ class CreditsDataHandler
body: [ body: [
{line: 'ninjamuffin99'}, {line: 'ninjamuffin99'},
{line: 'PhantomArcade'}, {line: 'PhantomArcade'},
{line: 'KawaiSprite'}, {line: 'Kawai Sprite'},
{line: 'evilsk8r'}, {line: 'evilsk8r'},
] ]
} }

View file

@ -386,12 +386,14 @@ class ChartEditorImportExportHandler
var variationMetadata:Null<SongMetadata> = state.songMetadata.get(variation); var variationMetadata:Null<SongMetadata> = state.songMetadata.get(variation);
if (variationMetadata != null) if (variationMetadata != null)
{ {
variationMetadata.version = funkin.data.song.SongRegistry.SONG_METADATA_VERSION;
variationMetadata.generatedBy = funkin.data.song.SongRegistry.DEFAULT_GENERATEDBY; variationMetadata.generatedBy = funkin.data.song.SongRegistry.DEFAULT_GENERATEDBY;
zipEntries.push(FileUtil.makeZIPEntry('${state.currentSongId}-metadata.json', variationMetadata.serialize())); zipEntries.push(FileUtil.makeZIPEntry('${state.currentSongId}-metadata.json', variationMetadata.serialize()));
} }
var variationChart:Null<SongChartData> = state.songChartData.get(variation); var variationChart:Null<SongChartData> = state.songChartData.get(variation);
if (variationChart != null) if (variationChart != null)
{ {
variationChart.version = funkin.data.song.SongRegistry.SONG_CHART_DATA_VERSION;
variationChart.generatedBy = funkin.data.song.SongRegistry.DEFAULT_GENERATEDBY; variationChart.generatedBy = funkin.data.song.SongRegistry.DEFAULT_GENERATEDBY;
zipEntries.push(FileUtil.makeZIPEntry('${state.currentSongId}-chart.json', variationChart.serialize())); zipEntries.push(FileUtil.makeZIPEntry('${state.currentSongId}-chart.json', variationChart.serialize()));
} }
@ -401,12 +403,12 @@ class ChartEditorImportExportHandler
var variationMetadata:Null<SongMetadata> = state.songMetadata.get(variation); var variationMetadata:Null<SongMetadata> = state.songMetadata.get(variation);
if (variationMetadata != null) if (variationMetadata != null)
{ {
variationMetadata.generatedBy = funkin.data.song.SongRegistry.DEFAULT_GENERATEDBY;
zipEntries.push(FileUtil.makeZIPEntry('${state.currentSongId}-metadata-$variationId.json', variationMetadata.serialize())); zipEntries.push(FileUtil.makeZIPEntry('${state.currentSongId}-metadata-$variationId.json', variationMetadata.serialize()));
} }
var variationChart:Null<SongChartData> = state.songChartData.get(variation); var variationChart:Null<SongChartData> = state.songChartData.get(variation);
if (variationChart != null) if (variationChart != null)
{ {
variationChart.version = funkin.data.song.SongRegistry.SONG_CHART_DATA_VERSION;
variationChart.generatedBy = funkin.data.song.SongRegistry.DEFAULT_GENERATEDBY; variationChart.generatedBy = funkin.data.song.SongRegistry.DEFAULT_GENERATEDBY;
zipEntries.push(FileUtil.makeZIPEntry('${state.currentSongId}-chart-$variationId.json', variationChart.serialize())); zipEntries.push(FileUtil.makeZIPEntry('${state.currentSongId}-chart-$variationId.json', variationChart.serialize()));
} }