Can now import Amidst for Minetest biome profiles

This commit is contained in:
Wuzzy 2024-11-30 20:14:30 +01:00
parent c8516aaca5
commit f635b083b9
3 changed files with 34 additions and 14 deletions

View File

@ -179,7 +179,7 @@ h3 {
font-weight: bold;
color: #2d8af0;
}
.exportEmphasis{
.importExportEmphasis{
font-weight: bold;
color: #00ff00;
}

View File

@ -197,11 +197,12 @@ A Voronoi diagram is supposed to be here but for some reason it cannot be displa
<div class="configFrame" id="importContainer" style="display:none">
<form id="importForm">
<p><b>WARNING</b>: Importing will replace all the biomes!</p>
<label for="inputImport">Put JSON text here:</label>
<label for="inputImport">Put text here:</label>
<br>
<textarea id="inputImport" rows="12" cols="80"></textarea>
<br>
<button id="inputImportSubmit" type="button">Import</button>
<button id="inputImportJSONSubmit" type="button">Import from <span class="importExportEmphasis">JSON</span></button>
<button id="inputImportAmidstForMinetestSubmit" type="button">Import from <span class="importExportEmphasis">Amidst for Minetest</span> biome profile</button>
<div id="importResultOuter" hidden><br><div id="importResultMessage"></div></div>
<hr class="thin">
<div>Hint: Use <a href="https://codeberg.org/Wuzzy/libpov_biome_exporter" title="Luanti mod: libpov_biome_exporter">libpov_biome_exporter</a> to convert game biomes to JSON.</div>
@ -214,9 +215,9 @@ A Voronoi diagram is supposed to be here but for some reason it cannot be displa
<div class="configFrame" id="exportContainer" style="display:none">
<form id="exportForm">
<div>
<button id="inputExportJSON" type="button">Export as <span class="exportEmphasis">JSON</span></button>
<button id="inputExportLua" type="button">Export as <span class="exportEmphasis">Lua</span></button>
<button id="inputExportAmidstForMinetest" type="button">Export as <span class="exportEmphasis">Amidst for Minetest</span> biome profile</button>
<button id="inputExportJSON" type="button">Export as <span class="importExportEmphasis">JSON</span></button>
<button id="inputExportLua" type="button">Export as <span class="importExportEmphasis">Lua</span></button>
<button id="inputExportAmidstForMinetest" type="button">Export as <span class="importExportEmphasis">Amidst for Minetest</span> biome profile</button>
<button id="inputExportClear" type="button">Clear</button>
</div>
<div id="exportSectionOuter" hidden><br><span id="exportLabel"></span>

View File

@ -2402,7 +2402,7 @@ inputExportClear.onclick = function() {
}
/* Import */
inputImportSubmit.onclick = function() {
function importJSON(jsonType) {
let importMessage = function(message) {
importResultOuter.hidden = false;
importResultMessage.innerText = message;
@ -2416,13 +2416,13 @@ inputImportSubmit.onclick = function() {
} else if (((typeof value) === "number") && (
key === "humidity_point" ||
key === "heat_point" ||
key === "x_min" ||
key === "x_max" ||
jsonType === "libpov" && key === "x_min" ||
jsonType === "libpov" && key === "x_max" ||
key === "y_min" ||
key === "y_max" ||
key === "z_min" ||
key === "z_max" ||
key === "colorcode")) {
jsonType === "libpov" && key === "z_min" ||
jsonType === "libpov" && key === "z_max" ||
jsonType === "libpov" && key === "colorcode")) {
return value;
} else {
return value;
@ -2454,6 +2454,18 @@ inputImportSubmit.onclick = function() {
return;
}
let innerJSON;
if (jsonType === "libpov") {
innerJSON = parsedJSON;
} else if (jsonType === "amidst_for_minetest") {
if (parsedJSON.biomeList) {
innerJSON = parsedJSON.biomeList;
} else {
importMessage("Import of biome profile failed. No biomeList found.");
return;
}
}
// Populate the temporary newPoints that MAY
// set the biomePoints if successful
let newPoints = [];
@ -2470,8 +2482,8 @@ inputImportSubmit.onclick = function() {
{ 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];
for (let p=0; p<innerJSON.length; p++) {
let parsedPoint = innerJSON[p];
// Type checking
for (let f=0; f<fieldsToCheck.length; f++) {
let field = fieldsToCheck[f].fieldName;
@ -2530,6 +2542,13 @@ inputImportSubmit.onclick = function() {
}
}
inputImportJSONSubmit.onclick = function() {
importJSON("libpov");
}
inputImportAmidstForMinetestSubmit.onclick = function() {
importJSON("amidst_for_minetest");
}
/* Mode events */
modernModeButton.onclick = function() {
biomeMode = "modern";