diff --git a/modules/military-generator.js b/modules/military-generator.js index 8064daba..bce56ef8 100644 --- a/modules/military-generator.js +++ b/modules/military-generator.js @@ -137,7 +137,14 @@ } } - armies.selectAll("g").remove(); // clear armies layer + void function removeExistingRegiments() { + armies.selectAll("g > g").each(function() { + const index = notes.findIndex(n => n.id === this.id); + if (index != -1) notes.splice(index, 1); + }); + armies.selectAll("g").remove(); + }() + const expected = 3 * populationRate.value; // expected regiment size const mergeable = (n, s) => (!n.s && !s.s) || n.u === s.u; // get regiments for each state @@ -264,18 +271,29 @@ const generateNote = function(r, s) { const base = cells.burg[r.cell] && pack.burgs[cells.burg[r.cell]] ? pack.burgs[cells.burg[r.cell]].name : cells.province[r.cell] && pack.provinces[cells.province[r.cell]] ? pack.provinces[cells.province[r.cell]].fullName : null; - const station = base ? `${r.name} is ${r.n ? "based" : "stationed"} in ${base}. ` : null; + const station = base ? `${r.name} is ${r.n ? "based" : "stationed"} in ${base}. ` : ""; - const composition = Object.keys(r.u).map(t => ` — ${t}: ${r.u[t]}`).join("\r\n"); - const troops = `\r\n\r\nRegiment composition:\r\n${composition}.`; + const composition = r.a ? Object.keys(r.u).map(t => `— ${t}: ${r.u[t]}`).join("\r\n") : null; + const troops = composition ? `\r\n\r\nRegiment composition:\r\n${composition}.` : ""; - const campaign = ra(s.campaigns); + const campaign = s.campaigns ? ra(s.campaigns) : null; const year = campaign ? rand(campaign.start, campaign.end) : gauss(options.year-100, 150, 1, options.year-6); const conflict = campaign ? ` during the ${campaign.name}` : ""; const legend = `Regiment was formed in ${year} ${options.era}${conflict}. ${station}${troops}`; notes.push({id:`regiment${s.i}-${r.i}`, name:`${r.icon} ${r.name}`, legend}); } + // const updateNote = function(r, s) { + // const id = `regiment${s}-${r.i}`; + // const note = notes.find(n => n.id === id); + // if (!note) return; + + // const oldComposition = note.legend.split("composition:\r\n")[1]||"".split(".")[0]; + // if (!oldComposition) return; + // const newComposition = Object.keys(r.u).map(t => `— ${t}: ${r.u[t]}`).join("\r\n") + "."; + // note.legend = note.legend.replace(oldComposition, newComposition); + // } + return {generate, getDefaultOptions, getName, generateNote, drawRegiments, drawRegiment, getTotal, getEmblem}; }))); \ No newline at end of file diff --git a/modules/ui/markers-editor.js b/modules/ui/markers-editor.js index 9df4b88a..884c531e 100644 --- a/modules/ui/markers-editor.js +++ b/modules/ui/markers-editor.js @@ -170,7 +170,7 @@ function editMarker() { } function drawIconsList() { - let icons = [ + const icons = [ // emoticons in FF: ["2693", "⚓", "Anchor"], ["26EA", "⛪", "Church"], diff --git a/modules/ui/regiment-editor.js b/modules/ui/regiment-editor.js index 1a2ddedf..a02eff41 100644 --- a/modules/ui/regiment-editor.js +++ b/modules/ui/regiment-editor.js @@ -164,6 +164,7 @@ function editRegiment(selector) { const newReg = {a, cell:reg.cell, i, n:reg.n, u:u2, x:reg.x, y:y(reg.x, reg.y), bx:reg.bx, by:reg.by, icon: reg.icon}; newReg.name = Military.getName(newReg, military); military.push(newReg); + Military.generateNote(newReg, pack.states[state]); // add legend Military.drawRegiment(newReg, state); // draw new reg below if (regimentsOverviewRefresh.offsetParent) regimentsOverviewRefresh.click(); @@ -190,6 +191,7 @@ function editRegiment(selector) { const reg = {a:0, cell, i, n, u:{}, x, y, bx:x, by:y, icon:"🛡️"}; reg.name = Military.getName(reg, military); military.push(reg); + Military.generateNote(reg, pack.states[state]); // add legend Military.drawRegiment(reg, state); if (regimentsOverviewRefresh.offsetParent) regimentsOverviewRefresh.click(); toggleAdd(); diff --git a/modules/ui/regiments-overview.js b/modules/ui/regiments-overview.js index 7878bb73..0e2e0e49 100644 --- a/modules/ui/regiments-overview.js +++ b/modules/ui/regiments-overview.js @@ -156,6 +156,7 @@ function overviewRegiments(state) { const reg = {a:0, cell, i, n, u:{}, x, y, bx:x, by:y, icon:"🛡️"}; reg.name = Military.getName(reg, military); military.push(reg); + Military.generateNote(reg, pack.states[state]); // add legend Military.drawRegiment(reg, state); toggleAdd(); }