mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 09:41:24 +01:00
refactor: religion editor
This commit is contained in:
parent
221079321f
commit
2c592a062d
1 changed files with 26 additions and 30 deletions
|
|
@ -783,14 +783,14 @@ function selectReligionOnMapClick() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function dragReligionBrush() {
|
function dragReligionBrush() {
|
||||||
const r = +religionsManuallyBrushNumber.value;
|
const radius = +byId("religionsManuallyBrushNumber").value;
|
||||||
|
|
||||||
d3.event.on("drag", () => {
|
d3.event.on("drag", () => {
|
||||||
if (!d3.event.dx && !d3.event.dy) return;
|
if (!d3.event.dx && !d3.event.dy) return;
|
||||||
const p = d3.mouse(this);
|
const [x, y] = d3.mouse(this);
|
||||||
moveCircle(p[0], p[1], r);
|
moveCircle(x, y, radius);
|
||||||
|
|
||||||
const found = r > 5 ? findAll(p[0], p[1], r) : [findCell(p[0], p[1], r)];
|
const found = radius > 5 ? findAll(x, y, radius) : [findCell(x, y, radius)];
|
||||||
const selection = found.filter(isLand);
|
const selection = found.filter(isLand);
|
||||||
if (selection) changeReligionForSelection(selection);
|
if (selection) changeReligionForSelection(selection);
|
||||||
});
|
});
|
||||||
|
|
@ -800,21 +800,21 @@ function dragReligionBrush() {
|
||||||
function changeReligionForSelection(selection) {
|
function changeReligionForSelection(selection) {
|
||||||
const temp = relig.select("#temp");
|
const temp = relig.select("#temp");
|
||||||
const selected = $body.querySelector("div.selected");
|
const selected = $body.querySelector("div.selected");
|
||||||
const r = +selected.dataset.id; // religionNew
|
const religionNew = +selected.dataset.id;
|
||||||
const color = pack.religions[r].color || "#ffffff";
|
const color = pack.religions[religionNew].color || "#ffffff";
|
||||||
|
|
||||||
selection.forEach(function (i) {
|
selection.forEach(function (i) {
|
||||||
const exists = temp.select("polygon[data-cell='" + i + "']");
|
const exists = temp.select("polygon[data-cell='" + i + "']");
|
||||||
const religionOld = exists.size() ? +exists.attr("data-religion") : pack.cells.religion[i];
|
const religionOld = exists.size() ? +exists.attr("data-religion") : pack.cells.religion[i];
|
||||||
if (r === religionOld) return;
|
if (religionNew === religionOld) return;
|
||||||
|
|
||||||
// change of append new element
|
// change of append new element
|
||||||
if (exists.size()) exists.attr("data-religion", r).attr("fill", color);
|
if (exists.size()) exists.attr("data-religion", religionNew).attr("fill", color);
|
||||||
else
|
else
|
||||||
temp
|
temp
|
||||||
.append("polygon")
|
.append("polygon")
|
||||||
.attr("data-cell", i)
|
.attr("data-cell", i)
|
||||||
.attr("data-religion", r)
|
.attr("data-religion", religionNew)
|
||||||
.attr("points", getPackPolygon(i))
|
.attr("points", getPackPolygon(i))
|
||||||
.attr("fill", color);
|
.attr("fill", color);
|
||||||
});
|
});
|
||||||
|
|
@ -822,9 +822,9 @@ function changeReligionForSelection(selection) {
|
||||||
|
|
||||||
function moveReligionBrush() {
|
function moveReligionBrush() {
|
||||||
showMainTip();
|
showMainTip();
|
||||||
const point = d3.mouse(this);
|
const [x, y] = d3.mouse(this);
|
||||||
const radius = +religionsManuallyBrushNumber.value;
|
const radius = +byId("religionsManuallyBrushNumber").value;
|
||||||
moveCircle(point[0], point[1], radius);
|
moveCircle(x, y, radius);
|
||||||
}
|
}
|
||||||
|
|
||||||
function applyReligionsManualAssignent() {
|
function applyReligionsManualAssignent() {
|
||||||
|
|
@ -850,23 +850,23 @@ function exitReligionsManualAssignment(close) {
|
||||||
document.querySelectorAll("#religionsBottom > button").forEach(el => (el.style.display = "inline-block"));
|
document.querySelectorAll("#religionsBottom > button").forEach(el => (el.style.display = "inline-block"));
|
||||||
byId("religionsManuallyButtons").style.display = "none";
|
byId("religionsManuallyButtons").style.display = "none";
|
||||||
|
|
||||||
religionsEditor.querySelectorAll(".hide").forEach(el => el.classList.remove("hidden"));
|
byId("religionsEditor")
|
||||||
religionsFooter.style.display = "block";
|
.querySelectorAll(".hide")
|
||||||
|
.forEach(el => el.classList.remove("hidden"));
|
||||||
|
byId("religionsFooter").style.display = "block";
|
||||||
$body.querySelectorAll("div > input, select, span, svg").forEach(e => (e.style.pointerEvents = "all"));
|
$body.querySelectorAll("div > input, select, span, svg").forEach(e => (e.style.pointerEvents = "all"));
|
||||||
if (!close) $("#religionsEditor").dialog({position: {my: "right top", at: "right-10 top+10", of: "svg"}});
|
if (!close) $("#religionsEditor").dialog({position: {my: "right top", at: "right-10 top+10", of: "svg"}});
|
||||||
|
|
||||||
debug.select("#religionCenters").style("display", null);
|
debug.select("#religionCenters").style("display", null);
|
||||||
restoreDefaultEvents();
|
restoreDefaultEvents();
|
||||||
clearMainTip();
|
clearMainTip();
|
||||||
const selected = $body.querySelector("div.selected");
|
const $selected = $body.querySelector("div.selected");
|
||||||
if (selected) selected.classList.remove("selected");
|
if ($selected) $selected.classList.remove("selected");
|
||||||
}
|
}
|
||||||
|
|
||||||
function enterAddReligionMode() {
|
function enterAddReligionMode() {
|
||||||
if (this.classList.contains("pressed")) {
|
if (this.classList.contains("pressed")) return exitAddReligionMode();
|
||||||
exitAddReligionMode();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
customization = 8;
|
customization = 8;
|
||||||
this.classList.add("pressed");
|
this.classList.add("pressed");
|
||||||
tip("Click on the map to add a new religion", true);
|
tip("Click on the map to add a new religion", true);
|
||||||
|
|
@ -883,17 +883,13 @@ function exitAddReligionMode() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function addReligion() {
|
function addReligion() {
|
||||||
const point = d3.mouse(this);
|
const [x, y] = d3.mouse(this);
|
||||||
const center = findCell(point[0], point[1]);
|
const center = findCell(x, y);
|
||||||
if (pack.cells.h[center] < 20) {
|
if (pack.cells.h[center] < 20)
|
||||||
tip("You cannot place religion center into the water. Please click on a land cell", false, "error");
|
return tip("You cannot place religion center into the water. Please click on a land cell", false, "error");
|
||||||
return;
|
|
||||||
}
|
|
||||||
const occupied = pack.religions.some(r => !r.removed && r.center === center);
|
const occupied = pack.religions.some(r => !r.removed && r.center === center);
|
||||||
if (occupied) {
|
if (occupied) return tip("This cell is already a religion center. Please select a different cell", false, "error");
|
||||||
tip("This cell is already a religion center. Please select a different cell", false, "error");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (d3.event.shiftKey === false) exitAddReligionMode();
|
if (d3.event.shiftKey === false) exitAddReligionMode();
|
||||||
Religions.add(center);
|
Religions.add(center);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue