mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2026-02-05 01:51:23 +01:00
feat: submap - allow custom number of cells
This commit is contained in:
parent
f587805da9
commit
0bd331f564
3 changed files with 35 additions and 29 deletions
|
|
@ -332,16 +332,12 @@ const cellsDensityMap = {
|
||||||
|
|
||||||
function changeCellsDensity(value) {
|
function changeCellsDensity(value) {
|
||||||
pointsInput.value = value;
|
pointsInput.value = value;
|
||||||
const cells = cellsDensityMap[value] || 1000;
|
const cells = cellsDensityMap[value] || pointsInput.dataset.cells;
|
||||||
pointsInput.dataset.cells = cells;
|
pointsInput.dataset.cells = cells;
|
||||||
pointsOutputFormatted.value = getCellsDensityValue(cells);
|
pointsOutputFormatted.value = cells / 1000 + "K";
|
||||||
pointsOutputFormatted.style.color = getCellsDensityColor(cells);
|
pointsOutputFormatted.style.color = getCellsDensityColor(cells);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCellsDensityValue(cells) {
|
|
||||||
return cells / 1000 + "K";
|
|
||||||
}
|
|
||||||
|
|
||||||
function getCellsDensityColor(cells) {
|
function getCellsDensityColor(cells) {
|
||||||
return cells > 50000 ? "#b12117" : cells !== 10000 ? "#dfdf12" : "#053305";
|
return cells > 50000 ? "#b12117" : cells !== 10000 ? "#dfdf12" : "#053305";
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
function openSubmapTool() {
|
function openSubmapTool() {
|
||||||
|
resetInputs();
|
||||||
|
|
||||||
$("#submapTool").dialog({
|
$("#submapTool").dialog({
|
||||||
title: "Create a submap",
|
title: "Create a submap",
|
||||||
resizable: false,
|
resizable: false,
|
||||||
|
|
@ -20,8 +22,19 @@ function openSubmapTool() {
|
||||||
if (modules.openSubmapTool) return;
|
if (modules.openSubmapTool) return;
|
||||||
modules.openSubmapTool = true;
|
modules.openSubmapTool = true;
|
||||||
|
|
||||||
// add listeners
|
function resetInputs() {
|
||||||
byId("submapPointsInput").on("input", handleCellsChange);
|
updateCellsNumber(byId("pointsInput").value);
|
||||||
|
byId("submapPointsInput").oninput = e => updateCellsNumber(e.target.value);
|
||||||
|
|
||||||
|
function updateCellsNumber(value) {
|
||||||
|
byId("submapPointsInput").value = value;
|
||||||
|
const cells = cellsDensityMap[value];
|
||||||
|
byId("submapPointsInput").dataset.cells = cells;
|
||||||
|
const output = byId("submapPointsFormatted");
|
||||||
|
output.value = cells / 1000 + "K";
|
||||||
|
output.style.color = getCellsDensityColor(cells);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function generateSubmap() {
|
function generateSubmap() {
|
||||||
INFO && console.group("generateSubmap");
|
INFO && console.group("generateSubmap");
|
||||||
|
|
@ -29,8 +42,9 @@ function openSubmapTool() {
|
||||||
const [x0, y0] = [Math.abs(viewX / scale), Math.abs(viewY / scale)]; // top-left corner
|
const [x0, y0] = [Math.abs(viewX / scale), Math.abs(viewY / scale)]; // top-left corner
|
||||||
recalculateMapSize(x0, y0);
|
recalculateMapSize(x0, y0);
|
||||||
|
|
||||||
const cellsNumber = +byId("submapPointsInput").value;
|
const submapPointsValue = byId("submapPointsInput").value;
|
||||||
changeCellsDensity(cellsNumber);
|
const globalPointsValue = byId("pointsInput").value;
|
||||||
|
if (submapPointsValue !== globalPointsValue) changeCellsDensity(submapPointsValue);
|
||||||
|
|
||||||
const projection = (x, y) => [(x - x0) * scale, (y - y0) * scale];
|
const projection = (x, y) => [(x - x0) * scale, (y - y0) * scale];
|
||||||
const inverse = (x, y) => [x / scale + x0, y / scale + y0];
|
const inverse = (x, y) => [x / scale + x0, y / scale + y0];
|
||||||
|
|
@ -77,12 +91,4 @@ function openSubmapTool() {
|
||||||
bl.dataset["size"] = Math.max(rn((size + size / scale) / 2, 2), 1) * scale;
|
bl.dataset["size"] = Math.max(rn((size + size / scale) / 2, 2), 1) * scale;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleCellsChange() {
|
|
||||||
const cells = cellsDensityMap[+this.value] || 1000;
|
|
||||||
this.dataset.cells = cells;
|
|
||||||
const output = byId("submapPointsFormatted");
|
|
||||||
output.value = getCellsDensityValue(cells);
|
|
||||||
output.style.color = getCellsDensityColor(cells);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,6 @@ async function openTransformTool() {
|
||||||
|
|
||||||
// add listeners
|
// add listeners
|
||||||
byId("transformToolBody").on("input", handleInput);
|
byId("transformToolBody").on("input", handleInput);
|
||||||
byId("transformPointsInput").on("input", handleCellsChange);
|
|
||||||
byId("transformPreview")
|
byId("transformPreview")
|
||||||
.on("mousedown", handleMousedown)
|
.on("mousedown", handleMousedown)
|
||||||
.on("mouseup", _ => (mouseIsDown = false))
|
.on("mouseup", _ => (mouseIsDown = false))
|
||||||
|
|
@ -69,6 +68,18 @@ async function openTransformTool() {
|
||||||
byId("transformShiftX").value = 0;
|
byId("transformShiftX").value = 0;
|
||||||
byId("transformShiftY").value = 0;
|
byId("transformShiftY").value = 0;
|
||||||
handleInput();
|
handleInput();
|
||||||
|
|
||||||
|
updateCellsNumber(byId("pointsInput").value);
|
||||||
|
byId("transformPointsInput").oninput = e => updateCellsNumber(e.target.value);
|
||||||
|
|
||||||
|
function updateCellsNumber(value) {
|
||||||
|
byId("transformPointsInput").value = value;
|
||||||
|
const cells = cellsDensityMap[value];
|
||||||
|
byId("transformPointsInput").dataset.cells = cells;
|
||||||
|
const output = byId("transformPointsFormatted");
|
||||||
|
output.value = cells / 1000 + "K";
|
||||||
|
output.style.color = getCellsDensityColor(cells);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleInput() {
|
function handleInput() {
|
||||||
|
|
@ -89,14 +100,6 @@ async function openTransformTool() {
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleCellsChange() {
|
|
||||||
const cells = cellsDensityMap[+this.value] || 1000;
|
|
||||||
this.dataset.cells = cells;
|
|
||||||
const output = byId("transformPointsFormatted");
|
|
||||||
output.value = getCellsDensityValue(cells);
|
|
||||||
output.style.color = getCellsDensityColor(cells);
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleMousedown(e) {
|
function handleMousedown(e) {
|
||||||
mouseIsDown = true;
|
mouseIsDown = true;
|
||||||
const shiftX = +byId("transformShiftX").value;
|
const shiftX = +byId("transformShiftX").value;
|
||||||
|
|
@ -123,8 +126,9 @@ async function openTransformTool() {
|
||||||
function transformMap() {
|
function transformMap() {
|
||||||
INFO && console.group("transformMap");
|
INFO && console.group("transformMap");
|
||||||
|
|
||||||
const cellsNumber = +byId("transformPointsInput").value;
|
const transformPointsValue = byId("transformPointsInput").value;
|
||||||
changeCellsDensity(cellsNumber);
|
const globalPointsValue = byId("pointsInput").value;
|
||||||
|
if (transformPointsValue !== globalPointsValue) changeCellsDensity(transformPointsValue);
|
||||||
|
|
||||||
const [projection, inverse] = getProjection();
|
const [projection, inverse] = getProjection();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue