Fix issues from newly found class type

This commit is contained in:
Tom Bloor 2019-10-22 00:21:59 +01:00
parent ad439e4832
commit 1b06d9ca94
Signed by: TBSliver
GPG key ID: 4657C7EBE42CC5CC
3 changed files with 27 additions and 19 deletions

View file

@ -100,7 +100,7 @@ stringval "string value"
class = key:stringkey singlequote_mark chars:pathchar* singlequote_mark { return [ key, chars.join("") ]; } 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:( pathchar = sequence:(
[a-zA-Z0-9] [a-zA-Z0-9]

View file

@ -1,9 +1,9 @@
function deparseJson(input) { function deparseJson(input, key) {
switch (typeof input) { switch (typeof input) {
case "object": case "object":
return deparseObject(input); return deparseObject(input);
case "number": case "number":
return deparseNumber(input); return deparseNumber(input, key);
case "string": case "string":
return deparseString(input); return deparseString(input);
case "undefined": case "undefined":
@ -35,7 +35,7 @@ function deparseObject(input) {
Object.keys(input).forEach(function (key, idx, array) { Object.keys(input).forEach(function (key, idx, array) {
output += key; output += key;
output += nameSeparator; output += nameSeparator;
output += deparseJson(input[key]); output += deparseJson(input[key], key);
if (idx !== array.length - 1) { if (idx !== array.length - 1) {
// Not the last item // Not the last item
@ -49,14 +49,20 @@ function deparseObject(input) {
function deparseArray(input) { function deparseArray(input) {
// We have one funky array option, where its 2 values and one of them is a recognised class. // We have one funky array option, where its 2 values and one of them is a recognised class.
if (input[0] === "BlueprintGeneratedClass") { // These are here for easier maintenance, as adding any new ones should just work. These all
return "BlueprintGeneratedClass" + "'" + input[1] + "'"; // Work off string equality, see found below.
} var specialCases = [
if (input[0] === "Blueprint") { 'BlueprintGeneratedClass',
return "Blueprint" + "'" + input[1] + "'"; 'Blueprint',
} 'SoundWave',
if (input[0] === "SoundWave") { 'Texture2D'
return "SoundWave" + "'" + input[1] + "'" ];
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 = '('; var beginObject = '(';
@ -78,8 +84,15 @@ function deparseArray(input) {
return output; return output;
} }
function deparseNumber(input) { function deparseNumber(input, key) {
// All numbers seem to be a string to 6 decimal places // 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); return Number(input).toFixed(6);
} }

View file

@ -23,11 +23,6 @@ function fromAtlasToJson() {
function fromJsonToAtlas() { function fromJsonToAtlas() {
var input = JSON.parse(jsonEditor.getValue()); var input = JSON.parse(jsonEditor.getValue());
console.log(input);
var output = deparseJson(input); var output = deparseJson(input);
console.log(output);
atlasEditor.setValue(output); atlasEditor.setValue(output);
} }