From 1b06d9ca942f59f27f8b3d203e2261560a1c6729 Mon Sep 17 00:00:00 2001 From: Tom Bloor Date: Tue, 22 Oct 2019 00:21:59 +0100 Subject: [PATCH] Fix issues from newly found class type --- js/atlas.pegjs | 2 +- js/atlas_reparser.js | 39 ++++++++++++++++++++++++++------------- js/parser_test.js | 5 ----- 3 files changed, 27 insertions(+), 19 deletions(-) diff --git a/js/atlas.pegjs b/js/atlas.pegjs index a2b5303..3cfc523 100644 --- a/js/atlas.pegjs +++ b/js/atlas.pegjs @@ -100,7 +100,7 @@ stringval "string value" class = key:stringkey singlequote_mark chars:pathchar* singlequote_mark { return [ key, chars.join("") ]; } -keychar = sequence:( [a-zA-Z] / "_" ) { return sequence; } +keychar = sequence:( [a-zA-Z0-9] / "_" ) { return sequence; } pathchar = sequence:( [a-zA-Z0-9] diff --git a/js/atlas_reparser.js b/js/atlas_reparser.js index 72070e9..a194575 100644 --- a/js/atlas_reparser.js +++ b/js/atlas_reparser.js @@ -1,9 +1,9 @@ -function deparseJson(input) { +function deparseJson(input, key) { switch (typeof input) { case "object": return deparseObject(input); case "number": - return deparseNumber(input); + return deparseNumber(input, key); case "string": return deparseString(input); case "undefined": @@ -35,7 +35,7 @@ function deparseObject(input) { Object.keys(input).forEach(function (key, idx, array) { output += key; output += nameSeparator; - output += deparseJson(input[key]); + output += deparseJson(input[key], key); if (idx !== array.length - 1) { // Not the last item @@ -49,14 +49,20 @@ function deparseObject(input) { function deparseArray(input) { // We have one funky array option, where its 2 values and one of them is a recognised class. - if (input[0] === "BlueprintGeneratedClass") { - return "BlueprintGeneratedClass" + "'" + input[1] + "'"; - } - if (input[0] === "Blueprint") { - return "Blueprint" + "'" + input[1] + "'"; - } - if (input[0] === "SoundWave") { - return "SoundWave" + "'" + input[1] + "'" + // These are here for easier maintenance, as adding any new ones should just work. These all + // Work off string equality, see found below. + var specialCases = [ + 'BlueprintGeneratedClass', + 'Blueprint', + 'SoundWave', + 'Texture2D' + ]; + + var found = specialCases.indexOf(input[0]); + if (found > -1) { + // We found one of our special cases! + var val = specialCases[found]; + return val + "'" + input[1] + "'"; } var beginObject = '('; @@ -78,8 +84,15 @@ function deparseArray(input) { return output; } -function deparseNumber(input) { - // All numbers seem to be a string to 6 decimal places +function deparseNumber(input, key) { + // Any number which has a decimal is stored to 6 decimal places + // Except for IDs. Unless they actually have such a number... erm... + if (key.substr(key.length - 2, 2) === "ID") { + if (input % 1 === 0) { + return Number(input).toString(); + } + // Else drop out and return as normal + } return Number(input).toFixed(6); } diff --git a/js/parser_test.js b/js/parser_test.js index 80240a5..dffd135 100644 --- a/js/parser_test.js +++ b/js/parser_test.js @@ -23,11 +23,6 @@ function fromAtlasToJson() { function fromJsonToAtlas() { var input = JSON.parse(jsonEditor.getValue()); - - console.log(input); - var output = deparseJson(input); - - console.log(output); atlasEditor.setValue(output); } \ No newline at end of file