@@ -7906,10 +7806,10 @@
-
+
-
+
@@ -7918,7 +7818,7 @@
-
+
@@ -7928,7 +7828,7 @@
-
+
@@ -7945,7 +7845,6 @@
-
diff --git a/modules/cultures-generator.js b/modules/cultures-generator.js
index 37f5bc93..b1072c22 100644
--- a/modules/cultures-generator.js
+++ b/modules/cultures-generator.js
@@ -60,7 +60,7 @@ window.Cultures = (function () {
c.color = colors[i];
c.type = defineCultureType(cell);
c.expansionism = defineCultureExpansionism(c.type);
- c.origin = 0;
+ c.origins = [0];
c.code = abbreviate(c.name, codes);
codes.push(c.code);
cells.culture[cell] = i + 1;
@@ -80,7 +80,7 @@ window.Cultures = (function () {
}
// the first culture with id 0 is for wildlands
- cultures.unshift({name: "Wildlands", i: 0, base: 1, origin: null, shield: "round"});
+ cultures.unshift({name: "Wildlands", i: 0, base: 1, origins: [null], shield: "round"});
// make sure all bases exist in nameBases
if (!nameBases.length) {
@@ -115,7 +115,11 @@ window.Cultures = (function () {
if (cells.h[i] > 50) return "Highland"; // no penalty for hills and moutains, high for other elevations
const f = pack.features[cells.f[cells.haven[i]]]; // opposite feature
if (f.type === "lake" && f.cells > 5) return "Lake"; // low water cross penalty and high for growth not along coastline
- if ((cells.harbor[i] && f.type !== "lake" && P(0.1)) || (cells.harbor[i] === 1 && P(0.6)) || (pack.features[cells.f[i]].group === "isle" && P(0.4)))
+ if (
+ (cells.harbor[i] && f.type !== "lake" && P(0.1)) ||
+ (cells.harbor[i] === 1 && P(0.6)) ||
+ (pack.features[cells.f[i]].group === "isle" && P(0.4))
+ )
return "Naval"; // low water cross penalty and high for non-along-coastline growth
if (cells.r[i] && cells.fl[i] > 100) return "River"; // no River cross penalty, penalty for non-River growth
if (cells.t[i] > 2 && [3, 7, 8, 9, 10, 12].includes(cells.biome[i])) return "Hunting"; // high penalty in non-native biomes
@@ -163,7 +167,22 @@ window.Cultures = (function () {
const emblemShape = document.getElementById("emblemShape").value;
if (emblemShape === "random") shield = getRandomShield();
- pack.cultures.push({name, color, base, center, i, expansionism: 1, type: "Generic", cells: 0, area: 0, rural: 0, urban: 0, origin: 0, code, shield});
+ pack.cultures.push({
+ name,
+ color,
+ base,
+ center,
+ i,
+ expansionism: 1,
+ type: "Generic",
+ cells: 0,
+ area: 0,
+ rural: 0,
+ urban: 0,
+ origins: [0],
+ code,
+ shield
+ });
};
const getDefault = function (count) {
@@ -180,7 +199,8 @@ window.Cultures = (function () {
return d ? d + 1 : 1;
}; // temperature difference fee
const bd = (cell, biomes, fee = 4) => (biomes.includes(cells.biome[cell]) ? 1 : fee); // biome difference fee
- const sf = (cell, fee = 4) => (cells.haven[cell] && pack.features[cells.f[cells.haven[cell]]].type !== "lake" ? 1 : fee); // not on sea coast fee
+ const sf = (cell, fee = 4) =>
+ cells.haven[cell] && pack.features[cells.f[cells.haven[cell]]].type !== "lake" ? 1 : fee; // not on sea coast fee
if (culturesSet.value === "european") {
return [
@@ -208,7 +228,13 @@ window.Cultures = (function () {
{name: "Hantzu", base: 11, odd: 1, sort: i => n(i) / td(i, 13), shield: "banner"},
{name: "Yamoto", base: 12, odd: 1, sort: i => n(i) / td(i, 15) / t[i], shield: "round"},
{name: "Turchian", base: 16, odd: 1, sort: i => n(i) / td(i, 12), shield: "round"},
- {name: "Berberan", base: 17, odd: 0.2, sort: i => (n(i) / td(i, 19) / bd(i, [1, 2, 3], 7)) * t[i], shield: "oval"},
+ {
+ name: "Berberan",
+ base: 17,
+ odd: 0.2,
+ sort: i => (n(i) / td(i, 19) / bd(i, [1, 2, 3], 7)) * t[i],
+ shield: "oval"
+ },
{name: "Eurabic", base: 18, odd: 1, sort: i => (n(i) / td(i, 26) / bd(i, [1, 2], 7)) * t[i], shield: "oval"},
{name: "Efratic", base: 23, odd: 0.1, sort: i => (n(i) / td(i, 22)) * t[i], shield: "round"},
{name: "Tehrani", base: 24, odd: 1, sort: i => (n(i) / td(i, 18)) * h[i], shield: "round"},
@@ -259,15 +285,45 @@ window.Cultures = (function () {
if (culturesSet.value === "highFantasy") {
return [
// fantasy races
- {name: "Quenian (Elfish)", base: 33, odd: 1, sort: i => (n(i) / bd(i, [6, 7, 8, 9], 10)) * t[i], shield: "gondor"}, // Elves
- {name: "Eldar (Elfish)", base: 33, odd: 1, sort: i => (n(i) / bd(i, [6, 7, 8, 9], 10)) * t[i], shield: "noldor"}, // Elves
- {name: "Trow (Dark Elfish)", base: 34, odd: 0.9, sort: i => (n(i) / bd(i, [7, 8, 9, 12], 10)) * t[i], shield: "hessen"}, // Dark Elves
- {name: "Lothian (Dark Elfish)", base: 34, odd: 0.3, sort: i => (n(i) / bd(i, [7, 8, 9, 12], 10)) * t[i], shield: "wedged"}, // Dark Elves
+ {
+ name: "Quenian (Elfish)",
+ base: 33,
+ odd: 1,
+ sort: i => (n(i) / bd(i, [6, 7, 8, 9], 10)) * t[i],
+ shield: "gondor"
+ }, // Elves
+ {
+ name: "Eldar (Elfish)",
+ base: 33,
+ odd: 1,
+ sort: i => (n(i) / bd(i, [6, 7, 8, 9], 10)) * t[i],
+ shield: "noldor"
+ }, // Elves
+ {
+ name: "Trow (Dark Elfish)",
+ base: 34,
+ odd: 0.9,
+ sort: i => (n(i) / bd(i, [7, 8, 9, 12], 10)) * t[i],
+ shield: "hessen"
+ }, // Dark Elves
+ {
+ name: "Lothian (Dark Elfish)",
+ base: 34,
+ odd: 0.3,
+ sort: i => (n(i) / bd(i, [7, 8, 9, 12], 10)) * t[i],
+ shield: "wedged"
+ }, // Dark Elves
{name: "Dunirr (Dwarven)", base: 35, odd: 1, sort: i => n(i) + h[i], shield: "ironHills"}, // Dwarfs
{name: "Khazadur (Dwarven)", base: 35, odd: 1, sort: i => n(i) + h[i], shield: "erebor"}, // Dwarfs
{name: "Kobold (Goblin)", base: 36, odd: 1, sort: i => t[i] - s[i], shield: "moriaOrc"}, // Goblin
{name: "Uruk (Orkish)", base: 37, odd: 1, sort: i => h[i] * t[i], shield: "urukHai"}, // Orc
- {name: "Ugluk (Orkish)", base: 37, odd: 0.5, sort: i => (h[i] * t[i]) / bd(i, [1, 2, 10, 11]), shield: "moriaOrc"}, // Orc
+ {
+ name: "Ugluk (Orkish)",
+ base: 37,
+ odd: 0.5,
+ sort: i => (h[i] * t[i]) / bd(i, [1, 2, 10, 11]),
+ shield: "moriaOrc"
+ }, // Orc
{name: "Yotunn (Giants)", base: 38, odd: 0.7, sort: i => td(i, -10), shield: "pavise"}, // Giant
{name: "Rake (Drakonic)", base: 39, odd: 0.7, sort: i => -s[i], shield: "fantasy2"}, // Draconic
{name: "Arago (Arachnid)", base: 40, odd: 0.7, sort: i => t[i] - s[i], shield: "horsehead2"}, // Arachnid
@@ -276,7 +332,13 @@ window.Cultures = (function () {
{name: "Anor (Human)", base: 32, odd: 1, sort: i => n(i) / td(i, 10), shield: "fantasy5"},
{name: "Dail (Human)", base: 32, odd: 1, sort: i => n(i) / td(i, 13), shield: "roman"},
{name: "Rohand (Human)", base: 16, odd: 1, sort: i => n(i) / td(i, 16), shield: "round"},
- {name: "Dulandir (Human)", base: 31, odd: 1, sort: i => (n(i) / td(i, 5) / bd(i, [2, 4, 10], 7)) * t[i], shield: "easterling"}
+ {
+ name: "Dulandir (Human)",
+ base: 31,
+ odd: 1,
+ sort: i => (n(i) / td(i, 5) / bd(i, [2, 4, 10], 7)) * t[i],
+ shield: "easterling"
+ }
];
}
@@ -296,18 +358,48 @@ window.Cultures = (function () {
{name: "Hetallian", base: 3, odd: 0.3, sort: i => n(i) / td(i, 15), shield: "oval"},
{name: "Astellian", base: 4, odd: 0.3, sort: i => n(i) / td(i, 16), shield: "spanish"},
// rare real-world exotic
- {name: "Kiswaili", base: 28, odd: 0.05, sort: i => n(i) / td(i, 29) / bd(i, [1, 3, 5, 7]), shield: "vesicaPiscis"},
+ {
+ name: "Kiswaili",
+ base: 28,
+ odd: 0.05,
+ sort: i => n(i) / td(i, 29) / bd(i, [1, 3, 5, 7]),
+ shield: "vesicaPiscis"
+ },
{name: "Yoruba", base: 21, odd: 0.05, sort: i => n(i) / td(i, 15) / bd(i, [5, 7]), shield: "vesicaPiscis"},
{name: "Koryo", base: 10, odd: 0.05, sort: i => n(i) / td(i, 12) / t[i], shield: "round"},
{name: "Hantzu", base: 11, odd: 0.05, sort: i => n(i) / td(i, 13), shield: "banner"},
{name: "Yamoto", base: 12, odd: 0.05, sort: i => n(i) / td(i, 15) / t[i], shield: "round"},
{name: "Guantzu", base: 30, odd: 0.05, sort: i => n(i) / td(i, 17), shield: "banner"},
- {name: "Ulus", base: 31, odd: 0.05, sort: i => (n(i) / td(i, 5) / bd(i, [2, 4, 10], 7)) * t[i], shield: "banner"},
+ {
+ name: "Ulus",
+ base: 31,
+ odd: 0.05,
+ sort: i => (n(i) / td(i, 5) / bd(i, [2, 4, 10], 7)) * t[i],
+ shield: "banner"
+ },
{name: "Turan", base: 16, odd: 0.05, sort: i => n(i) / td(i, 12), shield: "round"},
- {name: "Berberan", base: 17, odd: 0.05, sort: i => (n(i) / td(i, 19) / bd(i, [1, 2, 3], 7)) * t[i], shield: "round"},
- {name: "Eurabic", base: 18, odd: 0.05, sort: i => (n(i) / td(i, 26) / bd(i, [1, 2], 7)) * t[i], shield: "round"},
+ {
+ name: "Berberan",
+ base: 17,
+ odd: 0.05,
+ sort: i => (n(i) / td(i, 19) / bd(i, [1, 2, 3], 7)) * t[i],
+ shield: "round"
+ },
+ {
+ name: "Eurabic",
+ base: 18,
+ odd: 0.05,
+ sort: i => (n(i) / td(i, 26) / bd(i, [1, 2], 7)) * t[i],
+ shield: "round"
+ },
{name: "Slovan", base: 5, odd: 0.05, sort: i => (n(i) / td(i, 6)) * t[i], shield: "round"},
- {name: "Keltan", base: 22, odd: 0.1, sort: i => n(i) / td(i, 11) ** 0.5 / bd(i, [6, 8]), shield: "vesicaPiscis"},
+ {
+ name: "Keltan",
+ base: 22,
+ odd: 0.1,
+ sort: i => n(i) / td(i, 11) ** 0.5 / bd(i, [6, 8]),
+ shield: "vesicaPiscis"
+ },
{name: "Elladan", base: 7, odd: 0.2, sort: i => (n(i) / td(i, 18) / sf(i)) * h[i], shield: "boeotian"},
{name: "Romian", base: 8, odd: 0.2, sort: i => n(i) / td(i, 14) / t[i], shield: "roman"},
// fantasy races
@@ -350,12 +442,24 @@ window.Cultures = (function () {
{name: "Nawatli", base: 14, odd: 0.1, sort: i => h[i] / td(i, 18) / bd(i, [7]), shield: "square"},
{name: "Vengrian", base: 15, odd: 0.2, sort: i => (n(i) / td(i, 11) / bd(i, [4])) * t[i], shield: "wedged"},
{name: "Turchian", base: 16, odd: 0.2, sort: i => n(i) / td(i, 13), shield: "round"},
- {name: "Berberan", base: 17, odd: 0.1, sort: i => (n(i) / td(i, 19) / bd(i, [1, 2, 3], 7)) * t[i], shield: "round"},
+ {
+ name: "Berberan",
+ base: 17,
+ odd: 0.1,
+ sort: i => (n(i) / td(i, 19) / bd(i, [1, 2, 3], 7)) * t[i],
+ shield: "round"
+ },
{name: "Eurabic", base: 18, odd: 0.2, sort: i => (n(i) / td(i, 26) / bd(i, [1, 2], 7)) * t[i], shield: "round"},
{name: "Inuk", base: 19, odd: 0.05, sort: i => td(i, -1) / bd(i, [10, 11]) / sf(i), shield: "square"},
{name: "Euskati", base: 20, odd: 0.05, sort: i => (n(i) / td(i, 15)) * h[i], shield: "spanish"},
{name: "Yoruba", base: 21, odd: 0.05, sort: i => n(i) / td(i, 15) / bd(i, [5, 7]), shield: "vesicaPiscis"},
- {name: "Keltan", base: 22, odd: 0.05, sort: i => (n(i) / td(i, 11) / bd(i, [6, 8])) * t[i], shield: "vesicaPiscis"},
+ {
+ name: "Keltan",
+ base: 22,
+ odd: 0.05,
+ sort: i => (n(i) / td(i, 11) / bd(i, [6, 8])) * t[i],
+ shield: "vesicaPiscis"
+ },
{name: "Efratic", base: 23, odd: 0.05, sort: i => (n(i) / td(i, 22)) * t[i], shield: "diamond"},
{name: "Tehrani", base: 24, odd: 0.1, sort: i => (n(i) / td(i, 18)) * h[i], shield: "round"},
{name: "Maui", base: 25, odd: 0.05, sort: i => n(i) / td(i, 24) / sf(i) / t[i], shield: "round"},
@@ -394,7 +498,8 @@ window.Cultures = (function () {
const heightCost = getHeightCost(e, cells.h[e], type);
const riverCost = getRiverCost(cells.r[e], e, type);
const typeCost = getTypeCost(cells.t[e], type);
- const totalCost = p + (biomeCost + biomeChangeCost + heightCost + riverCost + typeCost) / pack.cultures[c].expansionism;
+ const totalCost =
+ p + (biomeCost + biomeChangeCost + heightCost + riverCost + typeCost) / pack.cultures[c].expansionism;
if (totalCost > neutral) return;
diff --git a/modules/dynamic/auto-update.js b/modules/dynamic/auto-update.js
index 6df4b634..fdb758de 100644
--- a/modules/dynamic/auto-update.js
+++ b/modules/dynamic/auto-update.js
@@ -30,8 +30,18 @@ export function resolveVersionConflicts(version) {
.attr("stroke-dasharray", null)
.attr("stroke-linecap", null)
.attr("filter", null);
- stateBorders.attr("opacity", 0.8).attr("stroke", "#56566d").attr("stroke-width", 1).attr("stroke-dasharray", "2").attr("stroke-linecap", "butt");
- provinceBorders.attr("opacity", 0.8).attr("stroke", "#56566d").attr("stroke-width", 0.5).attr("stroke-dasharray", "1").attr("stroke-linecap", "butt");
+ stateBorders
+ .attr("opacity", 0.8)
+ .attr("stroke", "#56566d")
+ .attr("stroke-width", 1)
+ .attr("stroke-dasharray", "2")
+ .attr("stroke-linecap", "butt");
+ provinceBorders
+ .attr("opacity", 0.8)
+ .attr("stroke", "#56566d")
+ .attr("stroke-width", 0.5)
+ .attr("stroke-dasharray", "1")
+ .attr("stroke-linecap", "butt");
// v1.0 added state relations, provinces, forms and full names
provs = viewbox.insert("g", "#borders").attr("id", "provs").attr("opacity", 0.6);
@@ -47,7 +57,12 @@ export function resolveVersionConflicts(version) {
// v1.0 added zones layer
zones = viewbox.insert("g", "#borders").attr("id", "zones").attr("display", "none");
- zones.attr("opacity", 0.6).attr("stroke", null).attr("stroke-width", 0).attr("stroke-dasharray", null).attr("stroke-linecap", "butt");
+ zones
+ .attr("opacity", 0.6)
+ .attr("stroke", null)
+ .attr("stroke-width", 0)
+ .attr("stroke-dasharray", null)
+ .attr("stroke-linecap", "butt");
addZones();
if (!markers.selectAll("*").size()) {
Markers.generate();
@@ -55,9 +70,23 @@ export function resolveVersionConflicts(version) {
}
// v1.0 add fogging layer (state focus)
- fogging = viewbox.insert("g", "#ruler").attr("id", "fogging-cont").attr("mask", "url(#fog)").append("g").attr("id", "fogging").style("display", "none");
+ fogging = viewbox
+ .insert("g", "#ruler")
+ .attr("id", "fogging-cont")
+ .attr("mask", "url(#fog)")
+ .append("g")
+ .attr("id", "fogging")
+ .style("display", "none");
fogging.append("rect").attr("x", 0).attr("y", 0).attr("width", "100%").attr("height", "100%");
- defs.append("mask").attr("id", "fog").append("rect").attr("x", 0).attr("y", 0).attr("width", "100%").attr("height", "100%").attr("fill", "white");
+ defs
+ .append("mask")
+ .attr("id", "fog")
+ .append("rect")
+ .attr("x", 0)
+ .attr("y", 0)
+ .attr("width", "100%")
+ .attr("height", "100%")
+ .attr("fill", "white");
// v1.0 changes states opacity bask to regions level
if (statesBody.attr("opacity")) {
@@ -103,12 +132,24 @@ export function resolveVersionConflicts(version) {
if (!document.getElementById("freshwater")) {
lakes.append("g").attr("id", "freshwater");
- lakes.select("#freshwater").attr("opacity", 0.5).attr("fill", "#a6c1fd").attr("stroke", "#5f799d").attr("stroke-width", 0.7).attr("filter", null);
+ lakes
+ .select("#freshwater")
+ .attr("opacity", 0.5)
+ .attr("fill", "#a6c1fd")
+ .attr("stroke", "#5f799d")
+ .attr("stroke-width", 0.7)
+ .attr("filter", null);
}
if (!document.getElementById("salt")) {
lakes.append("g").attr("id", "salt");
- lakes.select("#salt").attr("opacity", 0.5).attr("fill", "#409b8a").attr("stroke", "#388985").attr("stroke-width", 0.7).attr("filter", null);
+ lakes
+ .select("#salt")
+ .attr("opacity", 0.5)
+ .attr("fill", "#409b8a")
+ .attr("stroke", "#388985")
+ .attr("stroke-width", 0.7)
+ .attr("filter", null);
}
// v1.1 added new lake and coast groups
@@ -116,14 +157,42 @@ export function resolveVersionConflicts(version) {
lakes.append("g").attr("id", "sinkhole");
lakes.append("g").attr("id", "frozen");
lakes.append("g").attr("id", "lava");
- lakes.select("#sinkhole").attr("opacity", 1).attr("fill", "#5bc9fd").attr("stroke", "#53a3b0").attr("stroke-width", 0.7).attr("filter", null);
- lakes.select("#frozen").attr("opacity", 0.95).attr("fill", "#cdd4e7").attr("stroke", "#cfe0eb").attr("stroke-width", 0).attr("filter", null);
- lakes.select("#lava").attr("opacity", 0.7).attr("fill", "#90270d").attr("stroke", "#f93e0c").attr("stroke-width", 2).attr("filter", "url(#crumpled)");
+ lakes
+ .select("#sinkhole")
+ .attr("opacity", 1)
+ .attr("fill", "#5bc9fd")
+ .attr("stroke", "#53a3b0")
+ .attr("stroke-width", 0.7)
+ .attr("filter", null);
+ lakes
+ .select("#frozen")
+ .attr("opacity", 0.95)
+ .attr("fill", "#cdd4e7")
+ .attr("stroke", "#cfe0eb")
+ .attr("stroke-width", 0)
+ .attr("filter", null);
+ lakes
+ .select("#lava")
+ .attr("opacity", 0.7)
+ .attr("fill", "#90270d")
+ .attr("stroke", "#f93e0c")
+ .attr("stroke-width", 2)
+ .attr("filter", "url(#crumpled)");
coastline.append("g").attr("id", "sea_island");
coastline.append("g").attr("id", "lake_island");
- coastline.select("#sea_island").attr("opacity", 0.5).attr("stroke", "#1f3846").attr("stroke-width", 0.7).attr("filter", "url(#dropShadow)");
- coastline.select("#lake_island").attr("opacity", 1).attr("stroke", "#7c8eaf").attr("stroke-width", 0.35).attr("filter", null);
+ coastline
+ .select("#sea_island")
+ .attr("opacity", 0.5)
+ .attr("stroke", "#1f3846")
+ .attr("stroke-width", 0.7)
+ .attr("filter", "url(#dropShadow)");
+ coastline
+ .select("#lake_island")
+ .attr("opacity", 1)
+ .attr("stroke", "#7c8eaf")
+ .attr("stroke-width", 0.35)
+ .attr("filter", null);
}
// v1.1 features stores more data
@@ -203,7 +272,13 @@ export function resolveVersionConflicts(version) {
// v1.3 added militry layer
armies = viewbox.insert("g", "#icons").attr("id", "armies");
- armies.attr("opacity", 1).attr("fill-opacity", 1).attr("font-size", 6).attr("box-size", 3).attr("stroke", "#000").attr("stroke-width", 0.3);
+ armies
+ .attr("opacity", 1)
+ .attr("fill-opacity", 1)
+ .attr("font-size", 6)
+ .attr("box-size", 3)
+ .attr("stroke", "#000")
+ .attr("stroke-width", 0.3);
turnButtonOn("toggleMilitary");
Military.generate();
}
@@ -212,12 +287,23 @@ export function resolveVersionConflicts(version) {
// v1.35 added dry lakes
if (!lakes.select("#dry").size()) {
lakes.append("g").attr("id", "dry");
- lakes.select("#dry").attr("opacity", 1).attr("fill", "#c9bfa7").attr("stroke", "#8e816f").attr("stroke-width", 0.7).attr("filter", null);
+ lakes
+ .select("#dry")
+ .attr("opacity", 1)
+ .attr("fill", "#c9bfa7")
+ .attr("stroke", "#8e816f")
+ .attr("stroke-width", 0.7)
+ .attr("filter", null);
}
// v1.4 added ice layer
ice = viewbox.insert("g", "#coastline").attr("id", "ice").style("display", "none");
- ice.attr("opacity", null).attr("fill", "#e8f0f6").attr("stroke", "#e8f0f6").attr("stroke-width", 1).attr("filter", "url(#dropShadow05)");
+ ice
+ .attr("opacity", null)
+ .attr("fill", "#e8f0f6")
+ .attr("stroke", "#e8f0f6")
+ .attr("stroke-width", 1)
+ .attr("filter", "url(#dropShadow05)");
drawIce();
// v1.4 added icon and power attributes for units
@@ -530,4 +616,17 @@ export function resolveVersionConflicts(version) {
// v1.84.0 moved intial screen out of maon svg
svg.select("#initial").remove();
}
+
+ if (version < 1.86) {
+ // v1.86.0 added multi-origin culture and religion hierarchy trees
+ for (const culture of pack.cultures) {
+ culture.origins = [culture.origin];
+ delete culture.origin;
+ }
+
+ for (const religion of pack.religions) {
+ religion.origins = [religion.origin];
+ delete religion.origin;
+ }
+ }
}
diff --git a/modules/dynamic/editors/cultures-editor.js b/modules/dynamic/editors/cultures-editor.js
index b3003584..613f1328 100644
--- a/modules/dynamic/editors/cultures-editor.js
+++ b/modules/dynamic/editors/cultures-editor.js
@@ -115,7 +115,9 @@ function refreshCulturesEditor() {
function culturesCollectStatistics() {
const {cells, cultures, burgs} = pack;
- cultures.forEach(c => (c.cells = c.area = c.rural = c.urban = 0));
+ cultures.forEach(c => {
+ c.cells = c.area = c.rural = c.urban = 0;
+ });
for (const i of cells.i) {
if (cells.h[i] < 20) continue;
@@ -143,7 +145,9 @@ function culturesEditorAddLines() {
const rural = c.rural * populationRate;
const urban = c.urban * populationRate * urbanization;
const population = rn(rural + urban);
- const populationTip = `Total population: ${si(population)}; Rural population: ${si(rural)}; Urban population: ${si(urban)}. Click to edit`;
+ const populationTip = `Total population: ${si(population)}. Rural population: ${si(rural)}. Urban population: ${si(
+ urban
+ )}. Click to edit`;
totalArea += area;
totalPopulation += population;
@@ -151,13 +155,13 @@ function culturesEditorAddLines() {
// Uncultured (neutral) line
lines += /* html */ `
${getTypeOptions(c.type)}
-
${getBaseOptions(c.base)}
+
${getBaseOptions(c.base)}
${c.cells}
@@ -175,7 +180,8 @@ function culturesEditorAddLines() {
${si(area)} ${unit}
-
${si(population)}
+
${si(population)}
${getShapeOptions(selectShape, c.shield)}
`;
@@ -184,23 +190,25 @@ function culturesEditorAddLines() {
lines += /* html */ `
-
${getTypeOptions(c.type)}
-
${getBaseOptions(c.base)}
+
${getTypeOptions(c.type)}
+
${getBaseOptions(c.base)}
${c.cells}
@@ -216,7 +224,8 @@ function culturesEditorAddLines() {
${si(area)} ${unit}
-
${si(population)}
+
${si(population)}
${getShapeOptions(selectShape, c.shield)}
@@ -245,7 +254,7 @@ function culturesEditorAddLines() {
$body.querySelectorAll("div > select.cultureEmblems").forEach(el => el.on("change", cultureChangeEmblemsShape));
$body.querySelectorAll("div > div.culturePopulation").forEach(el => el.on("click", changePopulation));
$body.querySelectorAll("div > span.icon-arrows-cw").forEach(el => el.on("click", cultureRegenerateBurgs));
- $body.querySelectorAll("div > span.icon-trash-empty").forEach(el => el.on("click", cultureRemove));
+ $body.querySelectorAll("div > span.icon-trash-empty").forEach(el => el.on("click", cultureRemovePrompt));
const $culturesHeader = byId("culturesHeader");
$culturesHeader.querySelector("div[data-sortby='emblems']").style.display = selectShape ? "inline-block" : "none";
@@ -276,23 +285,22 @@ function getShapeOptions(selectShape, selected) {
const shapes = Object.keys(COA.shields.types)
.map(type => Object.keys(COA.shields[type]))
.flat();
- const options = shapes.map(shape => `
${capitalize(shape)} `);
+ const options = shapes.map(
+ shape => `
${capitalize(shape)} `
+ );
return `
${options} `;
}
function cultureHighlightOn(event) {
- const culture = +event.target.dataset.id;
+ const cultureId = Number(event.id || event.target.dataset.id);
const $info = byId("cultureInfo");
if ($info) {
- d3.select("#hierarchy")
- .select("g[data-id='" + culture + "'] > path")
- .classed("selected", 1);
- const c = pack.cultures[culture];
- const rural = c.rural * populationRate;
- const urban = c.urban * populationRate * urbanization;
- const population = rural + urban > 0 ? si(rn(rural + urban)) + " people" : "Extinct";
- $info.innerHTML = `${c.name} culture. ${c.type}. ${population}`;
- tip("Drag to change parent, drag to itself to move to the top level. Hold CTRL and click to change abbreviation");
+ d3.select("#hierarchy").select(`g[data-id='${cultureId}']`).classed("selected", 1);
+ const {name, type, rural, urban} = pack.cultures[cultureId];
+ const population = rural * populationRate + urban * populationRate * urbanization;
+ const populationText = population > 0 ? si(rn(population)) + " people" : "Extinct";
+ $info.innerHTML = `${name} culture. ${type}. ${populationText}`;
+ tip("Drag to other node to add parent, click to edit");
}
if (!layerIsOn("toggleCultures")) return;
@@ -300,13 +308,13 @@ function cultureHighlightOn(event) {
const animate = d3.transition().duration(2000).ease(d3.easeSinIn);
cults
- .select("#culture" + culture)
+ .select("#culture" + cultureId)
.raise()
.transition(animate)
.attr("stroke-width", 2.5)
.attr("stroke", "#d0240f");
debug
- .select("#cultureCenter" + culture)
+ .select("#cultureCenter" + cultureId)
.raise()
.transition(animate)
.attr("r", 8)
@@ -314,24 +322,23 @@ function cultureHighlightOn(event) {
}
function cultureHighlightOff(event) {
- const culture = +event.target.dataset.id;
+ const cultureId = Number(event.id || event.target.dataset.id);
+
const $info = byId("cultureInfo");
if ($info) {
- d3.select("#hierarchy")
- .select("g[data-id='" + culture + "'] > path")
- .classed("selected", 0);
+ d3.select("#hierarchy").select(`g[data-id='${cultureId}']`).classed("selected", 0);
$info.innerHTML = "";
tip("");
}
if (!layerIsOn("toggleCultures")) return;
cults
- .select("#culture" + culture)
+ .select("#culture" + cultureId)
.transition()
.attr("stroke-width", null)
.attr("stroke", null);
debug
- .select("#cultureCenter" + culture)
+ .select("#cultureCenter" + cultureId)
.transition()
.attr("r", 6)
.attr("stroke", null);
@@ -340,16 +347,16 @@ function cultureHighlightOff(event) {
function cultureChangeColor() {
const $el = this;
const currentFill = $el.getAttribute("fill");
- const culture = +$el.parentNode.dataset.id;
+ const cultureId = +$el.parentNode.dataset.id;
const callback = newFill => {
$el.fill = newFill;
- pack.cultures[culture].color = newFill;
+ pack.cultures[cultureId].color = newFill;
cults
- .select("#culture" + culture)
+ .select("#culture" + cultureId)
.attr("fill", newFill)
.attr("stroke", newFill);
- debug.select("#cultureCenter" + culture).attr("fill", newFill);
+ debug.select("#cultureCenter" + cultureId).attr("fill", newFill);
};
openPicker(currentFill, callback);
@@ -412,7 +419,14 @@ function cultureChangeEmblemsShape() {
});
pack.provinces.forEach(province => {
- if (pack.cells.culture[province.center] !== culture || !province.i || province.removed || !province.coa || province.coa === "custom") return;
+ if (
+ pack.cells.culture[province.center] !== culture ||
+ !province.i ||
+ province.removed ||
+ !province.coa ||
+ province.coa === "custom"
+ )
+ return;
if (shape === province.coa.shield) return;
province.coa.shield = shape;
rerenderCOA("provinceCOA" + province.i, province.coa);
@@ -434,12 +448,20 @@ function changePopulation() {
const rural = rn(culture.rural * populationRate);
const urban = rn(culture.urban * populationRate * urbanization);
const total = rural + urban;
- const l = n => Number(n).toLocaleString();
+ const format = n => Number(n).toLocaleString();
const burgs = pack.burgs.filter(b => !b.removed && b.culture === cultureId);
- alertMessage.innerHTML = /* html */ `Rural:
Urban:
-
-
Total population: ${l(total)} ⇒ ${l(total)} (100 %)
`;
+ alertMessage.innerHTML = /* html */ `
+
Change population of all cells assigned to the culture
+
+ Rural:
+ Urban:
+
+
Total population: ${format(total)} ⇒ ${format(total)}
+ (100 %)
+
+
`;
const update = function () {
const totalNew = ruralPop.valueAsNumber + urbanPop.valueAsNumber;
@@ -522,37 +544,36 @@ function removeCulture(cultureId) {
});
cultures[cultureId].removed = true;
- const origin = cultures[cultureId].origin;
- cultures.forEach(c => {
- if (c.origin === cultureId) c.origin = origin;
- });
+ cultures
+ .filter(c => c.i && !c.removed)
+ .forEach(c => {
+ c.origins = c.origins.filter(origin => origin !== cultureId);
+ if (!c.origins.length) c.origins = [0];
+ });
refreshCulturesEditor();
}
-function cultureRemove() {
- if (customization === 4) return;
- const cultureId = +this.parentNode.dataset.id;
+function cultureRemovePrompt() {
+ if (customization) return;
- alertMessage.innerHTML = "Are you sure you want to remove the culture?
This action cannot be reverted";
- $("#alert").dialog({
- resizable: false,
+ const cultureId = +this.parentNode.dataset.id;
+ confirmationDialog({
title: "Remove culture",
- buttons: {
- Remove: function () {
- removeCulture(cultureId);
- $(this).dialog("close");
- },
- Cancel: function () {
- $(this).dialog("close");
- }
- }
+ message: "Are you sure you want to remove the culture?
This action cannot be reverted",
+ confirm: "Remove",
+ onConfirm: () => removeCulture(cultureId)
});
}
function drawCultureCenters() {
const tooltip = "Drag to move the culture center (ancestral home)";
debug.select("#cultureCenters").remove();
- const cultureCenters = debug.append("g").attr("id", "cultureCenters").attr("stroke-width", 2).attr("stroke", "#444444").style("cursor", "move");
+ const cultureCenters = debug
+ .append("g")
+ .attr("id", "cultureCenters")
+ .attr("stroke-width", 2)
+ .attr("stroke", "#444444")
+ .style("cursor", "move");
const data = pack.cultures.filter(c => c.i && !c.removed);
cultureCenters
@@ -580,22 +601,21 @@ function drawCultureCenters() {
}
function cultureCenterDrag() {
- const el = d3.select(this);
- const c = +this.id.slice(13);
+ const $el = d3.select(this);
+ const cultureId = +this.id.slice(13);
d3.event.on("drag", () => {
- el.attr("cx", d3.event.x).attr("cy", d3.event.y);
- const cell = findCell(d3.event.x, d3.event.y);
+ const {x, y} = d3.event;
+ $el.attr("cx", x).attr("cy", y);
+ const cell = findCell(x, y);
if (pack.cells.h[cell] < 20) return; // ignore dragging on water
- pack.cultures[c].center = cell;
+ pack.cultures[cultureId].center = cell;
recalculateCultures();
});
}
function toggleLegend() {
- if (legend.selectAll("*").size()) {
- clearLegend();
- return;
- } // hide legend
+ if (legend.selectAll("*").size()) return clearLegend();
+
const data = pack.cultures
.filter(c => c.i && !c.removed && c.cells)
.sort((a, b) => b.area - a.area)
@@ -606,14 +626,15 @@ function toggleLegend() {
function togglePercentageMode() {
if ($body.dataset.type === "absolute") {
$body.dataset.type = "percentage";
- const totalCells = +culturesFooterCells.innerHTML;
- const totalArea = +culturesFooterArea.dataset.area;
- const totalPopulation = +culturesFooterPopulation.dataset.population;
+ const totalCells = +byId("culturesFooterCells").innerText;
+ const totalArea = +byId("culturesFooterArea").dataset.area;
+ const totalPopulation = +byId("culturesFooterPopulation").dataset.population;
$body.querySelectorAll(":scope > div").forEach(function (el) {
- el.querySelector(".cultureCells").innerHTML = rn((+el.dataset.cells / totalCells) * 100) + "%";
- el.querySelector(".cultureArea").innerHTML = rn((+el.dataset.area / totalArea) * 100) + "%";
- el.querySelector(".culturePopulation").innerHTML = rn((+el.dataset.population / totalPopulation) * 100) + "%";
+ const {cells, area, population} = el.dataset;
+ el.querySelector(".cultureCells").innerText = rn((+cells / totalCells) * 100) + "%";
+ el.querySelector(".cultureArea").innerText = rn((+area / totalArea) * 100) + "%";
+ el.querySelector(".culturePopulation").innerText = rn((+population / totalPopulation) * 100) + "%";
});
} else {
$body.dataset.type = "absolute";
@@ -623,17 +644,17 @@ function togglePercentageMode() {
function showHierarchy() {
// build hierarchy tree
- pack.cultures[0].origin = null;
+ pack.cultures[0].origins = [null];
const validCultures = pack.cultures.filter(c => !c.removed);
if (validCultures.length < 3) return tip("Not enough cultures to show hierarchy", false, "error");
const root = d3
.stratify()
.id(d => d.i)
- .parentId(d => d.origin)(validCultures);
+ .parentId(d => d.origins[0])(validCultures);
const treeWidth = root.leaves().length;
const treeHeight = root.height;
- const width = treeWidth * 40;
+ const width = Math.max(treeWidth * 40, 300);
const height = treeHeight * 60;
const margin = {top: 10, right: 10, bottom: -5, left: 10};
@@ -641,47 +662,76 @@ function showHierarchy() {
const h = height + 30 - margin.top - margin.bottom;
const treeLayout = d3.tree().size([w, h]);
+ alertMessage.innerHTML = /* html */ `
+
+
+ culture.
+ Abbreviation:
+ Clear
+ Close
+
+
`;
+
// prepare svg
- alertMessage.innerHTML = "
";
const svg = d3
.select("#alertMessage")
- .insert("svg", "#cultureInfo")
+ .insert("svg", "#cultureChartDetails")
.attr("id", "hierarchy")
.attr("width", width)
.attr("height", height)
- .style("text-anchor", "middle");
+ .style("text-anchor", "middle")
+ .style("min-width", "300px");
const graph = svg.append("g").attr("transform", `translate(10, -45)`);
const links = graph.append("g").attr("fill", "none").attr("stroke", "#aaaaaa");
+ const primaryLinks = links.append("g");
+ const secondaryLinks = links.append("g").attr("stroke-dasharray", 1);
const nodes = graph.append("g");
+ // render helper functions
+ const getLinkPath = d => {
+ const {
+ source: {x: sx, y: sy},
+ target: {x: tx, y: ty}
+ } = d;
+ return `M${sx},${sy} C${sx},${(sy * 3 + ty) / 4} ${tx},${(sy * 2 + ty) / 3} ${tx},${ty}`;
+ };
+
+ const getSecondaryLinks = root => {
+ const nodes = root.descendants();
+ const links = [];
+
+ for (const node of nodes) {
+ const origins = node.data.origins;
+ if (node.depth < 2) continue;
+
+ for (let i = 1; i < origins.length; i++) {
+ const source = nodes.find(n => n.data.i === origins[i]);
+ if (source) links.push({source, target: node});
+ }
+ }
+
+ return links;
+ };
+
+ const nodePathMap = {
+ undefined: "M5,0A5,5,0,1,1,-5,0A5,5,0,1,1,5,0", // small circle
+ Generic: "M11.3,0A11.3,11.3,0,1,1,-11.3,0A11.3,11.3,0,1,1,11.3,0", // circle
+ River: "M0,-14L14,0L0,14L-14,0Z", // diamond
+ Lake: "M-6.5,-11.26l13,0l6.5,11.26l-6.5,11.26l-13,0l-6.5,-11.26Z", // hexagon
+ Naval: "M-11,-11h22v22h-22Z", // square
+ Highland: "M-11,-11l11,2l11,-2l-2,11l2,11l-11,-2l-11,2l2,-11Z", // concave square
+ Nomadic: "M-4.97,-12.01 l9.95,0 l7.04,7.04 l0,9.95 l-7.04,7.04 l-9.95,0 l-7.04,-7.04 l0,-9.95Z", // octagon
+ Hunting: "M0,-14l14,11l-6,14h-16l-6,-14Z" // pentagon
+ };
+
+ const getNodePath = d => nodePathMap[d.data.type];
+
renderTree();
function renderTree() {
treeLayout(root);
- links
- .selectAll("path")
- .data(root.links())
- .enter()
- .append("path")
- .attr("d", d => {
- return (
- "M" +
- d.source.x +
- "," +
- d.source.y +
- "C" +
- d.source.x +
- "," +
- (d.source.y * 3 + d.target.y) / 4 +
- " " +
- d.target.x +
- "," +
- (d.source.y * 2 + d.target.y) / 3 +
- " " +
- d.target.x +
- "," +
- d.target.y
- );
- });
+
+ primaryLinks.selectAll("path").data(root.links()).enter().append("path").attr("d", getLinkPath);
+ secondaryLinks.selectAll("path").data(getSecondaryLinks(root)).enter().append("path").attr("d", getLinkPath);
const node = nodes
.selectAll("g")
@@ -691,34 +741,21 @@ function showHierarchy() {
.attr("data-id", d => d.data.i)
.attr("stroke", "#333333")
.attr("transform", d => `translate(${d.x}, ${d.y})`)
- .on("mouseenter", () => cultureHighlightOn(event))
- .on("mouseleave", () => cultureHighlightOff(event))
- .call(d3.drag().on("start", d => dragToReorigin(d)));
+ .on("mouseenter", cultureHighlightOn)
+ .on("mouseleave", cultureHighlightOff)
+ .on("click", cultureSelect)
+ .call(d3.drag().on("start", dragToReorigin));
node
.append("path")
- .attr("d", d => {
- if (!d.data.i) return "M5,0A5,5,0,1,1,-5,0A5,5,0,1,1,5,0";
- // small circle
- else if (d.data.type === "Generic") return "M11.3,0A11.3,11.3,0,1,1,-11.3,0A11.3,11.3,0,1,1,11.3,0";
- // circle
- else if (d.data.type === "River") return "M0,-14L14,0L0,14L-14,0Z";
- // diamond
- else if (d.data.type === "Lake") return "M-6.5,-11.26l13,0l6.5,11.26l-6.5,11.26l-13,0l-6.5,-11.26Z";
- // hexagon
- else if (d.data.type === "Naval") return "M-11,-11h22v22h-22Z"; // square
- if (d.data.type === "Highland") return "M-11,-11l11,2l11,-2l-2,11l2,11l-11,-2l-11,2l2,-11Z"; // concave square
- if (d.data.type === "Nomadic") return "M-4.97,-12.01 l9.95,0 l7.04,7.04 l0,9.95 l-7.04,7.04 l-9.95,0 l-7.04,-7.04 l0,-9.95Z"; // octagon
- if (d.data.type === "Hunting") return "M0,-14l14,11l-6,14h-16l-6,-14Z"; // pentagon
- return "M-11,-11h22v22h-22Z"; // square
- })
- .attr("fill", d => (d.data.i ? d.data.color : "#ffffff"))
+ .attr("d", getNodePath)
+ .attr("fill", d => d.data.color || "#ffffff")
.attr("stroke-dasharray", d => (d.data.cells ? "null" : "1"));
node
.append("text")
.attr("dy", ".35em")
- .text(d => (d.data.i ? d.data.code : ""));
+ .text(d => d.data.code || "");
}
$("#alert").dialog({
@@ -726,15 +763,44 @@ function showHierarchy() {
width: fitContent(),
resizable: false,
position: {my: "left center", at: "left+10 center", of: "svg"},
- buttons: {},
+ buttons: null,
close: () => {
alertMessage.innerHTML = "";
}
});
- function dragToReorigin(d) {
- if (isCtrlClick(d3.event.sourceEvent)) return changeCode(d);
+ function cultureSelect(d) {
+ d3.event.stopPropagation();
+ nodes.selectAll("g").style("outline", "none");
+ this.style.outline = "1px solid #c13119";
+ byId("cultureSelected").style.display = "block";
+ byId("cultureInfo").style.display = "none";
+
+ const culture = d.data;
+ byId("cultureSelectedName").innerText = culture.name;
+ byId("cultureSelectedCode").value = culture.code;
+
+ byId("cultureSelectedCode").onchange = function () {
+ if (this.value.length > 3) return tip("Abbreviation must be 3 characters or less", false, "error", 3000);
+ if (!this.value.length) return tip("Abbreviation cannot be empty", false, "error", 3000);
+ nodes.select(`g[data-id="${d.id}"] > text`).text(this.value);
+ culture.code = this.value;
+ };
+
+ byId("cultureSelectedClear").onclick = () => {
+ culture.origins = [0];
+ showHierarchy();
+ };
+
+ byId("cultureSelectedClose").onclick = () => {
+ this.style.outline = "none";
+ byId("cultureSelected").style.display = "none";
+ byId("cultureInfo").style.display = "block";
+ };
+ }
+
+ function dragToReorigin(d) {
const originLine = graph.append("path").attr("class", "dragLine").attr("d", `M${d.x},${d.y}L${d.x},${d.y}`);
d3.event.on("drag", () => {
@@ -743,26 +809,20 @@ function showHierarchy() {
d3.event.on("end", () => {
originLine.remove();
- const selected = graph.select("path.selected");
+ const selected = graph.select("g.selected");
if (!selected.size()) return;
- const culture = d.data.i;
- const oldOrigin = d.data.origin;
- let newOrigin = selected.datum().data.i;
- if (newOrigin == oldOrigin) return; // already a child of the selected node
- if (newOrigin == culture) newOrigin = 0; // move to top
- if (newOrigin && d.descendants().some(node => node.id == newOrigin)) return; // cannot be a child of its own child
- pack.cultures[culture].origin = d.data.origin = newOrigin; // change data
- showHierarchy(); // update hierarchy
- });
- }
- function changeCode(d) {
- prompt(`Please provide an abbreviation for culture: ${d.data.name}`, {default: d.data.code}, v => {
- pack.cultures[d.data.i].code = v;
- nodes
- .select("g[data-id='" + d.data.i + "']")
- .select("text")
- .text(v);
+ const cultureId = d.data.i;
+ const newOrigin = selected.datum().data.i;
+ if (cultureId === newOrigin) return; // dragged to itself
+ if (d.data.origins.includes(newOrigin)) return; // already a child of the selected node
+ if (d.descendants().some(node => node.data.i === newOrigin)) return; // cannot be a child of its own child
+
+ const culture = pack.cultures[cultureId];
+ if (culture.origins[0] === 0) culture.origins = [];
+ culture.origins.push(newOrigin);
+
+ showHierarchy();
});
}
}
@@ -853,7 +913,13 @@ function changeCultureForSelection(selection) {
// change of append new element
if (exists.size()) exists.attr("data-culture", cultureNew).attr("fill", color).attr("stroke", color);
else
- temp.append("polygon").attr("data-cell", i).attr("data-culture", cultureNew).attr("points", getPackPolygon(i)).attr("fill", color).attr("stroke", color);
+ temp
+ .append("polygon")
+ .attr("data-cell", i)
+ .attr("data-culture", cultureNew)
+ .attr("points", getPackPolygon(i))
+ .attr("fill", color)
+ .attr("stroke", color);
});
}
@@ -921,7 +987,8 @@ function addCulture() {
const point = d3.mouse(this);
const center = findCell(point[0], point[1]);
- if (pack.cells.h[center] < 20) return tip("You cannot place culture center into the water. Please click on a land cell", false, "error");
+ if (pack.cells.h[center] < 20)
+ return tip("You cannot place culture center into the water. Please click on a land cell", false, "error");
const occupied = pack.cultures.some(c => !c.removed && c.center === center);
if (occupied) return tip("This cell is already a culture center. Please select a different cell", false, "error");
@@ -934,13 +1001,15 @@ function addCulture() {
function downloadCulturesCsv() {
const unit = getAreaUnit("2");
- const headers = `Id,Name,Color,Cells,Expansionism,Type,Area ${unit},Population,Namesbase,Emblems Shape,Origin`;
+ const headers = `Id,Name,Color,Cells,Expansionism,Type,Area ${unit},Population,Namesbase,Emblems Shape,Origins`;
const lines = Array.from($body.querySelectorAll(":scope > div"));
const data = lines.map($line => {
const {id, name, color, cells, expansionism, type, area, population, emblems, base} = $line.dataset;
const namesbase = nameBases[+base].name;
- const {origin} = pack.cultures[+id];
- return [id, name, color, cells, expansionism, type, area, population, namesbase, emblems, origin].join(",");
+ const {origins} = pack.cultures[+id];
+ const originList = origins.filter(origin => origin).map(origin => pack.cultures[origin].name);
+ const originText = '"' + originList.join(", ") + '"';
+ return [id, name, color, cells, expansionism, type, area, population, namesbase, emblems, originText].join(",");
});
const csvData = [headers].concat(data).join("\n");
@@ -989,7 +1058,7 @@ async function uploadCulturesData() {
current.color = c.color;
current.expansionism = +c.expansionism;
- current.origin = +c.origin;
+ current.origins = JSON.parse(c.origins);
if (cultureTypes.includes(c.type)) current.type = c.type;
else current.type = "Generic";
diff --git a/modules/dynamic/editors/religions-editor.js b/modules/dynamic/editors/religions-editor.js
new file mode 100644
index 00000000..03f43f26
--- /dev/null
+++ b/modules/dynamic/editors/religions-editor.js
@@ -0,0 +1,924 @@
+const $body = insertEditorHtml();
+addListeners();
+
+export function open() {
+ closeDialogs("#religionsEditor, .stable");
+ if (!layerIsOn("toggleCultures")) toggleCultures();
+ if (layerIsOn("toggleStates")) toggleStates();
+ if (layerIsOn("toggleBiomes")) toggleBiomes();
+ if (layerIsOn("toggleReligions")) toggleReligions();
+ if (layerIsOn("toggleProvinces")) toggleProvinces();
+
+ refreshReligionsEditor();
+ drawReligionCenters();
+
+ $("#religionsEditor").dialog({
+ title: "Religions Editor",
+ resizable: false,
+ close: closeReligionsEditor,
+ position: {my: "right top", at: "right-10 top+10", of: "svg"}
+ });
+ $body.focus();
+}
+
+function insertEditorHtml() {
+ const editorHtml = /* html */ `
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Brush size:
+
+
+
+
+
+
+
+
+
`;
+
+ byId("dialogs").insertAdjacentHTML("beforeend", editorHtml);
+ return byId("religionsBody");
+}
+
+function addListeners() {
+ applySortingByHeader("religionsHeader");
+
+ byId("religionsEditorRefresh").on("click", refreshReligionsEditor);
+ byId("religionsEditStyle").on("click", () => editStyle("relig"));
+ byId("religionsLegend").on("click", toggleLegend);
+ byId("religionsPercentage").on("click", togglePercentageMode);
+ byId("religionsHeirarchy").on("click", showHierarchy);
+ byId("religionsExtinct").on("click", toggleExtinct);
+ byId("religionsManually").on("click", enterReligionsManualAssignent);
+ byId("religionsManuallyApply").on("click", applyReligionsManualAssignent);
+ byId("religionsManuallyCancel").on("click", () => exitReligionsManualAssignment());
+ byId("religionsAdd").on("click", enterAddReligionMode);
+ byId("religionsExport").on("click", downloadReligionsCsv);
+}
+
+function refreshReligionsEditor() {
+ religionsCollectStatistics();
+ religionsEditorAddLines();
+}
+
+function religionsCollectStatistics() {
+ const {cells, religions, burgs} = pack;
+ religions.forEach(r => {
+ r.cells = r.area = r.rural = r.urban = 0;
+ });
+
+ for (const i of cells.i) {
+ if (cells.h[i] < 20) continue;
+ const religionId = cells.religion[i];
+ religions[religionId].cells += 1;
+ religions[religionId].area += cells.area[i];
+ religions[religionId].rural += cells.pop[i];
+ const burgId = cells.burg[i];
+ if (burgId) religions[religionId].urban += burgs[burgId].population;
+ }
+}
+
+// add line for each religion
+function religionsEditorAddLines() {
+ const unit = " " + getAreaUnit();
+ let lines = "";
+ let totalArea = 0;
+ let totalPopulation = 0;
+
+ for (const r of pack.religions) {
+ if (r.removed) continue;
+ if (r.i && !r.cells && $body.dataset.extinct !== "show") continue; // hide extinct religions
+
+ const area = getArea(r.area);
+ const rural = r.rural * populationRate;
+ const urban = r.urban * populationRate * urbanization;
+ const population = rn(rural + urban);
+ const populationTip = `Believers: ${si(population)}; Rural areas: ${si(rural)}; Urban areas: ${si(
+ urban
+ )}. Click to change`;
+ totalArea += area;
+ totalPopulation += population;
+
+ if (!r.i) {
+ // No religion (neutral) line
+ lines += /* html */ `
+
+
+
+ ${getTypeOptions(r.type)}
+
+
+
+
+
+
${si(area) + unit}
+
+
${si(population)}
+
`;
+ continue;
+ }
+
+ lines += /* html */ `
+
+
+
+ ${getTypeOptions(r.type)}
+
+
+
+
+
+
${si(area) + unit}
+
+
${si(population)}
+
+
`;
+ }
+ $body.innerHTML = lines;
+
+ // update footer
+ const validReligions = pack.religions.filter(r => r.i && !r.removed);
+ byId("religionsOrganized").innerHTML = validReligions.filter(r => r.type === "Organized").length;
+ byId("religionsHeresies").innerHTML = validReligions.filter(r => r.type === "Heresy").length;
+ byId("religionsCults").innerHTML = validReligions.filter(r => r.type === "Cult").length;
+ byId("religionsFolk").innerHTML = validReligions.filter(r => r.type === "Folk").length;
+ byId("religionsFooterArea").innerHTML = si(totalArea) + unit;
+ byId("religionsFooterPopulation").innerHTML = si(totalPopulation);
+ byId("religionsFooterArea").dataset.area = totalArea;
+ byId("religionsFooterPopulation").dataset.population = totalPopulation;
+
+ // add listeners
+ $body.querySelectorAll("div.religions").forEach(el => el.on("mouseenter", religionHighlightOn));
+ $body.querySelectorAll("div.religions").forEach(el => el.on("mouseleave", religionHighlightOff));
+ $body.querySelectorAll("div.states").forEach(el => el.on("click", selectReligionOnLineClick));
+ $body.querySelectorAll("fill-box").forEach(el => el.on("click", religionChangeColor));
+ $body.querySelectorAll("div > input.religionName").forEach(el => el.on("input", religionChangeName));
+ $body.querySelectorAll("div > select.religionType").forEach(el => el.on("change", religionChangeType));
+ $body.querySelectorAll("div > input.religionForm").forEach(el => el.on("input", religionChangeForm));
+ $body.querySelectorAll("div > input.religionDeity").forEach(el => el.on("input", religionChangeDeity));
+ $body.querySelectorAll("div > span.icon-arrows-cw").forEach(el => el.on("click", regenerateDeity));
+ $body.querySelectorAll("div > div.religionPopulation").forEach(el => el.on("click", changePopulation));
+ $body.querySelectorAll("div > span.icon-trash-empty").forEach(el => el.on("click", religionRemovePrompt));
+
+ if ($body.dataset.type === "percentage") {
+ $body.dataset.type = "absolute";
+ togglePercentageMode();
+ }
+ applySorting(religionsHeader);
+ $("#religionsEditor").dialog({width: fitContent()});
+}
+
+function getTypeOptions(type) {
+ let options = "";
+ const types = ["Folk", "Organized", "Cult", "Heresy"];
+ types.forEach(t => (options += `
${t} `));
+ return options;
+}
+
+function religionHighlightOn(event) {
+ const religionId = Number(event.id || event.target.dataset.id);
+ const $info = byId("religionInfo");
+ if ($info) {
+ d3.select("#hierarchy").select(`g[data-id='${religionId}']`).classed("selected", 1);
+ const {name, type, form, rural, urban} = pack.religions[religionId];
+
+ const getTypeText = () => {
+ if (name.includes(type)) return "";
+ if (form.includes(type)) return "";
+ if (type === "Folk" || type === "Organized") return `. ${type} religion`;
+ return `. ${type}`;
+ };
+ const formText = form === type ? "" : ". " + form;
+ const population = rural * populationRate + urban * populationRate * urbanization;
+ const populationText = population > 0 ? si(rn(population)) + " people" : "Extinct";
+
+ $info.innerHTML = `${name}${getTypeText()}${formText}. ${populationText}`;
+ tip("Drag to other node to add parent, click to edit");
+ }
+
+ const $el = $body.querySelector(`div[data-id='${religionId}']`);
+ if ($el) $el.classList.add("active");
+
+ if (!layerIsOn("toggleReligions")) return;
+ if (customization) return;
+
+ const animate = d3.transition().duration(1500).ease(d3.easeSinIn);
+ relig
+ .select("#religion" + religionId)
+ .raise()
+ .transition(animate)
+ .attr("stroke-width", 2.5)
+ .attr("stroke", "#c13119");
+ debug
+ .select("#religionsCenter" + religionId)
+ .raise()
+ .transition(animate)
+ .attr("r", 8)
+ .attr("stroke-width", 2)
+ .attr("stroke", "#c13119");
+}
+
+function religionHighlightOff(event) {
+ const religionId = Number(event.id || event.target.dataset.id);
+ const $info = byId("religionInfo");
+ if ($info) {
+ d3.select("#hierarchy").select(`g[data-id='${religionId}']`).classed("selected", 0);
+ $info.innerHTML = "";
+ tip("");
+ }
+
+ const $el = $body.querySelector(`div[data-id='${religionId}']`);
+ if ($el) $el.classList.remove("active");
+
+ relig
+ .select("#religion" + religionId)
+ .transition()
+ .attr("stroke-width", null)
+ .attr("stroke", null);
+ debug
+ .select("#religionsCenter" + religionId)
+ .transition()
+ .attr("r", 4)
+ .attr("stroke-width", 1.2)
+ .attr("stroke", null);
+}
+
+function religionChangeColor() {
+ const $el = this;
+ const currentFill = $el.getAttribute("fill");
+ const religionId = +$el.parentNode.dataset.id;
+
+ const callback = newFill => {
+ $el.fill = newFill;
+ pack.religions[religionId].color = newFill;
+ relig.select("#religion" + religionId).attr("fill", newFill);
+ debug.select("#religionsCenter" + religionId).attr("fill", newFill);
+ };
+
+ openPicker(currentFill, callback);
+}
+
+function religionChangeName() {
+ const religionId = +this.parentNode.dataset.id;
+ this.parentNode.dataset.name = this.value;
+ pack.religions[religionId].name = this.value;
+ pack.religions[religionId].code = abbreviate(
+ this.value,
+ pack.religions.map(c => c.code)
+ );
+}
+
+function religionChangeType() {
+ const religionId = +this.parentNode.dataset.id;
+ this.parentNode.dataset.type = this.value;
+ pack.religions[religionId].type = this.value;
+}
+
+function religionChangeForm() {
+ const religionId = +this.parentNode.dataset.id;
+ this.parentNode.dataset.form = this.value;
+ pack.religions[religionId].form = this.value;
+}
+
+function religionChangeDeity() {
+ const religionId = +this.parentNode.dataset.id;
+ this.parentNode.dataset.deity = this.value;
+ pack.religions[religionId].deity = this.value;
+}
+
+function regenerateDeity() {
+ const religionId = +this.parentNode.dataset.id;
+ const cultureId = pack.religions[religionId].culture;
+ const deity = Religions.getDeityName(cultureId);
+ this.parentNode.dataset.deity = deity;
+ pack.religions[religionId].deity = deity;
+ this.nextElementSibling.value = deity;
+}
+
+function changePopulation() {
+ const religionId = +this.parentNode.dataset.id;
+ const religion = pack.religions[religionId];
+ if (!religion.cells) return tip("Religion does not have any cells, cannot change population", false, "error");
+
+ const rural = rn(religion.rural * populationRate);
+ const urban = rn(religion.urban * populationRate * urbanization);
+ const total = rural + urban;
+ const format = n => Number(n).toLocaleString();
+ const burgs = pack.burgs.filter(b => !b.removed && pack.cells.religion[b.cell] === religionId);
+
+ alertMessage.innerHTML = /* html */ `
+
All population of religion territory is considered believers of this religion. It means believers number change will directly affect population
+
+ Rural:
+ Urban:
+
+
Total population: ${format(total)} ⇒ ${format(total)}
+ (100 %)
+
+
`;
+
+ const update = function () {
+ const totalNew = ruralPop.valueAsNumber + urbanPop.valueAsNumber;
+ if (isNaN(totalNew)) return;
+ totalPop.innerHTML = format(totalNew);
+ totalPopPerc.innerHTML = rn((totalNew / total) * 100);
+ };
+
+ ruralPop.oninput = () => update();
+ urbanPop.oninput = () => update();
+
+ $("#alert").dialog({
+ resizable: false,
+ title: "Change believers number",
+ width: "24em",
+ buttons: {
+ Apply: function () {
+ applyPopulationChange();
+ $(this).dialog("close");
+ },
+ Cancel: function () {
+ $(this).dialog("close");
+ }
+ },
+ position: {my: "center", at: "center", of: "svg"}
+ });
+
+ function applyPopulationChange() {
+ const ruralChange = ruralPop.value / rural;
+ if (isFinite(ruralChange) && ruralChange !== 1) {
+ const cells = pack.cells.i.filter(i => pack.cells.religion[i] === religionId);
+ cells.forEach(i => (pack.cells.pop[i] *= ruralChange));
+ }
+ if (!isFinite(ruralChange) && +ruralPop.value > 0) {
+ const points = ruralPop.value / populationRate;
+ const cells = pack.cells.i.filter(i => pack.cells.religion[i] === religionId);
+ const pop = rn(points / cells.length);
+ cells.forEach(i => (pack.cells.pop[i] = pop));
+ }
+
+ const urbanChange = urbanPop.value / urban;
+ if (isFinite(urbanChange) && urbanChange !== 1) {
+ burgs.forEach(b => (b.population = rn(b.population * urbanChange, 4)));
+ }
+ if (!isFinite(urbanChange) && +urbanPop.value > 0) {
+ const points = urbanPop.value / populationRate / urbanization;
+ const population = rn(points / burgs.length, 4);
+ burgs.forEach(b => (b.population = population));
+ }
+
+ refreshReligionsEditor();
+ }
+}
+
+function religionRemovePrompt() {
+ if (customization) return;
+
+ const religionId = +this.parentNode.dataset.id;
+ confirmationDialog({
+ title: "Remove religion",
+ message: "Are you sure you want to remove the religion?
This action cannot be reverted",
+ confirm: "Remove",
+ onConfirm: () => removeReligion(religionId)
+ });
+}
+
+function removeReligion(religionId) {
+ relig.select("#religion" + religionId).remove();
+ relig.select("#religion-gap" + religionId).remove();
+ debug.select("#religionsCenter" + religionId).remove();
+
+ pack.cells.religion.forEach((r, i) => {
+ if (r === religionId) pack.cells.religion[i] = 0;
+ });
+ pack.religions[religionId].removed = true;
+
+ pack.religions
+ .filter(r => r.i && !r.removed)
+ .forEach(r => {
+ r.origins = r.origins.filter(origin => origin !== religionId);
+ if (!r.origins.length) r.origins = [0];
+ });
+
+ refreshReligionsEditor();
+}
+
+function drawReligionCenters() {
+ debug.select("#religionCenters").remove();
+ const religionCenters = debug
+ .append("g")
+ .attr("id", "religionCenters")
+ .attr("stroke-width", 1.2)
+ .attr("stroke", "#444444")
+ .style("cursor", "move");
+
+ const data = pack.religions.filter(r => r.i && r.center && r.cells && !r.removed);
+ religionCenters
+ .selectAll("circle")
+ .data(data)
+ .enter()
+ .append("circle")
+ .attr("id", d => "religionsCenter" + d.i)
+ .attr("data-id", d => d.i)
+ .attr("r", 4)
+ .attr("fill", d => d.color)
+ .attr("cx", d => pack.cells.p[d.center][0])
+ .attr("cy", d => pack.cells.p[d.center][1])
+ .on("mouseenter", d => {
+ tip(d.name + ". Drag to move the religion center", true);
+ religionHighlightOn(event);
+ })
+ .on("mouseleave", d => {
+ tip("", true);
+ religionHighlightOff(event);
+ })
+ .call(d3.drag().on("start", religionCenterDrag));
+}
+
+function religionCenterDrag() {
+ const $el = d3.select(this);
+ const religionId = +this.dataset.id;
+ d3.event.on("drag", () => {
+ const {x, y} = d3.event;
+ $el.attr("cx", x).attr("cy", y);
+ const cell = findCell(x, y);
+ if (pack.cells.h[cell] < 20) return; // ignore dragging on water
+ pack.religions[religionId].center = cell;
+ });
+}
+
+function toggleLegend() {
+ if (legend.selectAll("*").size()) return clearLegend(); // hide legend
+
+ const data = pack.religions
+ .filter(r => r.i && !r.removed && r.area)
+ .sort((a, b) => b.area - a.area)
+ .map(r => [r.i, r.color, r.name]);
+ drawLegend("Religions", data);
+}
+
+function togglePercentageMode() {
+ if ($body.dataset.type === "absolute") {
+ $body.dataset.type = "percentage";
+ const totalArea = +byId("religionsFooterArea").dataset.area;
+ const totalPopulation = +byId("religionsFooterPopulation").dataset.population;
+
+ $body.querySelectorAll(":scope > div").forEach($el => {
+ const {area, population} = $el.dataset;
+ $el.querySelector(".religionArea").innerText = rn((+area / totalArea) * 100) + "%";
+ $el.querySelector(".religionPopulation").innerText = rn((+population / totalPopulation) * 100) + "%";
+ });
+ } else {
+ $body.dataset.type = "absolute";
+ religionsEditorAddLines();
+ }
+}
+
+function showHierarchy() {
+ // build hierarchy tree
+ pack.religions[0].origins = [null];
+ const validReligions = pack.religions.filter(r => !r.removed);
+ if (validReligions.length < 3) return tip("Not enough religions to show hierarchy", false, "error");
+
+ const root = d3
+ .stratify()
+ .id(d => d.i)
+ .parentId(d => d.origins[0])(validReligions);
+ const treeWidth = root.leaves().length;
+ const treeHeight = root.height;
+ const width = Math.max(treeWidth * 40, 300);
+ const height = treeHeight * 60;
+
+ const margin = {top: 10, right: 10, bottom: -5, left: 10};
+ const w = width - margin.left - margin.right;
+ const h = height + 30 - margin.top - margin.bottom;
+ const treeLayout = d3.tree().size([w, h]);
+
+ alertMessage.innerHTML = /* html */ `
+
+
+ .
+ Abbreviation:
+ Clear
+ Close
+
+
`;
+
+ // prepare svg
+ const svg = d3
+ .select("#alertMessage")
+ .insert("svg", "#religionChartDetails")
+ .attr("id", "hierarchy")
+ .attr("width", width)
+ .attr("height", height)
+ .style("text-anchor", "middle");
+ const graph = svg.append("g").attr("transform", `translate(10, -45)`);
+ const links = graph.append("g").attr("fill", "none").attr("stroke", "#aaaaaa");
+ const primaryLinks = links.append("g");
+ const secondaryLinks = links.append("g").attr("stroke-dasharray", 1);
+ const nodes = graph.append("g");
+
+ // render helper functions
+ const getLinkPath = d => {
+ const {
+ source: {x: sx, y: sy},
+ target: {x: tx, y: ty}
+ } = d;
+ return `M${sx},${sy} C${sx},${(sy * 3 + ty) / 4} ${tx},${(sy * 2 + ty) / 3} ${tx},${ty}`;
+ };
+
+ const getSecondaryLinks = root => {
+ const nodes = root.descendants();
+ const links = [];
+
+ for (const node of nodes) {
+ const origins = node.data.origins;
+ if (node.depth < 2) continue;
+
+ for (let i = 1; i < origins.length; i++) {
+ const source = nodes.find(n => n.data.i === origins[i]);
+ if (source) links.push({source, target: node});
+ }
+ }
+
+ return links;
+ };
+
+ const nodePathMap = {
+ undefined: "M5,0A5,5,0,1,1,-5,0A5,5,0,1,1,5,0", // small circle
+ Folk: "M11.3,0A11.3,11.3,0,1,1,-11.3,0A11.3,11.3,0,1,1,11.3,0", // circle
+ Organized: "M-11,-11h22v22h-22Z", // square
+ Cult: "M-6.5,-11.26l13,0l6.5,11.26l-6.5,11.26l-13,0l-6.5,-11.26Z", // hexagon
+ Heresy: "M0,-14L14,0L0,14L-14,0Z" // diamond
+ };
+
+ const getNodePath = d => nodePathMap[d.data.type];
+
+ renderTree();
+ function renderTree() {
+ treeLayout(root);
+
+ primaryLinks.selectAll("path").data(root.links()).enter().append("path").attr("d", getLinkPath);
+ secondaryLinks.selectAll("path").data(getSecondaryLinks(root)).enter().append("path").attr("d", getLinkPath);
+
+ const node = nodes
+ .selectAll("g")
+ .data(root.descendants())
+ .enter()
+ .append("g")
+ .attr("data-id", d => d.data.i)
+ .attr("stroke", "#333333")
+ .attr("transform", d => `translate(${d.x}, ${d.y})`)
+ .on("mouseenter", religionHighlightOn)
+ .on("mouseleave", religionHighlightOff)
+ .on("click", religionSelect)
+ .call(d3.drag().on("start", dragToReorigin));
+
+ node
+ .append("path")
+ .attr("d", getNodePath)
+ .attr("fill", d => d.data.color || "#ffffff")
+ .attr("stroke-dasharray", d => (d.data.cells ? "null" : "1"));
+
+ node
+ .append("text")
+ .attr("dy", ".35em")
+ .text(d => d.data.code || "");
+ }
+
+ $("#alert").dialog({
+ title: "Religions tree",
+ width: fitContent(),
+ resizable: false,
+ position: {my: "left center", at: "left+10 center", of: "svg"},
+ buttons: {},
+ close: () => {
+ alertMessage.innerHTML = "";
+ }
+ });
+
+ function religionSelect(d) {
+ d3.event.stopPropagation();
+
+ nodes.selectAll("g").style("outline", "none");
+ this.style.outline = "1px solid #c13119";
+ byId("religionSelected").style.display = "block";
+ byId("religionInfo").style.display = "none";
+
+ const religion = d.data;
+ byId("religionSelectedName").innerText = religion.name;
+ byId("religionSelectedCode").value = religion.code;
+
+ byId("religionSelectedCode").onchange = function () {
+ if (this.value.length > 3) return tip("Abbreviation must be 3 characters or less", false, "error", 3000);
+ if (!this.value.length) return tip("Abbreviation cannot be empty", false, "error", 3000);
+ nodes.select(`g[data-id="${d.id}"] > text`).text(this.value);
+ religion.code = this.value;
+ };
+
+ byId("religionSelectedClear").onclick = () => {
+ religion.origins = [0];
+ showHierarchy();
+ };
+
+ byId("religionSelectedClose").onclick = () => {
+ this.style.outline = "none";
+ byId("religionSelected").style.display = "none";
+ byId("religionInfo").style.display = "block";
+ };
+ }
+
+ function dragToReorigin(d) {
+ const originLine = graph.append("path").attr("class", "dragLine").attr("d", `M${d.x},${d.y}L${d.x},${d.y}`);
+
+ d3.event.on("drag", () => {
+ originLine.attr("d", `M${d.x},${d.y}L${d3.event.x},${d3.event.y}`);
+ });
+
+ d3.event.on("end", () => {
+ originLine.remove();
+ const selected = graph.select("g.selected");
+ if (!selected.size()) return;
+
+ const religionId = d.data.i;
+ const newOrigin = selected.datum().data.i;
+ if (religionId === newOrigin) return; // dragged to itself
+ if (d.data.origins.includes(newOrigin)) return; // already a child of the selected node
+ if (d.descendants().some(node => node.data.i === newOrigin)) return; // cannot be a child of its own child
+
+ const religion = pack.religions[religionId];
+ if (religion.origins[0] === 0) religion.origins = [];
+ religion.origins.push(newOrigin);
+
+ showHierarchy();
+ });
+ }
+}
+
+function toggleExtinct() {
+ $body.dataset.extinct = $body.dataset.extinct !== "show" ? "show" : "hide";
+ religionsEditorAddLines();
+}
+
+function enterReligionsManualAssignent() {
+ if (!layerIsOn("toggleReligions")) toggleReligions();
+ customization = 7;
+ relig.append("g").attr("id", "temp");
+ document.querySelectorAll("#religionsBottom > button").forEach(el => (el.style.display = "none"));
+ byId("religionsManuallyButtons").style.display = "inline-block";
+ debug.select("#religionCenters").style("display", "none");
+
+ religionsEditor.querySelectorAll(".hide").forEach(el => el.classList.add("hidden"));
+ religionsFooter.style.display = "none";
+ $body.querySelectorAll("div > input, select, span, svg").forEach(e => (e.style.pointerEvents = "none"));
+ $("#religionsEditor").dialog({position: {my: "right top", at: "right-10 top+10", of: "svg"}});
+
+ tip("Click on religion to select, drag the circle to change religion", true);
+ viewbox
+ .style("cursor", "crosshair")
+ .on("click", selectReligionOnMapClick)
+ .call(d3.drag().on("start", dragReligionBrush))
+ .on("touchmove mousemove", moveReligionBrush);
+
+ $body.querySelector("div").classList.add("selected");
+}
+
+function selectReligionOnLineClick(i) {
+ if (customization !== 7) return;
+ $body.querySelector("div.selected").classList.remove("selected");
+ this.classList.add("selected");
+}
+
+function selectReligionOnMapClick() {
+ const point = d3.mouse(this);
+ const i = findCell(point[0], point[1]);
+ if (pack.cells.h[i] < 20) return;
+
+ const assigned = relig.select("#temp").select("polygon[data-cell='" + i + "']");
+ const religion = assigned.size() ? +assigned.attr("data-religion") : pack.cells.religion[i];
+
+ $body.querySelector("div.selected").classList.remove("selected");
+ $body.querySelector("div[data-id='" + religion + "']").classList.add("selected");
+}
+
+function dragReligionBrush() {
+ const radius = +byId("religionsManuallyBrushNumber").value;
+
+ d3.event.on("drag", () => {
+ if (!d3.event.dx && !d3.event.dy) return;
+ const [x, y] = d3.mouse(this);
+ moveCircle(x, y, radius);
+
+ const found = radius > 5 ? findAll(x, y, radius) : [findCell(x, y, radius)];
+ const selection = found.filter(isLand);
+ if (selection) changeReligionForSelection(selection);
+ });
+}
+
+// change religion within selection
+function changeReligionForSelection(selection) {
+ const temp = relig.select("#temp");
+ const selected = $body.querySelector("div.selected");
+ const religionNew = +selected.dataset.id;
+ const color = pack.religions[religionNew].color || "#ffffff";
+
+ selection.forEach(function (i) {
+ const exists = temp.select("polygon[data-cell='" + i + "']");
+ const religionOld = exists.size() ? +exists.attr("data-religion") : pack.cells.religion[i];
+ if (religionNew === religionOld) return;
+
+ // change of append new element
+ if (exists.size()) exists.attr("data-religion", religionNew).attr("fill", color);
+ else
+ temp
+ .append("polygon")
+ .attr("data-cell", i)
+ .attr("data-religion", religionNew)
+ .attr("points", getPackPolygon(i))
+ .attr("fill", color);
+ });
+}
+
+function moveReligionBrush() {
+ showMainTip();
+ const [x, y] = d3.mouse(this);
+ const radius = +byId("religionsManuallyBrushNumber").value;
+ moveCircle(x, y, radius);
+}
+
+function applyReligionsManualAssignent() {
+ const changed = relig.select("#temp").selectAll("polygon");
+ changed.each(function () {
+ const i = +this.dataset.cell;
+ const r = +this.dataset.religion;
+ pack.cells.religion[i] = r;
+ });
+
+ if (changed.size()) {
+ drawReligions();
+ refreshReligionsEditor();
+ drawReligionCenters();
+ }
+ exitReligionsManualAssignment();
+}
+
+function exitReligionsManualAssignment(close) {
+ customization = 0;
+ relig.select("#temp").remove();
+ removeCircle();
+ document.querySelectorAll("#religionsBottom > button").forEach(el => (el.style.display = "inline-block"));
+ byId("religionsManuallyButtons").style.display = "none";
+
+ byId("religionsEditor")
+ .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"));
+ if (!close) $("#religionsEditor").dialog({position: {my: "right top", at: "right-10 top+10", of: "svg"}});
+
+ debug.select("#religionCenters").style("display", null);
+ restoreDefaultEvents();
+ clearMainTip();
+ const $selected = $body.querySelector("div.selected");
+ if ($selected) $selected.classList.remove("selected");
+}
+
+function enterAddReligionMode() {
+ if (this.classList.contains("pressed")) return exitAddReligionMode();
+
+ customization = 8;
+ this.classList.add("pressed");
+ tip("Click on the map to add a new religion", true);
+ viewbox.style("cursor", "crosshair").on("click", addReligion);
+ $body.querySelectorAll("div > input, select, span, svg").forEach(e => (e.style.pointerEvents = "none"));
+}
+
+function exitAddReligionMode() {
+ customization = 0;
+ restoreDefaultEvents();
+ clearMainTip();
+ $body.querySelectorAll("div > input, select, span, svg").forEach(e => (e.style.pointerEvents = "all"));
+ if (religionsAdd.classList.contains("pressed")) religionsAdd.classList.remove("pressed");
+}
+
+function addReligion() {
+ const [x, y] = d3.mouse(this);
+ const center = findCell(x, y);
+ if (pack.cells.h[center] < 20)
+ return tip("You cannot place religion center into the water. Please click on a land cell", false, "error");
+
+ const occupied = pack.religions.some(r => !r.removed && r.center === center);
+ if (occupied) return tip("This cell is already a religion center. Please select a different cell", false, "error");
+
+ if (d3.event.shiftKey === false) exitAddReligionMode();
+ Religions.add(center);
+
+ drawReligions();
+ refreshReligionsEditor();
+ drawReligionCenters();
+}
+
+function downloadReligionsCsv() {
+ const unit = getAreaUnit("2");
+ const headers = `Id,Name,Color,Type,Form,Supreme Deity,Area ${unit},Believers,Origins`;
+ const lines = Array.from($body.querySelectorAll(":scope > div"));
+ const data = lines.map($line => {
+ const {id, name, color, type, form, deity, area, population} = $line.dataset;
+ const deityText = '"' + deity + '"';
+ const {origins} = pack.religions[+id];
+ const originList = (origins || []).filter(origin => origin).map(origin => pack.religions[origin].name);
+ const originText = '"' + originList.join(", ") + '"';
+ return [id, name, color, type, form, deityText, area, population, originText].join(",");
+ });
+ const csvData = [headers].concat(data).join("\n");
+
+ const name = getFileName("Religions") + ".csv";
+ downloadFile(csvData, name);
+}
+
+function closeReligionsEditor() {
+ debug.select("#religionCenters").remove();
+ exitReligionsManualAssignment("close");
+ exitAddReligionMode();
+}
diff --git a/modules/dynamic/editors/states-editor.js b/modules/dynamic/editors/states-editor.js
index 44dc59fa..26a09d17 100644
--- a/modules/dynamic/editors/states-editor.js
+++ b/modules/dynamic/editors/states-editor.js
@@ -145,14 +145,14 @@ function addListeners() {
$body.on("click", event => {
const $element = event.target;
const classList = $element.classList;
- const state = +$element.parentNode?.dataset?.id;
+ const stateId = +$element.parentNode?.dataset?.id;
if ($element.tagName === "FILL-BOX") stateChangeFill($element);
- else if (classList.contains("name")) editStateName(state);
- else if (classList.contains("coaIcon")) editEmblem("state", "stateCOA" + state, pack.states[state]);
- else if (classList.contains("icon-star-empty")) stateCapitalZoomIn(state);
- else if (classList.contains("statePopulation")) changePopulation(state);
- else if (classList.contains("icon-pin")) toggleFog(state, classList);
- else if (classList.contains("icon-trash-empty")) stateRemovePrompt(state);
+ else if (classList.contains("name")) editStateName(stateId);
+ else if (classList.contains("coaIcon")) editEmblem("state", "stateCOA" + stateId, pack.states[stateId]);
+ else if (classList.contains("icon-star-empty")) stateCapitalZoomIn(stateId);
+ else if (classList.contains("statePopulation")) changePopulation(stateId);
+ else if (classList.contains("icon-pin")) toggleFog(stateId, classList);
+ else if (classList.contains("icon-trash-empty")) stateRemovePrompt(stateId);
});
$body.on("input", function (ev) {
@@ -194,7 +194,9 @@ function statesEditorAddLines() {
const rural = s.rural * populationRate;
const urban = s.urban * populationRate * urbanization;
const population = rn(rural + urban);
- const populationTip = `Total population: ${si(population)}; Rural population: ${si(rural)}; Urban population: ${si(urban)}. Click to change`;
+ const populationTip = `Total population: ${si(population)}; Rural population: ${si(rural)}; Urban population: ${si(
+ urban
+ )}. Click to change`;
totalArea += area;
totalPopulation += population;
totalBurgs += s.burgs;
@@ -218,7 +220,9 @@ function statesEditorAddLines() {
data-expansionism=""
>
-
+
@@ -258,18 +262,26 @@ function statesEditorAddLines() {
>
-
-
+
+
-
${getCultureOptions(s.culture)}
+
${getCultureOptions(
+ s.culture
+ )}
${s.burgs}
${si(area)} ${unit}
${si(population)}
-
${getTypeOptions(s.type)}
+
${getTypeOptions(
+ s.type
+ )}
@@ -488,25 +500,30 @@ function stateChangeCapitalName(state, line, value) {
document.querySelector("#burgLabel" + capital).textContent = value;
}
-function changePopulation(state) {
- const s = pack.states[state];
- if (!s.cells) {
- tip("State does not have any cells, cannot change population", false, "error");
- return;
- }
- const rural = rn(s.rural * populationRate);
- const urban = rn(s.urban * populationRate * urbanization);
- const total = rural + urban;
- const l = n => Number(n).toLocaleString();
+function changePopulation(stateId) {
+ const state = pack.states[stateId];
+ if (!state.cells) return tip("State does not have any cells, cannot change population", false, "error");
- alertMessage.innerHTML = /* html */ ` Rural:
Urban:
-
-
Total population: ${l(total)} ⇒ ${l(total)} (100 %)
`;
+ const rural = rn(state.rural * populationRate);
+ const urban = rn(state.urban * populationRate * urbanization);
+ const total = rural + urban;
+ const format = n => Number(n).toLocaleString();
+
+ alertMessage.innerHTML = /* html */ `
+
Change population of all cells assigned to the state
+
+ Rural:
+ Urban:
+
+
Total population: ${format(total)} ⇒ ${format(total)}
+ (100 %)
+
+
`;
const update = function () {
const totalNew = ruralPop.valueAsNumber + urbanPop.valueAsNumber;
if (isNaN(totalNew)) return;
- totalPop.innerHTML = l(totalNew);
+ totalPop.innerHTML = format(totalNew);
totalPopPerc.innerHTML = rn((totalNew / total) * 100);
};
@@ -532,24 +549,24 @@ function changePopulation(state) {
function applyPopulationChange() {
const ruralChange = ruralPop.value / rural;
if (isFinite(ruralChange) && ruralChange !== 1) {
- const cells = pack.cells.i.filter(i => pack.cells.state[i] === state);
+ const cells = pack.cells.i.filter(i => pack.cells.state[i] === stateId);
cells.forEach(i => (pack.cells.pop[i] *= ruralChange));
}
if (!isFinite(ruralChange) && +ruralPop.value > 0) {
const points = ruralPop.value / populationRate;
- const cells = pack.cells.i.filter(i => pack.cells.state[i] === state);
+ const cells = pack.cells.i.filter(i => pack.cells.state[i] === stateId);
const pop = points / cells.length;
cells.forEach(i => (pack.cells.pop[i] = pop));
}
const urbanChange = urbanPop.value / urban;
if (isFinite(urbanChange) && urbanChange !== 1) {
- const burgs = pack.burgs.filter(b => !b.removed && b.state === state);
+ const burgs = pack.burgs.filter(b => !b.removed && b.state === stateId);
burgs.forEach(b => (b.population = rn(b.population * urbanChange, 4)));
}
if (!isFinite(urbanChange) && +urbanPop.value > 0) {
const points = urbanPop.value / populationRate / urbanization;
- const burgs = pack.burgs.filter(b => !b.removed && b.state === state);
+ const burgs = pack.burgs.filter(b => !b.removed && b.state === stateId);
const population = rn(points / burgs.length, 4);
burgs.forEach(b => (b.population = population));
}
@@ -591,19 +608,11 @@ function toggleFog(state, cl) {
function stateRemovePrompt(state) {
if (customization) return;
- alertMessage.innerHTML = "Are you sure you want to remove the state?
This action cannot be reverted";
- $("#alert").dialog({
- resizable: false,
+ confirmationDialog({
title: "Remove state",
- buttons: {
- Remove: function () {
- $(this).dialog("close");
- stateRemove(state);
- },
- Cancel: function () {
- $(this).dialog("close");
- }
- }
+ message: "Are you sure you want to remove the state?
This action cannot be reverted",
+ confirm: "Remove",
+ onConfirm: () => stateRemove(state)
});
}
@@ -667,10 +676,8 @@ function stateRemove(state) {
}
function toggleLegend() {
- if (legend.selectAll("*").size()) {
- clearLegend();
- return;
- } // hide legend
+ if (legend.selectAll("*").size()) return clearLegend(); // hide legend
+
const data = pack.states
.filter(s => s.i && !s.removed && s.cells)
.sort((a, b) => b.area - a.area)
@@ -681,16 +688,17 @@ function toggleLegend() {
function togglePercentageMode() {
if ($body.dataset.type === "absolute") {
$body.dataset.type = "percentage";
- const totalCells = +statesFooterCells.innerHTML;
- const totalBurgs = +statesFooterBurgs.innerHTML;
- const totalArea = +statesFooterArea.dataset.area;
- const totalPopulation = +statesFooterPopulation.dataset.population;
+ const totalCells = +byId("statesFooterCells").innerText;
+ const totalBurgs = +byId("statesFooterBurgs").innerText;
+ const totalArea = +byId("statesFooterArea").dataset.area;
+ const totalPopulation = +byId("statesFooterPopulation").dataset.population;
$body.querySelectorAll(":scope > div").forEach(function (el) {
- el.querySelector(".stateCells").innerHTML = rn((+el.dataset.cells / totalCells) * 100) + "%";
- el.querySelector(".stateBurgs").innerHTML = rn((+el.dataset.burgs / totalBurgs) * 100) + "%";
- el.querySelector(".stateArea").innerHTML = rn((+el.dataset.area / totalArea) * 100) + "%";
- el.querySelector(".statePopulation").innerHTML = rn((+el.dataset.population / totalPopulation) * 100) + "%";
+ const {cells, burgs, area, population} = el.dataset;
+ el.querySelector(".stateCells").innerText = rn((+cells / totalCells) * 100) + "%";
+ el.querySelector(".stateBurgs").innerText = rn((+burgs / totalBurgs) * 100) + "%";
+ el.querySelector(".stateArea").innerText = rn((+area / totalArea) * 100) + "%";
+ el.querySelector(".statePopulation").innerText = rn((+population / totalPopulation) * 100) + "%";
});
} else {
$body.dataset.type = "absolute";
@@ -913,7 +921,11 @@ function enterStatesManualAssignent() {
$("#statesEditor").dialog({position: {my: "right top", at: "right-10 top+10", of: "svg", collision: "fit"}});
tip("Click on state to select, drag the circle to change state", true);
- viewbox.style("cursor", "crosshair").on("click", selectStateOnMapClick).call(d3.drag().on("start", dragStateBrush)).on("touchmove mousemove", moveStateBrush);
+ viewbox
+ .style("cursor", "crosshair")
+ .on("click", selectStateOnMapClick)
+ .call(d3.drag().on("start", dragStateBrush))
+ .on("touchmove mousemove", moveStateBrush);
$body.querySelector("div").classList.add("selected");
}
@@ -967,7 +979,14 @@ function changeStateForSelection(selection) {
// change of append new element
if (exists.size()) exists.attr("data-state", stateNew).attr("fill", color).attr("stroke", color);
- else temp.append("polygon").attr("data-cell", i).attr("data-state", stateNew).attr("points", getPackPolygon(i)).attr("fill", color).attr("stroke", color);
+ else
+ temp
+ .append("polygon")
+ .attr("data-cell", i)
+ .attr("data-state", stateNew)
+ .attr("points", getPackPolygon(i))
+ .attr("fill", color)
+ .attr("stroke", color);
});
}
@@ -1118,7 +1137,17 @@ function adjustProvinces(affectedProvinces) {
const coa = COA.generate(burg?.coa || states[stateId].coa, kinship, burg ? null : 0.9, type);
coa.shield = COA.getShield(culture, stateId);
- provinces.push({i: newProvinceId, state: stateId, center, burg: burgId, name, formName, fullName: `${name} ${formName}`, color, coa});
+ provinces.push({
+ i: newProvinceId,
+ state: stateId,
+ center,
+ burg: burgId,
+ name,
+ formName,
+ fullName: `${name} ${formName}`,
+ color,
+ coa
+ });
provinceCells.forEach(i => {
cells.province[i] = newProvinceId;
@@ -1134,7 +1163,9 @@ function adjustProvinces(affectedProvinces) {
})
);
- const closesProvince = borderCell && cells.c[borderCell].map(c => cells.province[c]).find(province => province && province !== provinceId);
+ const closesProvince =
+ borderCell &&
+ cells.c[borderCell].map(c => cells.province[c]).find(province => province && province !== provinceId);
return closesProvince;
}
}
@@ -1152,7 +1183,8 @@ function exitStatesManualAssignment(close) {
.forEach(el => el.classList.remove("hidden"));
statesFooter.style.display = "block";
$body.querySelectorAll("div > input, select, span, svg").forEach(e => (e.style.pointerEvents = "all"));
- if (!close) $("#statesEditor").dialog({position: {my: "right top", at: "right-10 top+10", of: "svg", collision: "fit"}});
+ if (!close)
+ $("#statesEditor").dialog({position: {my: "right top", at: "right-10 top+10", of: "svg", collision: "fit"}});
restoreDefaultEvents();
clearMainTip();
@@ -1176,10 +1208,12 @@ function addState() {
const {cells, states, burgs} = pack;
const point = d3.mouse(this);
const center = findCell(point[0], point[1]);
- if (cells.h[center] < 20) return tip("You cannot place state into the water. Please click on a land cell", false, "error");
+ if (cells.h[center] < 20)
+ return tip("You cannot place state into the water. Please click on a land cell", false, "error");
let burg = cells.burg[center];
- if (burg && burgs[burg].capital) return tip("Existing capital cannot be selected as a new state capital! Select other cell", false, "error");
+ if (burg && burgs[burg].capital)
+ return tip("Existing capital cannot be selected as a new state capital! Select other cell", false, "error");
if (!burg) burg = addBurg(point); // add new burg
@@ -1226,7 +1260,10 @@ function addState() {
return relations;
});
diplomacy.push("x");
- states[0].diplomacy.push([`Independance declaration`, `${name} declared its independance from ${states[oldState].name}`]);
+ states[0].diplomacy.push([
+ `Independance declaration`,
+ `${name} declared its independance from ${states[oldState].name}`
+ ]);
cells.state[center] = newState;
cells.province[center] = 0;
@@ -1296,7 +1333,23 @@ function downloadStatesCsv() {
const {fullName = "", rural, urban} = pack.states[+id];
const ruralPopulation = Math.round(rural * populationRate);
const urbanPopulation = Math.round(urban * populationRate * urbanization);
- return [id, name, fullName, form, color, capital, culture, type, expansionism, cells, burgs, area, population, ruralPopulation, urbanPopulation].join(",");
+ return [
+ id,
+ name,
+ fullName,
+ form,
+ color,
+ capital,
+ culture,
+ type,
+ expansionism,
+ cells,
+ burgs,
+ area,
+ population,
+ ruralPopulation,
+ urbanPopulation
+ ].join(",");
});
const csvData = [headers].concat(data).join("\n");
diff --git a/modules/io/load.js b/modules/io/load.js
index 0e3e85de..93f88b6c 100644
--- a/modules/io/load.js
+++ b/modules/io/load.js
@@ -244,7 +244,10 @@ async function parseLoadedData(data) {
const usedFonts = JSON.parse(data[34]);
usedFonts.forEach(usedFont => {
const {family: usedFamily, unicodeRange: usedRange, variant: usedVariant} = usedFont;
- const defaultFont = fonts.find(({family, unicodeRange, variant}) => family === usedFamily && unicodeRange === usedRange && variant === usedVariant);
+ const defaultFont = fonts.find(
+ ({family, unicodeRange, variant}) =>
+ family === usedFamily && unicodeRange === usedRange && variant === usedVariant
+ );
if (!defaultFont) fonts.push(usedFont);
declareFont(usedFont);
});
@@ -421,13 +424,15 @@ async function parseLoadedData(data) {
void (function restoreEvents() {
scaleBar.on("mousemove", () => tip("Click to open Units Editor")).on("click", () => editUnits());
- legend.on("mousemove", () => tip("Drag to change the position. Click to hide the legend")).on("click", () => clearLegend());
+ legend
+ .on("mousemove", () => tip("Drag to change the position. Click to hide the legend"))
+ .on("click", () => clearLegend());
})();
{
// dynamically import and run auto-udpdate script
const versionNumber = parseFloat(params[0]);
- const {resolveVersionConflicts} = await import("../dynamic/auto-update.js?v=01062022");
+ const {resolveVersionConflicts} = await import("../dynamic/auto-update.js?v=06062022");
resolveVersionConflicts(versionNumber);
}
@@ -435,7 +440,10 @@ async function parseLoadedData(data) {
const cells = pack.cells;
if (pack.cells.i.length !== pack.cells.state.length) {
- ERROR && console.error("Striping issue. Map data is corrupted. The only solution is to edit the heightmap in erase mode");
+ ERROR &&
+ console.error(
+ "Striping issue. Map data is corrupted. The only solution is to edit the heightmap in erase mode"
+ );
}
const invalidStates = [...new Set(cells.state)].filter(s => !pack.states[s] || pack.states[s].removed);
@@ -445,7 +453,9 @@ async function parseLoadedData(data) {
ERROR && console.error("Data Integrity Check. Invalid state", s, "is assigned to cells", invalidCells);
});
- const invalidProvinces = [...new Set(cells.province)].filter(p => p && (!pack.provinces[p] || pack.provinces[p].removed));
+ const invalidProvinces = [...new Set(cells.province)].filter(
+ p => p && (!pack.provinces[p] || pack.provinces[p].removed)
+ );
invalidProvinces.forEach(p => {
const invalidCells = cells.i.filter(i => cells.province[i] === p);
invalidCells.forEach(i => (cells.province[i] = 0));
@@ -459,7 +469,9 @@ async function parseLoadedData(data) {
ERROR && console.error("Data Integrity Check. Invalid culture", c, "is assigned to cells", invalidCells);
});
- const invalidReligions = [...new Set(cells.religion)].filter(r => !pack.religions[r] || pack.religions[r].removed);
+ const invalidReligions = [...new Set(cells.religion)].filter(
+ r => !pack.religions[r] || pack.religions[r].removed
+ );
invalidReligions.forEach(r => {
const invalidCells = cells.i.filter(i => cells.religion[i] === r);
invalidCells.forEach(i => (cells.religion[i] = 0));
diff --git a/modules/religions-generator.js b/modules/religions-generator.js
index abe168ef..bc820384 100644
--- a/modules/religions-generator.js
+++ b/modules/religions-generator.js
@@ -277,7 +277,24 @@ window.Religions = (function () {
"Word",
"World"
],
- color: ["Amber", "Black", "Blue", "Bright", "Brown", "Dark", "Golden", "Green", "Grey", "Light", "Orange", "Pink", "Purple", "Red", "White", "Yellow"]
+ color: [
+ "Amber",
+ "Black",
+ "Blue",
+ "Bright",
+ "Brown",
+ "Dark",
+ "Golden",
+ "Green",
+ "Grey",
+ "Light",
+ "Orange",
+ "Pink",
+ "Purple",
+ "Red",
+ "White",
+ "Yellow"
+ ]
};
const forms = {
@@ -311,7 +328,18 @@ window.Religions = (function () {
Cult: {Cult: 4, Sect: 4, Arcanum: 1, Coterie: 1, Order: 1, Worship: 1},
"Dark Cult": {Cult: 2, Sect: 2, Blasphemy: 1, Circle: 1, Coven: 1, Idols: 1, Occultism: 1},
- Heresy: {Heresy: 3, Sect: 2, Apostates: 1, Brotherhood: 1, Circle: 1, Dissent: 1, Dissenters: 1, Iconoclasm: 1, Schism: 1, Society: 1}
+ Heresy: {
+ Heresy: 3,
+ Sect: 2,
+ Apostates: 1,
+ Brotherhood: 1,
+ Circle: 1,
+ Dissent: 1,
+ Dissenters: 1,
+ Iconoclasm: 1,
+ Schism: 1,
+ Society: 1
+ }
};
const generate = function () {
@@ -324,25 +352,27 @@ window.Religions = (function () {
// add folk religions
pack.cultures.forEach(c => {
- if (!c.i) {
- religions.push({i: 0, name: "No religion"});
- return;
- }
+ if (!c.i) return religions.push({i: 0, name: "No religion"});
+
if (c.removed) {
- religions.push({i: c.i, name: "Extinct religion for " + c.name, color: getMixedColor(c.color, 0.1, 0), removed: true});
+ religions.push({
+ i: c.i,
+ name: "Extinct religion for " + c.name,
+ color: getMixedColor(c.color, 0.1, 0),
+ removed: true
+ });
return;
}
+
const form = rw(forms.Folk);
const name = c.name + " " + rw(types[form]);
const deity = form === "Animism" ? null : getDeityName(c.i);
const color = getMixedColor(c.color, 0.1, 0); // `url(#hatch${rand(8,13)})`;
- religions.push({i: c.i, name, color, culture: c.i, type: "Folk", form, deity, center: c.center, origin: 0});
+ religions.push({i: c.i, name, color, culture: c.i, type: "Folk", form, deity, center: c.center, origins: [0]});
});
- if (religionsInput.value == 0 || pack.cultures.length < 2) {
- religions.filter(r => r.i).forEach(r => (r.code = abbreviate(r.name)));
- return;
- }
+ if (religionsInput.value == 0 || pack.cultures.length < 2)
+ return religions.filter(r => r.i).forEach(r => (r.code = abbreviate(r.name)));
const burgs = pack.burgs.filter(b => b.i && !b.removed);
const sorted =
@@ -354,6 +384,12 @@ window.Religions = (function () {
const cultsCount = Math.floor((rand(10, 40) / 100) * religionsInput.value);
const count = +religionsInput.value - cultsCount + religions.length;
+ function getReligionsInRadius({x, y, r, max}) {
+ const cellsInRadius = findAll(x, y, r);
+ const religions = unique(cellsInRadius.map(i => cells.religion[i]).filter(r => r));
+ return religions.length ? religions.slice(0, max) : [0];
+ }
+
// generate organized religions
for (let i = 0; religions.length < count && i < 1000; i++) {
let center = sorted[biased(0, sorted.length - 1, 5)]; // religion center
@@ -369,21 +405,35 @@ window.Religions = (function () {
if (expansion === "state" && Math.random() > 0.5) center = states[state].center;
if (expansion === "culture" && Math.random() > 0.5) center = cultures[culture].center;
- if (!cells.burg[center] && cells.c[center].some(c => cells.burg[c])) center = cells.c[center].find(c => cells.burg[c]);
- const x = cells.p[center][0],
- y = cells.p[center][1];
+ if (!cells.burg[center] && cells.c[center].some(c => cells.burg[c]))
+ center = cells.c[center].find(c => cells.burg[c]);
+ const [x, y] = cells.p[center];
const s = spacing * gauss(1, 0.3, 0.2, 2, 2); // randomize to make the placement not uniform
if (religionsTree.find(x, y, s) !== undefined) continue; // to close to existing religion
// add "Old" to name of the folk religion on this culture
- const folk = religions.find(r => r.culture === culture && r.type === "Folk");
+ const isFolkBased = expansion === "culture" || P(0.5);
+ const folk = isFolkBased && religions.find(r => r.culture === culture && r.type === "Folk");
if (folk && expansion === "culture" && folk.name.slice(0, 3) !== "Old") folk.name = "Old " + folk.name;
- const origin = folk ? folk.i : 0;
+ const origins = folk ? [folk.i] : getReligionsInRadius({x, y, r: 30, max: 2});
const expansionism = rand(3, 8);
- const color = getMixedColor(religions[origin].color, 0.3, 0); // `url(#hatch${rand(0,5)})`;
- religions.push({i: religions.length, name, color, culture, type: "Organized", form, deity, expansion, expansionism, center, origin});
+ const baseColor = religions[culture]?.color || states[state]?.color || getRandomColor();
+ const color = getMixedColor(baseColor, 0.3, 0);
+ religions.push({
+ i: religions.length,
+ name,
+ color,
+ culture,
+ type: "Organized",
+ form,
+ deity,
+ expansion,
+ expansionism,
+ center,
+ origins
+ });
religionsTree.add([x, y]);
}
@@ -391,23 +441,34 @@ window.Religions = (function () {
for (let i = 0; religions.length < count + cultsCount && i < 1000; i++) {
const form = rw(forms.Cult);
let center = sorted[biased(0, sorted.length - 1, 1)]; // religion center
- if (!cells.burg[center] && cells.c[center].some(c => cells.burg[c])) center = cells.c[center].find(c => cells.burg[c]);
- const x = cells.p[center][0],
- y = cells.p[center][1];
+ if (!cells.burg[center] && cells.c[center].some(c => cells.burg[c]))
+ center = cells.c[center].find(c => cells.burg[c]);
+ const [x, y] = cells.p[center];
const s = spacing * gauss(2, 0.3, 1, 3, 2); // randomize to make the placement not uniform
if (religionsTree.find(x, y, s) !== undefined) continue; // to close to existing religion
const culture = cells.culture[center];
- const folk = religions.find(r => r.culture === culture && r.type === "Folk");
- const origin = folk ? folk.i : 0;
+ const origins = getReligionsInRadius({x, y, r: 75, max: rand(0, 4)});
+
const deity = getDeityName(culture);
const name = getCultName(form, center);
const expansionism = gauss(1.1, 0.5, 0, 5);
const color = getMixedColor(cultures[culture].color, 0.5, 0); // "url(#hatch7)";
- religions.push({i: religions.length, name, color, culture, type: "Cult", form, deity, expansion: "global", expansionism, center, origin});
+ religions.push({
+ i: religions.length,
+ name,
+ color,
+ culture,
+ type: "Cult",
+ form,
+ deity,
+ expansion: "global",
+ expansionism,
+ center,
+ origins
+ });
religionsTree.add([x, y]);
- //debug.append("circle").attr("cx", x).attr("cy", y).attr("r", 2).attr("fill", "red");
}
expandReligions();
@@ -419,11 +480,13 @@ window.Religions = (function () {
if (r.expansionism < 3) return;
const count = gauss(0, 1, 0, 3);
for (let i = 0; i < count; i++) {
- let center = ra(cells.i.filter(i => cells.religion[i] === r.i && cells.c[i].some(c => cells.religion[c] !== r.i)));
+ let center = ra(
+ cells.i.filter(i => cells.religion[i] === r.i && cells.c[i].some(c => cells.religion[c] !== r.i))
+ );
if (!center) continue;
- if (!cells.burg[center] && cells.c[center].some(c => cells.burg[c])) center = cells.c[center].find(c => cells.burg[c]);
- const x = cells.p[center][0],
- y = cells.p[center][1];
+ if (!cells.burg[center] && cells.c[center].some(c => cells.burg[c]))
+ center = cells.c[center].find(c => cells.burg[c]);
+ const [x, y] = cells.p[center];
if (religionsTree.find(x, y, spacing / 10) !== undefined) continue; // to close to other
const culture = cells.culture[center];
@@ -441,7 +504,7 @@ window.Religions = (function () {
expansion: "global",
expansionism,
center,
- origin: r.i
+ origins: [r.i]
});
religionsTree.add([x, y]);
}
@@ -461,7 +524,8 @@ window.Religions = (function () {
const culture = cells.culture[center];
const color = getMixedColor(religions[r].color, 0.3, 0);
- const type = religions[r].type === "Organized" ? rw({Organized: 4, Cult: 1, Heresy: 2}) : rw({Organized: 5, Cult: 2});
+ const type =
+ religions[r].type === "Organized" ? rw({Organized: 4, Cult: 1, Heresy: 2}) : rw({Organized: 5, Cult: 2});
const form = rw(forms[type]);
const deity = type === "Heresy" ? religions[r].deity : form === "Non-theism" ? null : getDeityName(culture);
@@ -491,7 +555,7 @@ window.Religions = (function () {
area: 0,
rural: 0,
urban: 0,
- origin: r,
+ origins: [r],
code
});
cells.religion[center] = i;
@@ -534,7 +598,9 @@ window.Religions = (function () {
const populationCost = Math.max(rn(popCost - cells.pop[e]), 0);
const heightCost = Math.max(cells.h[e], 20) - 20;
const waterCost = cells.h[e] < 20 ? (cells.road[e] ? 50 : 1000) : 0;
- const totalCost = p + (cultureCost + stateCost + biomeCost + populationCost + heightCost + waterCost) / religions[r].expansionism;
+ const totalCost =
+ p +
+ (cultureCost + stateCost + biomeCost + populationCost + heightCost + waterCost) / religions[r].expansionism;
if (totalCost > neutral) return;
if (!cost[e] || totalCost < cost[e]) {
@@ -576,7 +642,8 @@ window.Religions = (function () {
const biomeCost = cells.road[e] ? 0 : biomesData.cost[cells.biome[e]];
const heightCost = Math.max(cells.h[e], 20) - 20;
const waterCost = cells.h[e] < 20 ? (cells.road[e] ? 50 : 1000) : 0;
- const totalCost = p + (religionCost + biomeCost + heightCost + waterCost) / Math.max(religions[r].expansionism, 0.1);
+ const totalCost =
+ p + (religionCost + biomeCost + heightCost + waterCost) / Math.max(religions[r].expansionism, 0.1);
if (totalCost > neutral) return;
@@ -641,35 +708,34 @@ window.Religions = (function () {
if (a === "Being + of + Genitive") return ra(base.being) + " of " + ra(base.genitive);
if (a === "Being + of the + Genitive") return ra(base.being) + " of the " + ra(base.theGenitive);
if (a === "Animal + of + Genitive") return ra(base.animal) + " of " + ra(base.genitive);
- if (a === "Adjective + Being + of + Genitive") return ra(base.adjective) + " " + ra(base.being) + " of " + ra(base.genitive);
- if (a === "Adjective + Animal + of + Genitive") return ra(base.adjective) + " " + ra(base.animal) + " of " + ra(base.genitive);
+ if (a === "Adjective + Being + of + Genitive")
+ return ra(base.adjective) + " " + ra(base.being) + " of " + ra(base.genitive);
+ if (a === "Adjective + Animal + of + Genitive")
+ return ra(base.adjective) + " " + ra(base.animal) + " of " + ra(base.genitive);
}
function getReligionName(form, deity, center) {
- const cells = pack.cells;
- const random = function () {
- return Names.getCulture(cells.culture[center], null, null, "", 0);
- };
- const type = function () {
- return rw(types[form]);
- };
- const supreme = function () {
- return deity.split(/[ ,]+/)[0];
- };
- const place = function (adj) {
- const base = cells.burg[center] ? pack.burgs[cells.burg[center]].name : pack.states[cells.state[center]].name;
+ const {cells, cultures, burgs, states} = pack;
+
+ const random = () => Names.getCulture(cells.culture[center], null, null, "", 0);
+ const type = () => rw(types[form]);
+ const supreme = () => deity.split(/[ ,]+/)[0];
+ const culture = () => cultures[cells.culture[center]].name;
+ const place = adj => {
+ const burgId = cells.burg[center];
+ const stateId = cells.state[center];
+
+ const base = burgId ? burgs[burgId].name : states[stateId].name;
let name = trimVowels(base.split(/[ ,]+/)[0]);
return adj ? getAdjective(name) : name;
};
- const culture = function () {
- return pack.cultures[cells.culture[center]].name;
- };
const m = rw(methods);
if (m === "Random + type") return [random() + " " + type(), "global"];
if (m === "Random + ism") return [trimVowels(random()) + "ism", "global"];
if (m === "Supreme + ism" && deity) return [trimVowels(supreme()) + "ism", "global"];
- if (m === "Faith of + Supreme" && deity) return [ra(["Faith", "Way", "Path", "Word", "Witnesses"]) + " of " + supreme(), "global"];
+ if (m === "Faith of + Supreme" && deity)
+ return [ra(["Faith", "Way", "Path", "Word", "Witnesses"]) + " of " + supreme(), "global"];
if (m === "Place + ism") return [place() + "ism", "state"];
if (m === "Culture + ism") return [trimVowels(culture()) + "ism", "culture"];
if (m === "Place + ian + type") return [place("adj") + " " + type(), "state"];
diff --git a/modules/ui/editors.js b/modules/ui/editors.js
index c744ce89..456bb781 100644
--- a/modules/ui/editors.js
+++ b/modules/ui/editors.js
@@ -330,7 +330,23 @@ function getMFCGlink(burg) {
return rn(normalize(deg, 0, 360) * 2, 2); // 0 = south, 0.5 = west, 1 = north, 1.5 = east
}
- const parameters = {name, population, size, seed, river, coast, farms, citadel, urban_castle, hub, plaza, temple, walls, shantytown, gates: -1};
+ const parameters = {
+ name,
+ population,
+ size,
+ seed,
+ river,
+ coast,
+ farms,
+ citadel,
+ urban_castle,
+ hub,
+ plaza,
+ temple,
+ walls,
+ shantytown,
+ gates: -1
+ };
const url = new URL("https://watabou.github.io/city-generator/");
url.search = new URLSearchParams(parameters);
if (sea) url.searchParams.append("sea", sea);
@@ -456,7 +472,12 @@ function createPicker() {
const cl = () => tip("Click to close the picker");
const closePicker = () => container.style("display", "none");
- const container = d3.select("body").append("svg").attr("id", "pickerContainer").attr("width", "100%").attr("height", "100%");
+ const container = d3
+ .select("body")
+ .append("svg")
+ .attr("id", "pickerContainer")
+ .attr("width", "100%")
+ .attr("height", "100%");
container
.append("rect")
.attr("x", 0)
@@ -589,8 +610,21 @@ function createPicker() {
.attr("height", 14)
.on("mousemove", cl)
.on("click", closePicker);
- picker.insert("text", ":first-child").attr("x", 12).attr("y", -10).attr("id", "pickerLabel").text("Color Picker").on("mousemove", pos);
- picker.insert("rect", ":first-child").attr("x", 0).attr("y", -30).attr("width", width).attr("height", 30).attr("id", "pickerHeader").on("mousemove", pos);
+ picker
+ .insert("text", ":first-child")
+ .attr("x", 12)
+ .attr("y", -10)
+ .attr("id", "pickerLabel")
+ .text("Color Picker")
+ .on("mousemove", pos);
+ picker
+ .insert("rect", ":first-child")
+ .attr("x", 0)
+ .attr("y", -30)
+ .attr("width", width)
+ .attr("height", 30)
+ .attr("id", "pickerHeader")
+ .on("mousemove", pos);
picker.attr("transform", `translate(${(svgWidth - width) / 2},${(svgHeight - height) / 2})`);
}
@@ -729,7 +763,12 @@ function changePickerSpace() {
const space = this.dataset.space;
const i = Array.from(this.parentNode.querySelectorAll("input")).map(input => input.value); // inputs
- const fill = space === "hex" ? d3.rgb(this.value) : space === "rgb" ? d3.rgb(i[0], i[1], i[2]) : d3.hsl(i[0], i[1] / 100, i[2] / 100);
+ const fill =
+ space === "hex"
+ ? d3.rgb(this.value)
+ : space === "rgb"
+ ? d3.rgb(i[0], i[1], i[2])
+ : d3.hsl(i[0], i[1] / 100, i[2] / 100);
const hsl = d3.hsl(fill);
if (isNaN(hsl.l)) {
@@ -750,7 +789,14 @@ function fog(id, path) {
if (defs.select("#fog #" + id).size()) return;
const fadeIn = d3.transition().duration(2000).ease(d3.easeSinInOut);
if (defs.select("#fog path").size()) {
- defs.select("#fog").append("path").attr("d", path).attr("id", id).attr("opacity", 0).transition(fadeIn).attr("opacity", 1);
+ defs
+ .select("#fog")
+ .append("path")
+ .attr("d", path)
+ .attr("id", id)
+ .attr("opacity", 0)
+ .transition(fadeIn)
+ .attr("opacity", 1);
} else {
defs.select("#fog").append("path").attr("d", path).attr("id", id).attr("opacity", 1);
const opacity = fogging.attr("opacity");
@@ -813,9 +859,20 @@ function highlightElement(element, zoom) {
const enter = d3.transition().duration(1000).ease(d3.easeBounceOut);
const exit = d3.transition().duration(500).ease(d3.easeLinear);
- const highlight = debug.append("rect").attr("x", box.x).attr("y", box.y).attr("width", box.width).attr("height", box.height);
+ const highlight = debug
+ .append("rect")
+ .attr("x", box.x)
+ .attr("y", box.y)
+ .attr("width", box.width)
+ .attr("height", box.height);
highlight.classed("highlighted", 1).attr("transform", transform);
- highlight.transition(enter).style("outline-offset", "0px").transition(exit).style("outline-color", "transparent").delay(1000).remove();
+ highlight
+ .transition(enter)
+ .style("outline-offset", "0px")
+ .transition(exit)
+ .style("outline-color", "transparent")
+ .delay(1000)
+ .remove();
if (zoom) {
const tr = parseTransform(transform);
@@ -1119,12 +1176,18 @@ function refreshAllEditors() {
// dynamically loaded editors
async function editStates() {
if (customization) return;
- const StateEditor = await import("../dynamic/editors/states-editor.js?v=29052022");
- StateEditor.open();
+ const Editor = await import("../dynamic/editors/states-editor.js?v=06062022");
+ Editor.open();
}
async function editCultures() {
if (customization) return;
- const CulturesEditor = await import("../dynamic/editors/cultures-editor.js?v=29052022");
- CulturesEditor.open();
+ const Editor = await import("../dynamic/editors/cultures-editor.js?v=06062022");
+ Editor.open();
+}
+
+async function editReligions() {
+ if (customization) return;
+ const Editor = await import("../dynamic/editors/religions-editor.js?v=06062022");
+ Editor.open();
}
diff --git a/modules/ui/layers.js b/modules/ui/layers.js
index 4f93cbab..304f455a 100644
--- a/modules/ui/layers.js
+++ b/modules/ui/layers.js
@@ -6,16 +6,68 @@ restoreCustomPresets(); // run on-load
function getDefaultPresets() {
return {
- political: ["toggleBorders", "toggleIcons", "toggleIce", "toggleLabels", "toggleRivers", "toggleRoutes", "toggleScaleBar", "toggleStates"],
- cultural: ["toggleBorders", "toggleCultures", "toggleIcons", "toggleLabels", "toggleRivers", "toggleRoutes", "toggleScaleBar"],
- religions: ["toggleBorders", "toggleIcons", "toggleLabels", "toggleReligions", "toggleRivers", "toggleRoutes", "toggleScaleBar"],
+ political: [
+ "toggleBorders",
+ "toggleIcons",
+ "toggleIce",
+ "toggleLabels",
+ "toggleRivers",
+ "toggleRoutes",
+ "toggleScaleBar",
+ "toggleStates"
+ ],
+ cultural: [
+ "toggleBorders",
+ "toggleCultures",
+ "toggleIcons",
+ "toggleLabels",
+ "toggleRivers",
+ "toggleRoutes",
+ "toggleScaleBar"
+ ],
+ religions: [
+ "toggleBorders",
+ "toggleIcons",
+ "toggleLabels",
+ "toggleReligions",
+ "toggleRivers",
+ "toggleRoutes",
+ "toggleScaleBar"
+ ],
provinces: ["toggleBorders", "toggleIcons", "toggleProvinces", "toggleRivers", "toggleScaleBar"],
biomes: ["toggleBiomes", "toggleIce", "toggleRivers", "toggleScaleBar"],
heightmap: ["toggleHeight", "toggleRivers"],
physical: ["toggleCoordinates", "toggleHeight", "toggleIce", "toggleRivers", "toggleScaleBar"],
- poi: ["toggleBorders", "toggleHeight", "toggleIce", "toggleIcons", "toggleMarkers", "toggleRivers", "toggleRoutes", "toggleScaleBar"],
- military: ["toggleBorders", "toggleIcons", "toggleLabels", "toggleMilitary", "toggleRivers", "toggleRoutes", "toggleScaleBar", "toggleStates"],
- emblems: ["toggleBorders", "toggleIcons", "toggleIce", "toggleEmblems", "toggleRivers", "toggleRoutes", "toggleScaleBar", "toggleStates"],
+ poi: [
+ "toggleBorders",
+ "toggleHeight",
+ "toggleIce",
+ "toggleIcons",
+ "toggleMarkers",
+ "toggleRivers",
+ "toggleRoutes",
+ "toggleScaleBar"
+ ],
+ military: [
+ "toggleBorders",
+ "toggleIcons",
+ "toggleLabels",
+ "toggleMilitary",
+ "toggleRivers",
+ "toggleRoutes",
+ "toggleScaleBar",
+ "toggleStates"
+ ],
+ emblems: [
+ "toggleBorders",
+ "toggleIcons",
+ "toggleIce",
+ "toggleEmblems",
+ "toggleRivers",
+ "toggleRoutes",
+ "toggleScaleBar",
+ "toggleStates"
+ ],
landmass: ["toggleScaleBar"]
};
}
@@ -193,12 +245,23 @@ function drawHeightmap() {
paths[h] += round(lineGen(points));
}
- terrs.append("rect").attr("x", 0).attr("y", 0).attr("width", graphWidth).attr("height", graphHeight).attr("fill", scheme(0.8)); // draw base layer
+ terrs
+ .append("rect")
+ .attr("x", 0)
+ .attr("y", 0)
+ .attr("width", graphWidth)
+ .attr("height", graphHeight)
+ .attr("fill", scheme(0.8)); // draw base layer
for (const i of d3.range(20, 101)) {
if (paths[i].length < 10) continue;
const color = getColor(i, scheme);
if (terracing)
- terrs.append("path").attr("d", paths[i]).attr("transform", "translate(.7,1.4)").attr("fill", d3.color(color).darker(terracing)).attr("data-height", i);
+ terrs
+ .append("path")
+ .attr("d", paths[i])
+ .attr("transform", "translate(.7,1.4)")
+ .attr("fill", d3.color(color).darker(terracing))
+ .attr("data-height", i);
terrs.append("path").attr("d", paths[i]).attr("fill", color).attr("data-height", i);
}
@@ -701,10 +764,8 @@ function drawCultures() {
TIME && console.time("drawCultures");
cults.selectAll("path").remove();
- const cells = pack.cells,
- vertices = pack.vertices,
- cultures = pack.cultures,
- n = cells.i.length;
+ const {cells, vertices, cultures} = pack;
+ const n = cells.i.length;
const used = new Uint8Array(cells.i.length);
const paths = new Array(cultures.length).fill("");
@@ -777,11 +838,9 @@ function drawReligions() {
TIME && console.time("drawReligions");
relig.selectAll("path").remove();
- const cells = pack.cells,
- vertices = pack.vertices,
- religions = pack.religions,
- features = pack.features,
- n = cells.i.length;
+ const {cells, vertices, religions} = pack;
+ const n = cells.i.length;
+
const used = new Uint8Array(cells.i.length);
const vArray = new Array(religions.length); // store vertices array
const body = new Array(religions.length).fill(""); // store path around each religion
@@ -801,11 +860,15 @@ function drawReligions() {
const points = chain.map(v => vertices.p[v[0]]);
if (!vArray[r]) vArray[r] = [];
vArray[r].push(points);
- body[r] += "M" + points.join("L");
+ body[r] += "M" + points.join("L") + "Z";
gap[r] +=
"M" +
vertices.p[chain[0][0]] +
- chain.reduce((r2, v, i, d) => (!i ? r2 : !v[2] ? r2 + "L" + vertices.p[v[0]] : d[i + 1] && !d[i + 1][2] ? r2 + "M" + vertices.p[v[0]] : r2), "");
+ chain.reduce(
+ (r2, v, i, d) =>
+ !i ? r2 : !v[2] ? r2 + "L" + vertices.p[v[0]] : d[i + 1] && !d[i + 1][2] ? r2 + "M" + vertices.p[v[0]] : r2,
+ ""
+ );
}
const bodyData = body.map((p, i) => [p.length > 10 ? p : null, i, religions[i].color]).filter(d => d[0]);
@@ -971,7 +1034,9 @@ function drawStates() {
const bodyString = bodyData.map(d => `
`).join("");
const gapString = gapData.map(d => `
`).join("");
- const clipString = bodyData.map(d => `
`).join("");
+ const clipString = bodyData
+ .map(d => `
`)
+ .join("");
const haloString = haloData
.map(
d =>
@@ -1064,7 +1129,9 @@ function drawBorders() {
const s = cells.state[i];
// if cell is on province border
- const provToCell = cells.c[i].find(n => cells.state[n] === s && p > cells.province[n] && pUsed[p][n] !== cells.province[n]);
+ const provToCell = cells.c[i].find(
+ n => cells.state[n] === s && p > cells.province[n] && pUsed[p][n] !== cells.province[n]
+ );
if (provToCell) {
const provTo = cells.province[provToCell];
pUsed[p][provToCell] = provTo;
@@ -1101,7 +1168,8 @@ function drawBorders() {
function connectVertices(current, f, array, t, used) {
let chain = [];
const checkCell = c => c >= n || array[c] !== f;
- const checkVertex = v => vertices.c[v].some(c => array[c] === f) && vertices.c[v].some(c => array[c] === t && cells.h[c] >= 20);
+ const checkVertex = v =>
+ vertices.c[v].some(c => array[c] === f) && vertices.c[v].some(c => array[c] === t && cells.h[c] >= 20);
// find starting vertex
for (let i = 0; i < 1000; i++) {
@@ -1234,7 +1302,11 @@ function getProvincesVertices() {
gap[p] +=
"M" +
vertices.p[chain[0][0]] +
- chain.reduce((r, v, i, d) => (!i ? r : !v[2] ? r + "L" + vertices.p[v[0]] : d[i + 1] && !d[i + 1][2] ? r + "M" + vertices.p[v[0]] : r), "");
+ chain.reduce(
+ (r, v, i, d) =>
+ !i ? r : !v[2] ? r + "L" + vertices.p[v[0]] : d[i + 1] && !d[i + 1][2] ? r + "M" + vertices.p[v[0]] : r,
+ ""
+ );
}
// find province visual center
@@ -1373,7 +1445,17 @@ function drawCoordinates() {
pos = projection(c); // map coordinates
const [x, y] = lat ? [rn(p.x, 2), rn(pos[1], 2)] : [rn(pos[0], 2), rn(p.y, 2)]; // labels position
const v = lat ? c[1] : c[0]; // label
- const text = !v ? v : Number.isInteger(v) ? (lat ? (c[1] < 0 ? -c[1] + "°S" : c[1] + "°N") : c[0] < 0 ? -c[0] + "°W" : c[0] + "°E") : "";
+ const text = !v
+ ? v
+ : Number.isInteger(v)
+ ? lat
+ ? c[1] < 0
+ ? -c[1] + "°S"
+ : c[1] + "°N"
+ : c[0] < 0
+ ? -c[0] + "°W"
+ : c[0] + "°E"
+ : "";
return {lat, x, y, text};
});
@@ -1483,7 +1565,9 @@ function drawRivers() {
if (!cells || cells.length < 2) return;
if (points && points.length !== cells.length) {
- console.error(`River ${i} has ${cells.length} cells, but only ${points.length} points defined. Resetting points data`);
+ console.error(
+ `River ${i} has ${cells.length} cells, but only ${points.length} points defined. Resetting points data`
+ );
points = undefined;
}
@@ -1552,15 +1636,20 @@ const getPin = (shape = "bubble", fill = "#fff", stroke = "#000") => {
return `
`;
if (shape === "pin")
return `
`;
- if (shape === "square") return `
`;
- if (shape === "squarish") return `
`;
+ if (shape === "square")
+ return `
`;
+ if (shape === "squarish")
+ return `
`;
if (shape === "diamond") return `
`;
if (shape === "hex") return `
`;
if (shape === "hexy") return `
`;
- if (shape === "shieldy") return `
`;
- if (shape === "shield") return `
`;
+ if (shape === "shieldy")
+ return `
`;
+ if (shape === "shield")
+ return `
`;
if (shape === "pentagon") return `
`;
- if (shape === "heptagon") return `
`;
+ if (shape === "heptagon")
+ return `
`;
if (shape === "circle") return `
`;
if (shape === "no") return "";
};
@@ -1744,19 +1833,34 @@ function drawEmblems() {
const burgNodes = nodes.filter(node => node.type === "burg");
const burgString = burgNodes
- .map(d => `
`)
+ .map(
+ d =>
+ `
`
+ )
.join("");
emblems.select("#burgEmblems").attr("font-size", sizeBurgs).html(burgString);
const provinceNodes = nodes.filter(node => node.type === "province");
const provinceString = provinceNodes
- .map(d => `
`)
+ .map(
+ d =>
+ `
`
+ )
.join("");
emblems.select("#provinceEmblems").attr("font-size", sizeProvinces).html(provinceString);
const stateNodes = nodes.filter(node => node.type === "state");
const stateString = stateNodes
- .map(d => `
`)
+ .map(
+ d =>
+ `
`
+ )
.join("");
emblems.select("#stateEmblems").attr("font-size", sizeStates).html(stateString);
diff --git a/modules/ui/religions-editor.js b/modules/ui/religions-editor.js
deleted file mode 100644
index e4e9d174..00000000
--- a/modules/ui/religions-editor.js
+++ /dev/null
@@ -1,799 +0,0 @@
-"use strict";
-function editReligions() {
- if (customization) return;
- closeDialogs("#religionsEditor, .stable");
- if (!layerIsOn("toggleReligions")) toggleReligions();
- if (layerIsOn("toggleCultures")) toggleCultures();
- if (layerIsOn("toggleStates")) toggleStates();
- if (layerIsOn("toggleBiomes")) toggleBiomes();
- if (layerIsOn("toggleProvinces")) toggleProvinces();
-
- const body = document.getElementById("religionsBody");
- const animate = d3.transition().duration(1500).ease(d3.easeSinIn);
- refreshReligionsEditor();
- drawReligionCenters();
-
- if (modules.editReligions) return;
- modules.editReligions = true;
-
- $("#religionsEditor").dialog({
- title: "Religions Editor",
- resizable: false,
- width: fitContent(),
- close: closeReligionsEditor,
- position: {my: "right top", at: "right-10 top+10", of: "svg"}
- });
-
- // add listeners
- document.getElementById("religionsEditorRefresh").addEventListener("click", refreshReligionsEditor);
- document.getElementById("religionsEditStyle").addEventListener("click", () => editStyle("relig"));
- document.getElementById("religionsLegend").addEventListener("click", toggleLegend);
- document.getElementById("religionsPercentage").addEventListener("click", togglePercentageMode);
- document.getElementById("religionsHeirarchy").addEventListener("click", showHierarchy);
- document.getElementById("religionsExtinct").addEventListener("click", toggleExtinct);
- document.getElementById("religionsManually").addEventListener("click", enterReligionsManualAssignent);
- document.getElementById("religionsManuallyApply").addEventListener("click", applyReligionsManualAssignent);
- document.getElementById("religionsManuallyCancel").addEventListener("click", () => exitReligionsManualAssignment());
- document.getElementById("religionsAdd").addEventListener("click", enterAddReligionMode);
- document.getElementById("religionsExport").addEventListener("click", downloadReligionsData);
-
- function refreshReligionsEditor() {
- religionsCollectStatistics();
- religionsEditorAddLines();
- }
-
- function religionsCollectStatistics() {
- const cells = pack.cells,
- religions = pack.religions;
- religions.forEach(r => (r.cells = r.area = r.rural = r.urban = 0));
-
- for (const i of cells.i) {
- if (cells.h[i] < 20) continue;
- const r = cells.religion[i];
- religions[r].cells += 1;
- religions[r].area += cells.area[i];
- religions[r].rural += cells.pop[i];
- if (cells.burg[i]) religions[r].urban += pack.burgs[cells.burg[i]].population;
- }
- }
-
- // add line for each religion
- function religionsEditorAddLines() {
- const unit = " " + getAreaUnit();
- let lines = "",
- totalArea = 0,
- totalPopulation = 0;
-
- for (const r of pack.religions) {
- if (r.removed) continue;
-
- const area = getArea(r.area);
- const rural = r.rural * populationRate;
- const urban = r.urban * populationRate * urbanization;
- const population = rn(rural + urban);
- if (r.i && !r.cells && body.dataset.extinct !== "show") continue; // hide extinct religions
- const populationTip = `Believers: ${si(population)}; Rural areas: ${si(rural)}; Urban areas: ${si(urban)}. Click to change`;
- totalArea += area;
- totalPopulation += population;
-
- if (r.i) {
- lines += /* html */ `
-
-
-
- ${getTypeOptions(r.type)}
-
-
-
-
-
-
${si(area) + unit}
-
-
${si(population)}
-
-
`;
- } else {
- // No religion (neutral) line
- lines += /* html */ `
-
-
-
- ${getTypeOptions(r.type)}
-
-
-
-
-
-
${si(area) + unit}
-
-
${si(population)}
-
`;
- }
- }
- body.innerHTML = lines;
-
- // update footer
- const valid = pack.religions.filter(r => r.i && !r.removed);
- religionsOrganized.innerHTML = valid.filter(r => r.type === "Organized").length;
- religionsHeresies.innerHTML = valid.filter(r => r.type === "Heresy").length;
- religionsCults.innerHTML = valid.filter(r => r.type === "Cult").length;
- religionsFolk.innerHTML = valid.filter(r => r.type === "Folk").length;
- religionsFooterArea.innerHTML = si(totalArea) + unit;
- religionsFooterPopulation.innerHTML = si(totalPopulation);
- religionsFooterArea.dataset.area = totalArea;
- religionsFooterPopulation.dataset.population = totalPopulation;
-
- // add listeners
- body.querySelectorAll("div.religions").forEach(el => el.addEventListener("mouseenter", ev => religionHighlightOn(ev)));
- body.querySelectorAll("div.religions").forEach(el => el.addEventListener("mouseleave", ev => religionHighlightOff(ev)));
- body.querySelectorAll("div.states").forEach(el => el.addEventListener("click", selectReligionOnLineClick));
- body.querySelectorAll("fill-box").forEach(el => el.addEventListener("click", religionChangeColor));
- body.querySelectorAll("div > input.religionName").forEach(el => el.addEventListener("input", religionChangeName));
- body.querySelectorAll("div > select.religionType").forEach(el => el.addEventListener("change", religionChangeType));
- body.querySelectorAll("div > input.religionForm").forEach(el => el.addEventListener("input", religionChangeForm));
- body.querySelectorAll("div > input.religionDeity").forEach(el => el.addEventListener("input", religionChangeDeity));
- body.querySelectorAll("div > span.icon-arrows-cw").forEach(el => el.addEventListener("click", regenerateDeity));
- body.querySelectorAll("div > div.culturePopulation").forEach(el => el.addEventListener("click", changePopulation));
- body.querySelectorAll("div > span.icon-trash-empty").forEach(el => el.addEventListener("click", religionRemove));
-
- if (body.dataset.type === "percentage") {
- body.dataset.type = "absolute";
- togglePercentageMode();
- }
- applySorting(religionsHeader);
- $("#religionsEditor").dialog({width: fitContent()});
- }
-
- function getTypeOptions(type) {
- let options = "";
- const types = ["Folk", "Organized", "Cult", "Heresy"];
- types.forEach(t => (options += `
${t} `));
- return options;
- }
-
- function religionHighlightOn(event) {
- const religion = +event.target.dataset.id;
- const info = document.getElementById("religionInfo");
- if (info) {
- d3.select("#hierarchy")
- .select("g[data-id='" + religion + "'] > path")
- .classed("selected", 1);
- const r = pack.religions[religion];
- const type = r.name.includes(r.type) ? "" : r.type === "Folk" || r.type === "Organized" ? ". " + r.type + " religion" : ". " + r.type;
- const form = r.form === r.type || r.name.includes(r.form) ? "" : ". " + r.form;
- const rural = r.rural * populationRate;
- const urban = r.urban * populationRate * urbanization;
- const population = rural + urban > 0 ? ". " + si(rn(rural + urban)) + " believers" : ". Extinct";
- info.innerHTML = /* html */ `${r.name}${type}${form}${population}`;
- tip("Drag to change parent, drag to itself to move to the top level. Hold CTRL and click to change abbreviation");
- }
-
- const el = body.querySelector(`div[data-id='${religion}']`);
- if (el) el.classList.add("active");
-
- if (!layerIsOn("toggleReligions")) return;
- if (customization) return;
- relig
- .select("#religion" + religion)
- .raise()
- .transition(animate)
- .attr("stroke-width", 2.5)
- .attr("stroke", "#c13119");
- debug
- .select("#religionsCenter" + religion)
- .raise()
- .transition(animate)
- .attr("r", 8)
- .attr("stroke-width", 2)
- .attr("stroke", "#c13119");
- }
-
- function religionHighlightOff(event) {
- const religion = +event.target.dataset.id;
- const info = document.getElementById("religionInfo");
- if (info) {
- d3.select("#hierarchy")
- .select("g[data-id='" + religion + "'] > path")
- .classed("selected", 0);
- info.innerHTML = "";
- tip("");
- }
-
- const el = body.querySelector(`div[data-id='${religion}']`);
- if (el) el.classList.remove("active");
-
- relig
- .select("#religion" + religion)
- .transition()
- .attr("stroke-width", null)
- .attr("stroke", null);
- debug
- .select("#religionsCenter" + religion)
- .transition()
- .attr("r", 4)
- .attr("stroke-width", 1.2)
- .attr("stroke", null);
- }
-
- function religionChangeColor() {
- const el = this;
- const currentFill = el.getAttribute("fill");
- const religion = +el.parentNode.dataset.id;
-
- const callback = newFill => {
- el.fill = newFill;
- pack.religions[religion].color = newFill;
- relig.select("#religion" + religion).attr("fill", newFill);
- debug.select("#religionsCenter" + religion).attr("fill", newFill);
- };
-
- openPicker(currentFill, callback);
- }
-
- function religionChangeName() {
- const religion = +this.parentNode.dataset.id;
- this.parentNode.dataset.name = this.value;
- pack.religions[religion].name = this.value;
- pack.religions[religion].code = abbreviate(
- this.value,
- pack.religions.map(c => c.code)
- );
- }
-
- function religionChangeType() {
- const religion = +this.parentNode.dataset.id;
- this.parentNode.dataset.type = this.value;
- pack.religions[religion].type = this.value;
- }
-
- function religionChangeForm() {
- const religion = +this.parentNode.dataset.id;
- this.parentNode.dataset.form = this.value;
- pack.religions[religion].form = this.value;
- }
-
- function religionChangeDeity() {
- const religion = +this.parentNode.dataset.id;
- this.parentNode.dataset.deity = this.value;
- pack.religions[religion].deity = this.value;
- }
-
- function regenerateDeity() {
- const religion = +this.parentNode.dataset.id;
- const culture = pack.religions[religion].culture;
- const deity = Religions.getDeityName(culture);
- this.parentNode.dataset.deity = deity;
- pack.religions[religion].deity = deity;
- this.nextElementSibling.value = deity;
- }
-
- function changePopulation() {
- const religion = +this.parentNode.dataset.id;
- const r = pack.religions[religion];
- if (!r.cells) {
- tip("Religion does not have any cells, cannot change population", false, "error");
- return;
- }
- const rural = rn(r.rural * populationRate);
- const urban = rn(r.urban * populationRate * urbanization);
- const total = rural + urban;
- const l = n => Number(n).toLocaleString();
- const burgs = pack.burgs.filter(b => !b.removed && pack.cells.religion[b.cell] === religion);
-
- alertMessage.innerHTML = /* html */ `
- Please note all population of religion territory is considered believers of this religion. It means believers number change will directly change
- population
-
- Rural:
Urban:
-
-
Total believers: ${l(total)} ⇒ ${l(total)} (100 %)
`;
-
- const update = function () {
- const totalNew = ruralPop.valueAsNumber + urbanPop.valueAsNumber;
- if (isNaN(totalNew)) return;
- totalPop.innerHTML = l(totalNew);
- totalPopPerc.innerHTML = rn((totalNew / total) * 100);
- };
-
- ruralPop.oninput = () => update();
- urbanPop.oninput = () => update();
-
- $("#alert").dialog({
- resizable: false,
- title: "Change believers number",
- width: "24em",
- buttons: {
- Apply: function () {
- applyPopulationChange();
- $(this).dialog("close");
- },
- Cancel: function () {
- $(this).dialog("close");
- }
- },
- position: {my: "center", at: "center", of: "svg"}
- });
-
- function applyPopulationChange() {
- const ruralChange = ruralPop.value / rural;
- if (isFinite(ruralChange) && ruralChange !== 1) {
- const cells = pack.cells.i.filter(i => pack.cells.religion[i] === religion);
- cells.forEach(i => (pack.cells.pop[i] *= ruralChange));
- }
- if (!isFinite(ruralChange) && +ruralPop.value > 0) {
- const points = ruralPop.value / populationRate;
- const cells = pack.cells.i.filter(i => pack.cells.religion[i] === religion);
- const pop = rn(points / cells.length);
- cells.forEach(i => (pack.cells.pop[i] = pop));
- }
-
- const urbanChange = urbanPop.value / urban;
- if (isFinite(urbanChange) && urbanChange !== 1) {
- burgs.forEach(b => (b.population = rn(b.population * urbanChange, 4)));
- }
- if (!isFinite(urbanChange) && +urbanPop.value > 0) {
- const points = urbanPop.value / populationRate / urbanization;
- const population = rn(points / burgs.length, 4);
- burgs.forEach(b => (b.population = population));
- }
-
- refreshReligionsEditor();
- }
- }
-
- function religionRemove() {
- if (customization) return;
- const religion = +this.parentNode.dataset.id;
-
- alertMessage.innerHTML = "Are you sure you want to remove the religion?
This action cannot be reverted";
- $("#alert").dialog({
- resizable: false,
- title: "Remove religion",
- buttons: {
- Remove: function () {
- relig.select("#religion" + religion).remove();
- relig.select("#religion-gap" + religion).remove();
- debug.select("#religionsCenter" + religion).remove();
-
- pack.cells.religion.forEach((r, i) => {
- if (r === religion) pack.cells.religion[i] = 0;
- });
- pack.religions[religion].removed = true;
- const origin = pack.religions[religion].origin;
- pack.religions.forEach(r => {
- if (r.origin === religion) r.origin = origin;
- });
-
- refreshReligionsEditor();
- $(this).dialog("close");
- },
- Cancel: function () {
- $(this).dialog("close");
- }
- }
- });
- }
-
- function drawReligionCenters() {
- debug.select("#religionCenters").remove();
- const religionCenters = debug.append("g").attr("id", "religionCenters").attr("stroke-width", 1.2).attr("stroke", "#444444").style("cursor", "move");
-
- const data = pack.religions.filter(r => r.i && r.center && r.cells && !r.removed);
- religionCenters
- .selectAll("circle")
- .data(data)
- .enter()
- .append("circle")
- .attr("id", d => "religionsCenter" + d.i)
- .attr("data-id", d => d.i)
- .attr("r", 4)
- .attr("fill", d => d.color)
- .attr("cx", d => pack.cells.p[d.center][0])
- .attr("cy", d => pack.cells.p[d.center][1])
- .on("mouseenter", d => {
- tip(d.name + ". Drag to move the religion center", true);
- religionHighlightOn(event);
- })
- .on("mouseleave", d => {
- tip("", true);
- religionHighlightOff(event);
- })
- .call(d3.drag().on("start", religionCenterDrag));
- }
-
- function religionCenterDrag() {
- const el = d3.select(this);
- const r = +this.dataset.id;
- d3.event.on("drag", () => {
- el.attr("cx", d3.event.x).attr("cy", d3.event.y);
- const cell = findCell(d3.event.x, d3.event.y);
- if (pack.cells.h[cell] < 20) return; // ignore dragging on water
- pack.religions[r].center = cell;
- });
- }
-
- function toggleLegend() {
- if (legend.selectAll("*").size()) {
- clearLegend();
- return;
- } // hide legend
- const data = pack.religions
- .filter(r => r.i && !r.removed && r.area)
- .sort((a, b) => b.area - a.area)
- .map(r => [r.i, r.color, r.name]);
- drawLegend("Religions", data);
- }
-
- function togglePercentageMode() {
- if (body.dataset.type === "absolute") {
- body.dataset.type = "percentage";
- const totalArea = +religionsFooterArea.dataset.area;
- const totalPopulation = +religionsFooterPopulation.dataset.population;
-
- body.querySelectorAll(":scope > div").forEach(function (el) {
- el.querySelector(".biomeArea").innerHTML = rn((+el.dataset.area / totalArea) * 100) + "%";
- el.querySelector(".culturePopulation").innerHTML = rn((+el.dataset.population / totalPopulation) * 100) + "%";
- });
- } else {
- body.dataset.type = "absolute";
- religionsEditorAddLines();
- }
- }
-
- function showHierarchy() {
- // build hierarchy tree
- pack.religions[0].origin = null;
- const religions = pack.religions.filter(r => !r.removed);
- if (religions.length < 3) {
- tip("Not enough religions to show hierarchy", false, "error");
- return;
- }
- const root = d3
- .stratify()
- .id(d => d.i)
- .parentId(d => d.origin)(religions);
- const treeWidth = root.leaves().length;
- const treeHeight = root.height;
- const width = treeWidth * 40,
- height = treeHeight * 60;
-
- const margin = {top: 10, right: 10, bottom: -5, left: 10};
- const w = width - margin.left - margin.right;
- const h = height + 30 - margin.top - margin.bottom;
- const treeLayout = d3.tree().size([w, h]);
-
- // prepare svg
- alertMessage.innerHTML = "
";
- const svg = d3
- .select("#alertMessage")
- .insert("svg", "#religionInfo")
- .attr("id", "hierarchy")
- .attr("width", width)
- .attr("height", height)
- .style("text-anchor", "middle");
- const graph = svg.append("g").attr("transform", `translate(10, -45)`);
- const links = graph.append("g").attr("fill", "none").attr("stroke", "#aaaaaa");
- const nodes = graph.append("g");
-
- renderTree();
- function renderTree() {
- treeLayout(root);
- links
- .selectAll("path")
- .data(root.links())
- .enter()
- .append("path")
- .attr("d", d => {
- return (
- "M" +
- d.source.x +
- "," +
- d.source.y +
- "C" +
- d.source.x +
- "," +
- (d.source.y * 3 + d.target.y) / 4 +
- " " +
- d.target.x +
- "," +
- (d.source.y * 2 + d.target.y) / 3 +
- " " +
- d.target.x +
- "," +
- d.target.y
- );
- });
-
- const node = nodes
- .selectAll("g")
- .data(root.descendants())
- .enter()
- .append("g")
- .attr("data-id", d => d.data.i)
- .attr("stroke", "#333333")
- .attr("transform", d => `translate(${d.x}, ${d.y})`)
- .on("mouseenter", () => religionHighlightOn(event))
- .on("mouseleave", () => religionHighlightOff(event))
- .call(d3.drag().on("start", d => dragToReorigin(d)));
-
- node
- .append("path")
- .attr("d", d => {
- if (d.data.type === "Folk") return "M11.3,0A11.3,11.3,0,1,1,-11.3,0A11.3,11.3,0,1,1,11.3,0";
- // circle
- else if (d.data.type === "Heresy") return "M0,-14L14,0L0,14L-14,0Z";
- // diamond
- else if (d.data.type === "Cult") return "M-6.5,-11.26l13,0l6.5,11.26l-6.5,11.26l-13,0l-6.5,-11.26Z";
- // hex
- else if (!d.data.i) return "M5,0A5,5,0,1,1,-5,0A5,5,0,1,1,5,0";
- // small circle
- else return "M-11,-11h22v22h-22Z"; // square
- })
- .attr("fill", d => (d.data.i ? d.data.color : "#ffffff"))
- .attr("stroke-dasharray", d => (d.data.cells ? "null" : "1"));
-
- node
- .append("text")
- .attr("dy", ".35em")
- .text(d => (d.data.i ? d.data.code : ""));
- }
-
- $("#alert").dialog({
- title: "Religions tree",
- width: fitContent(),
- resizable: false,
- position: {my: "left center", at: "left+10 center", of: "svg"},
- buttons: {},
- close: () => {
- alertMessage.innerHTML = "";
- }
- });
-
- function dragToReorigin(d) {
- if (isCtrlClick(d3.event.sourceEvent)) {
- changeCode(d);
- return;
- }
-
- const originLine = graph.append("path").attr("class", "dragLine").attr("d", `M${d.x},${d.y}L${d.x},${d.y}`);
-
- d3.event.on("drag", () => {
- originLine.attr("d", `M${d.x},${d.y}L${d3.event.x},${d3.event.y}`);
- });
-
- d3.event.on("end", () => {
- originLine.remove();
- const selected = graph.select("path.selected");
- if (!selected.size()) return;
- const religion = d.data.i;
- const oldOrigin = d.data.origin;
- let newOrigin = selected.datum().data.i;
- if (newOrigin == oldOrigin) return; // already a child of the selected node
- if (newOrigin == religion) newOrigin = 0; // move to top
- if (newOrigin && d.descendants().some(node => node.id == newOrigin)) return; // cannot be a child of its own child
- pack.religions[religion].origin = d.data.origin = newOrigin; // change data
- showHierarchy(); // update hierarchy
- });
- }
-
- function changeCode(d) {
- prompt(`Please provide an abbreviation for ${d.data.name}`, {default: d.data.code}, v => {
- pack.religions[d.data.i].code = v;
- nodes
- .select("g[data-id='" + d.data.i + "']")
- .select("text")
- .text(v);
- });
- }
- }
-
- function toggleExtinct() {
- body.dataset.extinct = body.dataset.extinct !== "show" ? "show" : "hide";
- religionsEditorAddLines();
- }
-
- function enterReligionsManualAssignent() {
- if (!layerIsOn("toggleReligions")) toggleReligions();
- customization = 7;
- relig.append("g").attr("id", "temp");
- document.querySelectorAll("#religionsBottom > button").forEach(el => (el.style.display = "none"));
- document.getElementById("religionsManuallyButtons").style.display = "inline-block";
- debug.select("#religionCenters").style("display", "none");
-
- religionsEditor.querySelectorAll(".hide").forEach(el => el.classList.add("hidden"));
- religionsFooter.style.display = "none";
- body.querySelectorAll("div > input, select, span, svg").forEach(e => (e.style.pointerEvents = "none"));
- $("#religionsEditor").dialog({position: {my: "right top", at: "right-10 top+10", of: "svg"}});
-
- tip("Click on religion to select, drag the circle to change religion", true);
- viewbox
- .style("cursor", "crosshair")
- .on("click", selectReligionOnMapClick)
- .call(d3.drag().on("start", dragReligionBrush))
- .on("touchmove mousemove", moveReligionBrush);
-
- body.querySelector("div").classList.add("selected");
- }
-
- function selectReligionOnLineClick(i) {
- if (customization !== 7) return;
- body.querySelector("div.selected").classList.remove("selected");
- this.classList.add("selected");
- }
-
- function selectReligionOnMapClick() {
- const point = d3.mouse(this);
- const i = findCell(point[0], point[1]);
- if (pack.cells.h[i] < 20) return;
-
- const assigned = relig.select("#temp").select("polygon[data-cell='" + i + "']");
- const religion = assigned.size() ? +assigned.attr("data-religion") : pack.cells.religion[i];
-
- body.querySelector("div.selected").classList.remove("selected");
- body.querySelector("div[data-id='" + religion + "']").classList.add("selected");
- }
-
- function dragReligionBrush() {
- const r = +religionsManuallyBrushNumber.value;
-
- d3.event.on("drag", () => {
- if (!d3.event.dx && !d3.event.dy) return;
- const p = d3.mouse(this);
- moveCircle(p[0], p[1], r);
-
- const found = r > 5 ? findAll(p[0], p[1], r) : [findCell(p[0], p[1], r)];
- const selection = found.filter(isLand);
- if (selection) changeReligionForSelection(selection);
- });
- }
-
- // change religion within selection
- function changeReligionForSelection(selection) {
- const temp = relig.select("#temp");
- const selected = body.querySelector("div.selected");
- const r = +selected.dataset.id; // religionNew
- const color = pack.religions[r].color || "#ffffff";
-
- selection.forEach(function (i) {
- const exists = temp.select("polygon[data-cell='" + i + "']");
- const religionOld = exists.size() ? +exists.attr("data-religion") : pack.cells.religion[i];
- if (r === religionOld) return;
-
- // change of append new element
- if (exists.size()) exists.attr("data-religion", r).attr("fill", color);
- else temp.append("polygon").attr("data-cell", i).attr("data-religion", r).attr("points", getPackPolygon(i)).attr("fill", color);
- });
- }
-
- function moveReligionBrush() {
- showMainTip();
- const point = d3.mouse(this);
- const radius = +religionsManuallyBrushNumber.value;
- moveCircle(point[0], point[1], radius);
- }
-
- function applyReligionsManualAssignent() {
- const changed = relig.select("#temp").selectAll("polygon");
- changed.each(function () {
- const i = +this.dataset.cell;
- const r = +this.dataset.religion;
- pack.cells.religion[i] = r;
- });
-
- if (changed.size()) {
- drawReligions();
- refreshReligionsEditor();
- drawReligionCenters();
- }
- exitReligionsManualAssignment();
- }
-
- function exitReligionsManualAssignment(close) {
- customization = 0;
- relig.select("#temp").remove();
- removeCircle();
- document.querySelectorAll("#religionsBottom > button").forEach(el => (el.style.display = "inline-block"));
- document.getElementById("religionsManuallyButtons").style.display = "none";
-
- religionsEditor.querySelectorAll(".hide").forEach(el => el.classList.remove("hidden"));
- religionsFooter.style.display = "block";
- 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"}});
-
- debug.select("#religionCenters").style("display", null);
- restoreDefaultEvents();
- clearMainTip();
- const selected = body.querySelector("div.selected");
- if (selected) selected.classList.remove("selected");
- }
-
- function enterAddReligionMode() {
- if (this.classList.contains("pressed")) {
- exitAddReligionMode();
- return;
- }
- customization = 8;
- this.classList.add("pressed");
- tip("Click on the map to add a new religion", true);
- viewbox.style("cursor", "crosshair").on("click", addReligion);
- body.querySelectorAll("div > input, select, span, svg").forEach(e => (e.style.pointerEvents = "none"));
- }
-
- function exitAddReligionMode() {
- customization = 0;
- restoreDefaultEvents();
- clearMainTip();
- body.querySelectorAll("div > input, select, span, svg").forEach(e => (e.style.pointerEvents = "all"));
- if (religionsAdd.classList.contains("pressed")) religionsAdd.classList.remove("pressed");
- }
-
- function addReligion() {
- const point = d3.mouse(this);
- const center = findCell(point[0], point[1]);
- if (pack.cells.h[center] < 20) {
- 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);
- if (occupied) {
- tip("This cell is already a religion center. Please select a different cell", false, "error");
- return;
- }
-
- if (d3.event.shiftKey === false) exitAddReligionMode();
- Religions.add(center);
-
- drawReligions();
- refreshReligionsEditor();
- drawReligionCenters();
- }
-
- function downloadReligionsData() {
- const unit = areaUnit.value === "square" ? distanceUnitInput.value + "2" : areaUnit.value;
- let data = "Id,Religion,Color,Type,Form,Deity,Area " + unit + ",Believers\n"; // headers
-
- body.querySelectorAll(":scope > div").forEach(function (el) {
- data += el.dataset.id + ",";
- data += el.dataset.name + ",";
- data += el.dataset.color + ",";
- data += el.dataset.type + ",";
- data += el.dataset.form + ",";
- data += el.dataset.deity.replace(",", " -") + ",";
- data += el.dataset.area + ",";
- data += el.dataset.population + "\n";
- });
-
- const name = getFileName("Religions") + ".csv";
- downloadFile(data, name);
- }
-
- function closeReligionsEditor() {
- debug.select("#religionCenters").remove();
- exitReligionsManualAssignment("close");
- exitAddReligionMode();
- }
-}
diff --git a/versioning.js b/versioning.js
index 24ba6288..f2da3518 100644
--- a/versioning.js
+++ b/versioning.js
@@ -1,7 +1,7 @@
"use strict";
// version and caching control
-const version = "1.85.02"; // generator version, update each time
+const version = "1.86.00"; // generator version, update each time
{
document.title += " v" + version;
@@ -28,6 +28,7 @@ const version = "1.85.02"; // generator version, update each time
Latest changes:
+ Сultures and religions can have multiple parents in hierarchy tree
Heightmap selection screen
Dialogs optimization for mobile
New heightmap template: Fractious