Export/Import color index in JSON

This commit is contained in:
Wuzzy 2024-11-30 19:17:15 +01:00
parent 1d537fba84
commit 8edc177a91
2 changed files with 20 additions and 5 deletions

View File

@ -2325,6 +2325,7 @@ inputExportJSON.onclick = function() {
jsonPoint.y_max = biome.max_y;
jsonPoint.z_min = biome.min_z;
jsonPoint.z_max = biome.max_z;
jsonPoint.color_index = biome.colorIndex;
jsonPoints.push(jsonPoint);
}
@ -2420,7 +2421,8 @@ inputImportSubmit.onclick = function() {
key === "y_min" ||
key === "y_max" ||
key === "z_min" ||
key === "z_max")) {
key === "z_max" ||
key === "colorcode")) {
return value;
} else {
return value;
@ -2466,6 +2468,7 @@ inputImportSubmit.onclick = function() {
{ fieldName: "y_max", type: "number", fieldDefault: MAX_Y },
{ fieldName: "z_min", type: "number", fieldDefault: MIN_Z },
{ fieldName: "z_max", type: "number", fieldDefault: MAX_Z },
{ fieldName: "color_index", type: "number", optional: true },
]
for (let p=0; p<parsedJSON.length; p++) {
let parsedPoint = parsedJSON[p];
@ -2474,9 +2477,12 @@ inputImportSubmit.onclick = function() {
let field = fieldsToCheck[f].fieldName;
let wantType = fieldsToCheck[f].type;
let defaultValue = fieldsToCheck[f].fieldDefault;
let isOptional = fieldsToCheck[f].optional;
let gotType = typeof parsedPoint[field];
if (gotType === "undefined") {
if (defaultValue !== undefined) {
if (isOptional) {
// skip
} else if (defaultValue !== undefined) {
parsedPoint[field] = defaultValue;
} else {
importMessage(`Import failed. attribute "${field}" of biome #${p} is undefined.`)
@ -2487,6 +2493,14 @@ inputImportSubmit.onclick = function() {
return;
}
}
let colorIndex = parsedPoint.color_index;
if (typeof colorIndex === "number") {
if (colorIndex < 0) {
colorIndex = undefined;
} else if (colorIndex > CELL_COLORS.length-1) {
colorIndex = undefined;
}
}
let newPoint = {
id: lastBiomeID,
@ -2499,7 +2513,7 @@ inputImportSubmit.onclick = function() {
max_y: parsedPoint.y_max,
min_z: parsedPoint.z_min,
max_z: parsedPoint.z_max,
colorIndex: lastBiomeID % CELL_COLORS.length,
colorIndex: colorIndex || lastBiomeID % CELL_COLORS.length,
};
lastBiomeID++;
newPoints.push(newPoint);

View File

@ -159,7 +159,7 @@
<li><code>humidity_point</code>: Humidity point (number). Same name as in Lua</li>
</ul>
<p>Additionally, the object may optionally specify any of the following fields to specify the minimum and maximum world coordinates of the biome:</p>
<p>Additionally, the object may optionally specify any of the following fields:</p>
<ul>
<li><code>x_min</code>: Minimum X position of biome (number). Corresponds to <code>min_pos.x</code> in Lua</li>
@ -168,9 +168,10 @@
<li><code>y_max</code>: Maximum Y position of biome (number). Corresponds to <code>max_pos.y</code> or <code>y_max</code> in Lua</li>
<li><code>z_min</code>: Minimum Z position of biome (number). Corresponds to <code>min_pos.z</code> in Lua</li>
<li><code>z_max</code>: Maximum Z position of biome (number). Corresponds to <code>max_pos.z</code> in Lua</li>
<li><code>color_index</code>: A number that represents a color of the biome color palette, starting with 0. Used by LiBPoV to store the biome color in the diagram, otherwise meaningless. The number does not represent any particular color, only a palette index, as the palette might change in future.</li>
</ul>
<p>If unspecified, these optional fields default to -31000 (minimum) and 31000 (maximum).</li>
<p>If unspecified, the minimum/maximum position arguments default to -31000 (minimum) and 31000 (maximum). If <code>color_index</code> is unspecified or is out of range, LiBPoV will pick a color index based on the position in the JSON array.</p>
<p>For general information about JSON, see <a href="https://www.json.org/" title="Introducing JSON">www.json.org</a>.</p>