JSON import: Make biome coords optional

This commit is contained in:
Wuzzy 2024-11-30 17:37:14 +01:00
parent ab71582907
commit c34a0db9ab

View File

@ -2415,8 +2415,12 @@ inputImportSubmit.onclick = function() {
} else if (((typeof value) === "number") && (
key === "humidity_point" ||
key === "heat_point" ||
key === "x_min" ||
key === "x_max" ||
key === "y_min" ||
key === "y_max")) {
key === "y_max" ||
key === "z_min" ||
key === "z_max")) {
return value;
} else {
return value;
@ -2456,8 +2460,12 @@ inputImportSubmit.onclick = function() {
{ fieldName: "name", type: "string" },
{ fieldName: "heat_point", type: "number" },
{ fieldName: "humidity_point", type: "number" },
{ fieldName: "y_min", type: "number" },
{ fieldName: "y_max", type: "number" },
{ fieldName: "x_min", type: "number", fieldDefault: MIN_X },
{ fieldName: "x_max", type: "number", fieldDefault: MAX_X },
{ fieldName: "y_min", type: "number", fieldDefault: MIN_Y },
{ fieldName: "y_max", type: "number", fieldDefault: MAX_Y },
{ fieldName: "z_min", type: "number", fieldDefault: MIN_Z },
{ fieldName: "z_max", type: "number", fieldDefault: MAX_Z },
]
for (let p=0; p<parsedJSON.length; p++) {
let parsedPoint = parsedJSON[p];
@ -2465,10 +2473,15 @@ inputImportSubmit.onclick = function() {
for (let f=0; f<fieldsToCheck.length; f++) {
let field = fieldsToCheck[f].fieldName;
let wantType = fieldsToCheck[f].type;
let defaultValue = fieldsToCheck[f].fieldDefault;
let gotType = typeof parsedPoint[field];
if (gotType === "undefined") {
importMessage(`Import failed. attribute "${field}" of biome #${p} is undefined.`)
return;
if (defaultValue !== undefined) {
parsedPoint[field] = defaultValue;
} else {
importMessage(`Import failed. attribute "${field}" of biome #${p} is undefined.`)
return;
}
} else if (gotType !== wantType) {
importMessage(`Import failed. attribute "${field}" of biome #${p} is of type "${gotType}" but "${wantType}" expected.`)
return;