mirror of
https://github.com/FunkinCrew/Funkin.git
synced 2024-11-29 11:06:00 -05:00
Fixes to the FNF Legacy JSON parser
This commit is contained in:
parent
9e27095659
commit
4ff5bd21df
10 changed files with 83 additions and 11 deletions
|
@ -178,7 +178,31 @@ class DataParse
|
|||
switch (json.value)
|
||||
{
|
||||
case JObject(fields):
|
||||
return cast Tools.getValue(json);
|
||||
var result:LegacyNoteSection =
|
||||
{
|
||||
mustHitSection: false,
|
||||
sectionNotes: [],
|
||||
};
|
||||
for (field in fields)
|
||||
{
|
||||
switch (field.name)
|
||||
{
|
||||
case 'sectionNotes':
|
||||
result.sectionNotes = legacyNotes(field.value, field.name);
|
||||
|
||||
case 'mustHitSection':
|
||||
result.mustHitSection = Tools.getValue(field.value);
|
||||
case 'typeOfSection':
|
||||
result.typeOfSection = Tools.getValue(field.value);
|
||||
case 'lengthInSteps':
|
||||
result.lengthInSteps = Tools.getValue(field.value);
|
||||
case 'changeBPM':
|
||||
result.changeBPM = Tools.getValue(field.value);
|
||||
case 'bpm':
|
||||
result.bpm = Tools.getValue(field.value);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
default:
|
||||
throw 'Expected property $name to be an object, but it was ${json.value}.';
|
||||
}
|
||||
|
@ -189,7 +213,12 @@ class DataParse
|
|||
switch (json.value)
|
||||
{
|
||||
case JObject(fields):
|
||||
return cast Tools.getValue(json);
|
||||
var result = {};
|
||||
for (field in fields)
|
||||
{
|
||||
Reflect.setField(result, field.name, legacyNoteSectionArray(field.value, field.name));
|
||||
}
|
||||
return result;
|
||||
default:
|
||||
throw 'Expected property $name to be an object, but it was ${json.value}.';
|
||||
}
|
||||
|
@ -211,13 +240,13 @@ class DataParse
|
|||
switch (json.value)
|
||||
{
|
||||
case JArray(values):
|
||||
// var time:Null<Float> = values[0] == null ? null : Tools.getValue(values[0]);
|
||||
// var data:Null<Int> = values[1] == null ? null : Tools.getValue(values[1]);
|
||||
// var length:Null<Float> = values[2] == null ? null : Tools.getValue(values[2]);
|
||||
// var alt:Null<Bool> = values[3] == null ? null : Tools.getValue(values[3]);
|
||||
var time:Null<Float> = values[0] == null ? null : Tools.getValue(values[0]);
|
||||
var data:Null<Int> = values[1] == null ? null : Tools.getValue(values[1]);
|
||||
var length:Null<Float> = values[2] == null ? null : Tools.getValue(values[2]);
|
||||
var alt:Null<Bool> = values[3] == null ? null : Tools.getValue(values[3]);
|
||||
|
||||
// return new LegacyNote(time, data, length, alt);
|
||||
return null;
|
||||
return new LegacyNote(time, data, length, alt);
|
||||
// return null;
|
||||
default:
|
||||
throw 'Expected property $name to be a note, but it was ${json.value}.';
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ class LevelRegistry extends BaseRegistry<Level, LevelData>
|
|||
// JsonParser does not take type parameters,
|
||||
// otherwise this function would be in BaseRegistry.
|
||||
var parser = new json2object.JsonParser<LevelData>();
|
||||
parser.ignoreUnknownVariables = false;
|
||||
|
||||
switch (loadEntryFile(id))
|
||||
{
|
||||
|
@ -57,6 +58,7 @@ class LevelRegistry extends BaseRegistry<Level, LevelData>
|
|||
public function parseEntryDataRaw(contents:String, ?fileName:String):Null<LevelData>
|
||||
{
|
||||
var parser = new json2object.JsonParser<LevelData>();
|
||||
parser.ignoreUnknownVariables = false;
|
||||
parser.fromJson(contents, fileName);
|
||||
|
||||
if (parser.errors.length > 0)
|
||||
|
|
|
@ -35,6 +35,7 @@ class NoteStyleRegistry extends BaseRegistry<NoteStyle, NoteStyleData>
|
|||
// JsonParser does not take type parameters,
|
||||
// otherwise this function would be in BaseRegistry.
|
||||
var parser = new json2object.JsonParser<NoteStyleData>();
|
||||
parser.ignoreUnknownVariables = false;
|
||||
|
||||
switch (loadEntryFile(id))
|
||||
{
|
||||
|
@ -62,6 +63,7 @@ class NoteStyleRegistry extends BaseRegistry<NoteStyle, NoteStyleData>
|
|||
public function parseEntryDataRaw(contents:String, ?fileName:String):Null<NoteStyleData>
|
||||
{
|
||||
var parser = new json2object.JsonParser<NoteStyleData>();
|
||||
parser.ignoreUnknownVariables = false;
|
||||
parser.fromJson(contents, fileName);
|
||||
|
||||
if (parser.errors.length > 0)
|
||||
|
|
|
@ -747,7 +747,7 @@ class SongNoteDataRaw
|
|||
/**
|
||||
* The kind of the note.
|
||||
* This can allow the note to include information used for custom behavior.
|
||||
* Defaults to blank or `"normal"`.
|
||||
* Defaults to blank or `Constants.DEFAULT_DIFFICULTY`.
|
||||
*/
|
||||
@:alias("k")
|
||||
@:default("normal")
|
||||
|
|
|
@ -230,6 +230,7 @@ class SongDataUtils
|
|||
trace('Read ${notesString.length} characters from clipboard.');
|
||||
|
||||
var parser = new json2object.JsonParser<SongClipboardItems>();
|
||||
parser.ignoreUnknownVariables = false;
|
||||
parser.fromJson(notesString, 'clipboard');
|
||||
if (parser.errors.length > 0)
|
||||
{
|
||||
|
|
|
@ -126,6 +126,8 @@ class SongRegistry extends BaseRegistry<Song, SongMetadata>
|
|||
variation = variation == null ? Constants.DEFAULT_VARIATION : variation;
|
||||
|
||||
var parser = new json2object.JsonParser<SongMetadata>();
|
||||
parser.ignoreUnknownVariables = false;
|
||||
|
||||
switch (loadEntryMetadataFile(id, variation))
|
||||
{
|
||||
case {fileName: fileName, contents: contents}:
|
||||
|
@ -147,6 +149,7 @@ class SongRegistry extends BaseRegistry<Song, SongMetadata>
|
|||
variation = variation == null ? Constants.DEFAULT_VARIATION : variation;
|
||||
|
||||
var parser = new json2object.JsonParser<SongMetadata>();
|
||||
parser.ignoreUnknownVariables = false;
|
||||
parser.fromJson(contents, fileName);
|
||||
|
||||
if (parser.errors.length > 0)
|
||||
|
@ -206,6 +209,8 @@ class SongRegistry extends BaseRegistry<Song, SongMetadata>
|
|||
variation = variation == null ? Constants.DEFAULT_VARIATION : variation;
|
||||
|
||||
var parser = new json2object.JsonParser<SongMetadata_v2_1_0>();
|
||||
parser.ignoreUnknownVariables = false;
|
||||
|
||||
switch (loadEntryMetadataFile(id, variation))
|
||||
{
|
||||
case {fileName: fileName, contents: contents}:
|
||||
|
@ -226,6 +231,8 @@ class SongRegistry extends BaseRegistry<Song, SongMetadata>
|
|||
variation = variation == null ? Constants.DEFAULT_VARIATION : variation;
|
||||
|
||||
var parser = new json2object.JsonParser<SongMetadata_v2_0_0>();
|
||||
parser.ignoreUnknownVariables = false;
|
||||
|
||||
switch (loadEntryMetadataFile(id, variation))
|
||||
{
|
||||
case {fileName: fileName, contents: contents}:
|
||||
|
@ -244,6 +251,7 @@ class SongRegistry extends BaseRegistry<Song, SongMetadata>
|
|||
function parseEntryMetadataRaw_v2_1_0(contents:String, ?fileName:String = 'raw'):Null<SongMetadata>
|
||||
{
|
||||
var parser = new json2object.JsonParser<SongMetadata_v2_1_0>();
|
||||
parser.ignoreUnknownVariables = false;
|
||||
parser.fromJson(contents, fileName);
|
||||
|
||||
if (parser.errors.length > 0)
|
||||
|
@ -257,6 +265,7 @@ class SongRegistry extends BaseRegistry<Song, SongMetadata>
|
|||
function parseEntryMetadataRaw_v2_0_0(contents:String, ?fileName:String = 'raw'):Null<SongMetadata>
|
||||
{
|
||||
var parser = new json2object.JsonParser<SongMetadata_v2_0_0>();
|
||||
parser.ignoreUnknownVariables = false;
|
||||
parser.fromJson(contents, fileName);
|
||||
|
||||
if (parser.errors.length > 0)
|
||||
|
@ -272,6 +281,8 @@ class SongRegistry extends BaseRegistry<Song, SongMetadata>
|
|||
variation = variation == null ? Constants.DEFAULT_VARIATION : variation;
|
||||
|
||||
var parser = new json2object.JsonParser<SongMusicData>();
|
||||
parser.ignoreUnknownVariables = false;
|
||||
|
||||
switch (loadMusicDataFile(id, variation))
|
||||
{
|
||||
case {fileName: fileName, contents: contents}:
|
||||
|
@ -291,6 +302,7 @@ class SongRegistry extends BaseRegistry<Song, SongMetadata>
|
|||
public function parseMusicDataRaw(contents:String, ?fileName:String = 'raw'):Null<SongMusicData>
|
||||
{
|
||||
var parser = new json2object.JsonParser<SongMusicData>();
|
||||
parser.ignoreUnknownVariables = false;
|
||||
parser.fromJson(contents, fileName);
|
||||
|
||||
if (parser.errors.length > 0)
|
||||
|
@ -334,6 +346,7 @@ class SongRegistry extends BaseRegistry<Song, SongMetadata>
|
|||
variation = variation == null ? Constants.DEFAULT_VARIATION : variation;
|
||||
|
||||
var parser = new json2object.JsonParser<SongChartData>();
|
||||
parser.ignoreUnknownVariables = false;
|
||||
|
||||
switch (loadEntryChartFile(id, variation))
|
||||
{
|
||||
|
@ -356,6 +369,7 @@ class SongRegistry extends BaseRegistry<Song, SongMetadata>
|
|||
variation = variation == null ? Constants.DEFAULT_VARIATION : variation;
|
||||
|
||||
var parser = new json2object.JsonParser<SongChartData>();
|
||||
parser.ignoreUnknownVariables = false;
|
||||
parser.fromJson(contents, fileName);
|
||||
|
||||
if (parser.errors.length > 0)
|
||||
|
|
|
@ -68,6 +68,7 @@ class ChartManifestData
|
|||
public static function deserialize(contents:String):Null<ChartManifestData>
|
||||
{
|
||||
var parser = new json2object.JsonParser<ChartManifestData>();
|
||||
parser.ignoreUnknownVariables = false;
|
||||
parser.fromJson(contents, 'manifest.json');
|
||||
|
||||
if (parser.errors.length > 0)
|
||||
|
|
|
@ -19,7 +19,8 @@ class LegacySongData
|
|||
|
||||
@:jcustomparse(funkin.data.DataParse.eitherLegacyScrollSpeeds)
|
||||
public var speed:Either<Float, LegacyScrollSpeeds>;
|
||||
public var stageDefault:String;
|
||||
@:optional
|
||||
public var stageDefault:Null<String>;
|
||||
public var bpm:Float;
|
||||
|
||||
@:jcustomparse(funkin.data.DataParse.eitherLegacyNoteData)
|
||||
|
|
|
@ -14,6 +14,7 @@ class FNFLegacyImporter
|
|||
public static function parseLegacyDataRaw(input:String, fileName:String = 'raw'):FNFLegacyData
|
||||
{
|
||||
var parser = new json2object.JsonParser<FNFLegacyData>();
|
||||
parser.ignoreUnknownVariables = true; // Set to true to ignore extra variables that might be included in the JSON.
|
||||
parser.fromJson(input, fileName);
|
||||
|
||||
if (parser.errors.length > 0)
|
||||
|
@ -185,15 +186,34 @@ class FNFLegacyImporter
|
|||
return result;
|
||||
}
|
||||
|
||||
static final STRUMLINE_SIZE = 4;
|
||||
|
||||
static function migrateNoteSections(input:Array<LegacyNoteSection>):Array<SongNoteData>
|
||||
{
|
||||
var result:Array<SongNoteData> = [];
|
||||
|
||||
for (section in input)
|
||||
{
|
||||
var mustHitSection = section.mustHitSection ?? false;
|
||||
for (note in section.sectionNotes)
|
||||
{
|
||||
result.push(new SongNoteData(note.time, note.data, note.length, note.getKind()));
|
||||
// Handle the dumb logic for mustHitSection.
|
||||
var noteData = note.data;
|
||||
|
||||
// Flip notes if mustHitSection is FALSE (not true lol).
|
||||
if (!mustHitSection)
|
||||
{
|
||||
if (noteData >= STRUMLINE_SIZE)
|
||||
{
|
||||
noteData -= STRUMLINE_SIZE;
|
||||
}
|
||||
else
|
||||
{
|
||||
noteData += STRUMLINE_SIZE;
|
||||
}
|
||||
}
|
||||
|
||||
result.push(new SongNoteData(note.time, noteData, note.length, note.getKind()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -156,6 +156,7 @@ class MyTypeRegistry extends BaseRegistry<MyType, MyTypeData>
|
|||
// JsonParser does not take type parameters,
|
||||
// otherwise this function would be in BaseRegistry.
|
||||
var parser = new json2object.JsonParser<MyTypeData>();
|
||||
parser.ignoreUnknownVariables = false;
|
||||
|
||||
switch (loadEntryFile(id))
|
||||
{
|
||||
|
@ -181,6 +182,7 @@ class MyTypeRegistry extends BaseRegistry<MyType, MyTypeData>
|
|||
// JsonParser does not take type parameters,
|
||||
// otherwise this function would be in BaseRegistry.
|
||||
var parser = new json2object.JsonParser<MyTypeData_v0_1_x>();
|
||||
parser.ignoreUnknownVariables = false;
|
||||
|
||||
switch (loadEntryFile(id))
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue