mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 17:51:24 +01:00
refactor: state labels - fix edit
This commit is contained in:
parent
392325eb53
commit
b6acd8ffff
1 changed files with 3 additions and 17 deletions
|
|
@ -14,6 +14,8 @@ export function open({el}) {
|
||||||
closeDialogs();
|
closeDialogs();
|
||||||
if (!layerIsOn("toggleLabels")) toggleLayer("toggleLabels");
|
if (!layerIsOn("toggleLabels")) toggleLayer("toggleLabels");
|
||||||
|
|
||||||
|
const lineGen = d3.line().curve(d3.curveBundle.beta(1));
|
||||||
|
|
||||||
const textPath = el.parentNode;
|
const textPath = el.parentNode;
|
||||||
const text = textPath.parentNode;
|
const text = textPath.parentNode;
|
||||||
elSelected = d3.select(text).call(d3.drag().on("start", dragLabel)).classed("draggable", true);
|
elSelected = d3.select(text).call(d3.drag().on("start", dragLabel)).classed("draggable", true);
|
||||||
|
|
@ -123,8 +125,6 @@ export function open({el}) {
|
||||||
redrawLabelPath();
|
redrawLabelPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
const lineGen = d3.line().curve(d3.curveBundle.beta(1));
|
|
||||||
|
|
||||||
function redrawLabelPath() {
|
function redrawLabelPath() {
|
||||||
const path = byId("textPath_" + elSelected.attr("id"));
|
const path = byId("textPath_" + elSelected.attr("id"));
|
||||||
const points = [];
|
const points = [];
|
||||||
|
|
@ -308,26 +308,12 @@ export function open({el}) {
|
||||||
function changeText() {
|
function changeText() {
|
||||||
const input = byId("labelText").value;
|
const input = byId("labelText").value;
|
||||||
const el = elSelected.select("textPath").node();
|
const el = elSelected.select("textPath").node();
|
||||||
const example = d3
|
|
||||||
.select(elSelected.node().parentNode)
|
|
||||||
.append("text")
|
|
||||||
.attr("x", 0)
|
|
||||||
.attr("x", 0)
|
|
||||||
.attr("font-size", el.getAttribute("font-size"))
|
|
||||||
.node();
|
|
||||||
|
|
||||||
const lines = input.split("|");
|
const lines = input.split("|");
|
||||||
const top = (lines.length - 1) / -2; // y offset
|
const top = (lines.length - 1) / -2; // y offset
|
||||||
const inner = lines
|
const inner = lines.map((l, d) => `<tspan x="0" dy="${d ? 1 : top}em">${l}</tspan>`).join("");
|
||||||
.map((l, d) => {
|
|
||||||
example.innerHTML = l;
|
|
||||||
const left = example.getBBox().width / -2; // x offset
|
|
||||||
return `<tspan x="${left}px" dy="${d ? 1 : top}em">${l}</tspan>`;
|
|
||||||
})
|
|
||||||
.join("");
|
|
||||||
|
|
||||||
el.innerHTML = inner;
|
el.innerHTML = inner;
|
||||||
example.remove();
|
|
||||||
|
|
||||||
if (elSelected.attr("id").slice(0, 10) === "stateLabel")
|
if (elSelected.attr("id").slice(0, 10) === "stateLabel")
|
||||||
tip("Use States Editor to change an actual state name, not just a label", false, "warning");
|
tip("Use States Editor to change an actual state name, not just a label", false, "warning");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue