97 lines
No EOL
2.2 KiB
JavaScript
97 lines
No EOL
2.2 KiB
JavaScript
function deparseJson(input) {
|
|
switch (typeof input) {
|
|
case "object":
|
|
return deparseObject(input);
|
|
case "number":
|
|
return deparseNumber(input);
|
|
case "string":
|
|
return deparseString(input);
|
|
case "undefined":
|
|
return "";
|
|
case "boolean":
|
|
return deparseBoolean(input);
|
|
default:
|
|
console.log("Unknown type for input", input);
|
|
return "";
|
|
}
|
|
}
|
|
|
|
function deparseObject(input) {
|
|
if (Array.isArray(input)) {
|
|
return deparseArray(input);
|
|
}
|
|
if (input === null) {
|
|
return "None";
|
|
}
|
|
|
|
var beginObject = '(';
|
|
var endObject = ')';
|
|
var nameSeparator = '=';
|
|
var valueSeparator = ',';
|
|
|
|
var output = '';
|
|
output += beginObject;
|
|
|
|
Object.keys(input).forEach(function (key, idx, array) {
|
|
output += key;
|
|
output += nameSeparator;
|
|
output += deparseJson(input[key]);
|
|
|
|
if (idx !== array.length - 1) {
|
|
// Not the last item
|
|
output += valueSeparator
|
|
}
|
|
});
|
|
output += endObject;
|
|
|
|
return output;
|
|
}
|
|
|
|
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] + "'"
|
|
}
|
|
|
|
var beginObject = '(';
|
|
var endObject = ')';
|
|
var valueSeparator = ',';
|
|
|
|
var output = '';
|
|
output += beginObject;
|
|
|
|
input.forEach(function (data, idx, array) {
|
|
output += deparseJson(data);
|
|
|
|
if (idx !== array.length - 1) {
|
|
output += valueSeparator;
|
|
}
|
|
});
|
|
output += endObject;
|
|
|
|
return output;
|
|
}
|
|
|
|
function deparseNumber(input) {
|
|
// All numbers seem to be a string to 6 decimal places
|
|
return Number(input).toFixed(6);
|
|
}
|
|
|
|
function deparseString(input) {
|
|
// We need to re-encode the strings properly
|
|
return JSON.stringify(input);
|
|
}
|
|
|
|
function deparseBoolean(input) {
|
|
if ( input ) {
|
|
return 'True';
|
|
} else {
|
|
return 'False';
|
|
}
|
|
} |