Add color support for Amidst for Minetest export

This commit is contained in:
Wuzzy 2023-10-27 16:18:41 +02:00
parent 42fda24809
commit 707dc2b01f
2 changed files with 36 additions and 11 deletions

@ -163,7 +163,7 @@ A Voronoi diagram is supposed to be here but for some reason it cannot be displa
<div>
<button id="inputExportLua" type="button">Export as Lua</button>
<button id="inputExportJSON" type="button">Export as JSON</button>
<button id="inputExportAmidstForMinetest" type="button">Export as Amidst for Minetest biome set</button>
<button id="inputExportAmidstForMinetest" type="button">Export as Amidst for Minetest biome profile</button>
<button id="inputExportClear" type="button">Clear</button>
</div>
<div id="exportSectionOuter" hidden><br><span id="exportLabel"></span>

@ -67,6 +67,8 @@ const AXIS_COLOR = "#000000";
// Color to be used when the diagram is cleared
const CLEAR_COLOR = "#ecddba";
// list of possible cell colors
// note: These MUST be in "#xxxxxx" format
// for the hexColorToRGBColor function to work.
const CELL_COLORS = [
"#64988e",
"#3d7085",
@ -1706,6 +1708,29 @@ inputExportJSON.onclick = function() {
}
exportSectionOuter.hidden = false;
}
// Assuming that hexColor is a string of the form
// "#xxxxxx" (where x is a hexadecimal digit),
// returns an object of the form { r: 0, g: 0, b: 0 }
function hexColorToRGBColor(hexColor) {
if (typeof hexColor !== "string") {
return null;
}
let rh = hexColor.slice(1,3);
let gh = hexColor.slice(3,5);
let bh = hexColor.slice(5,7);
if (rh === "" || gh === "" || bh === "") {
return null;
}
let r = Number("0x"+rh)
let g = Number("0x"+gh)
let b = Number("0x"+bh)
if (typeof r !== "number" || typeof g !== "number" || typeof b !== "number") {
return null;
}
return { r:r, g:g, b:b }
}
inputExportAmidstForMinetest.onclick = function() {
let jsonOut = {};
jsonOut.name = "MiBPoV Export";
@ -1714,28 +1739,28 @@ inputExportAmidstForMinetest.onclick = function() {
let biome = biomePoints[b];
let jsonPoint = {};
jsonPoint.name = biome.name;
jsonPoint.heat_point = biome.heat;
jsonPoint.humidity_point = biome.humidity;
let color = hexColorToRGBColor(CELL_COLORS[biome.colorIndex]);
if (color !== null) {
jsonPoint.color = color;
} else {
jsonPoint.color = { r: 255, g: 255, b: 255 };
}
jsonPoint.y_min = biome.min_y;
jsonPoint.y_max = biome.max_y;
// TODO: Export cell color
jsonPoint.color = {
r: 255,
g: 255,
b: 255,
},
jsonPoint.heat_point = biome.heat;
jsonPoint.humidity_point = biome.humidity;
jsonPoints.push(jsonPoint);
}
jsonOut.biomeList = jsonPoints;
let str = JSON.stringify(jsonOut);
let str = JSON.stringify(jsonOut, undefined, 4);
exportSectionText.innerText = str;
if (str === "") {
exportSectionText.hidden = true;
exportLabel.innerText = "Export is empty.";
} else {
exportSectionText.hidden = false;
exportLabel.innerText = "Exported biomes (as Amidst for Minetest biome set):";
exportLabel.innerText = "Exported biomes (as Amidst for Minetest biome profile):";
}
exportSectionOuter.hidden = false;
}