This commit is contained in:
Azgaar 2019-12-23 20:06:43 +03:00
parent f684996f82
commit bc6b8cdafe
18 changed files with 111 additions and 111 deletions

View file

@ -40,7 +40,7 @@
if (sorted.length < count * 10) {
count = Math.floor(sorted.length / 10);
if (!count) {console.warn(`There is no populated cells. Cannot generate states`); return burgs;}
if (!count) {console.warn(`There is no populated cells. Cannot generate states`); return burgs;}
else {console.warn(`Not enought populated cells (${sorted.length}). Will generate only ${count} states`);}
}
@ -92,7 +92,7 @@
states.push({i, color: colors[i-1], name, expansionism, capital: i, type, center: b.cell, culture: b.culture});
cells.burg[b.cell] = i;
});
console.timeEnd('createStates');
return states;
}
@ -219,11 +219,11 @@
capitalLabels.selectAll("text").data(capitals).enter()
.append("text").attr("id", d => "burgLabel"+d.i).attr("data-id", d => d.i)
.attr("x", d => d.x).attr("y", d => d.y).attr("dy", `${capitalSize * -1.5}px`).text(d => d.name);
capitalAnchors.selectAll("use").data(capitals.filter(c => c.port)).enter()
.append("use").attr("xlink:href", "#icon-anchor").attr("data-id", d => d.i)
.attr("x", d => rn(d.x - caSize * .47, 2)).attr("y", d => rn(d.y - caSize * .47, 2))
.attr("width", caSize).attr("height", caSize);
.attr("width", caSize).attr("height", caSize);
// towns
const towns = pack.burgs.filter(b => b.i && !b.capital);
@ -260,7 +260,7 @@
states.filter(s => s.i && !s.removed).forEach(function(s) {
cells.state[burgs[s.capital].cell] = s.i;
const b = cells.biome[cultures[s.culture].center]; // native biome
queue.queue({e:s.center, p:0, s:s.i, b});
queue.queue({e:s.center, p:0, s:s.i, b});
cost[s.center] = 1;
});
const neutral = cells.i.length / 5000 * 2000 * neutralInput.value * statesNeutral.value; // limit cost for state growth
@ -312,7 +312,7 @@
function getRiverCost(r, i, type) {
if (type === "River") return r ? 0 : 100; // penalty for river cultures
if (!r) return 0; // no penalty for others if there is no river
if (!r) return 0; // no penalty for others if there is no river
return Math.min(Math.max(cells.fl[i] / 10, 20), 100) // river penalty from 20 to 100 based on flux
}
@ -372,7 +372,7 @@
function getHull(start, state, maxLake) {
const queue = [start], hull = new Set();
while (queue.length) {
const q = queue.pop();
const nQ = cells.c[q].filter(c => cells.state[c] === state);
@ -388,7 +388,7 @@
queue.push(c);
});
}
return hull;
}
@ -414,7 +414,7 @@
while (queue.length) {
const next = queue.dequeue(), n = next.e, p = next.p;
if (n === end) break;
for (const v of c.v[n]) {
if (v === -1) continue;
const totalCost = p + (inside[v] ? 1 : 100);
@ -436,7 +436,7 @@
}
}
void function drawLabels() {
const g = labels.select("#states"), t = defs.select("#textPaths");
const displayed = layerIsOn("toggleLabels");
@ -553,7 +553,7 @@
states[s].area += cells.area[i];
states[s].rural += cells.pop[i];
if (cells.burg[i]) {
states[s].urban += pack.burgs[cells.burg[i]].population;
states[s].urban += pack.burgs[cells.burg[i]].population;
states[s].burgs++;
}
}
@ -995,8 +995,8 @@
console.timeEnd("generateProvinces");
}
return {generate, expandStates, normalizeStates, assignColors,
drawBurgs, specifyBurgs, defineBurgFeatures, drawStateLabels, collectStatistics,
return {generate, expandStates, normalizeStates, assignColors,
drawBurgs, specifyBurgs, defineBurgFeatures, drawStateLabels, collectStatistics,
generateDiplomacy, defineStateForms, getFullName, generateProvinces};
})));

View file

@ -5,7 +5,7 @@
}(this, (function () {'use strict';
let cells;
const generate = function() {
console.time('generateCultures');
cells = pack.cells;
@ -99,7 +99,7 @@
if (b === 3 || b === 9 || b === 10) return "Hunting"; // high penalty in non-native biomes
return "Generic";
}
function defineCultureExpansionism(type) {
let base = 1; // Generic
if (type === "Lake") base = .8; else
@ -348,7 +348,7 @@
];
}
// expand cultures across the map (Dijkstra-like algorithm)
// expand cultures across the map (Dijkstra-like algorithm)
const expand = function() {
console.time('expandCultures');
cells = pack.cells;
@ -358,7 +358,7 @@
if (!c.i || c.removed) return;
queue.queue({e:c.center, p:0, c:c.i});
});
const neutral = cells.i.length / 5000 * 3000 * neutralInput.value; // limit cost for culture growth
const cost = [];
while (queue.length) {
@ -413,7 +413,7 @@
function getRiverCost(r, i, type) {
if (type === "River") return r ? 0 : 100; // penalty for river cultures
if (!r) return 0; // no penalty for others if there is no river
if (!r) return 0; // no penalty for others if there is no river
return Math.min(Math.max(cells.fl[i] / 10, 20), 100) // river penalty from 20 to 100 based on flux
}

View file

@ -293,7 +293,7 @@
// find start and end points
const startX = getPointInRange(rangeX, graphWidth);
const startY = getPointInRange(rangeY, graphHeight);
let dist = 0, limit = 0, endX, endY;
do {
endX = Math.random() * graphWidth * .8 + graphWidth * .1;
@ -382,7 +382,7 @@
limit++;
} while ((dist < graphWidth / 8 || dist > graphWidth / 2) && limit < 50)
let range = getRange(start, findGridCell(endX, endY));
let range = getRange(start, findGridCell(endX, endY));
// get main ridge
function getRange(cur, end) {
@ -452,7 +452,7 @@
function getRange(cur, end) {
const range = [];
while (cur !== end) {
let min = Infinity;
cells.c[cur].forEach(function(e) {
@ -465,7 +465,7 @@
return range;
}
const step = .1 / width;
while (width > 0) {
@ -512,7 +512,7 @@
const max = range.split("-")[1]/100 || 100;
return rand(min * length, max * length);
}
return {generate, addHill, addRange, addTrough, addStrait, addPit, smooth, modify};
})));

View file

@ -45,8 +45,8 @@
const data = chains[base];
if (!data || data[" "] === undefined) {
tip("Namesbase " + base + " is incorrect. Please check in namesbase editor", false, "error");
console.error("Namebase " + base + " is incorrect!");
tip("Namesbase " + base + " is incorrect. Please check in namesbase editor", false, "error");
console.error("Namebase " + base + " is incorrect!");
return "ERROR";
}
@ -115,7 +115,7 @@
// generate short name for base
const getBaseShort = function(base) {
if (nameBases[base] === undefined) {
tip(`Namebase for culture ${pack.cultures[culture].name} does not exist.
tip(`Namebase for culture ${pack.cultures[culture].name} does not exist.
Please upload custom namebases of change the base in Cultures Editor`, false, "error");
base = 1;
}
@ -148,7 +148,7 @@
else if (P(.7)) name = name.slice(0,-1); // ~60% for cv
else return name;
} else if (P(.4)) return name; // 60% for cc and vc
// define suffix
let suffix = "ia"; // standard suffix
@ -202,7 +202,7 @@
if (suffix === "land" && name.length > 6) name = name.slice(0, -(name.length-5));
return validateSuffix(name, suffix);
}
const getNameBases = function() {
// name, min length, max length, letters to allow duplication, multi-word name rate
return [

View file

@ -87,7 +87,7 @@
chain.push(chain[0]); // push first vertex as the last one
return chain;
}
return OceanLayers;
})));

View file

@ -16,7 +16,7 @@
for (const i of cells.i) {
const height = cells.h[i];
if (height < 20) continue; // no icons on water
if (cells.r[i]) continue; // no icons on rivers
if (cells.r[i]) continue; // no icons on rivers
const b = cells.biome[i];
if (height < 50 && biomesData.iconsDensity[b] === 0) continue; // no icons for this biome
const polygon = getPackPolygon(i);
@ -42,7 +42,7 @@
function placeReliefIcons(i) {
const radius = 2 / density;
const [icon, h] = getReliefIcon(i, height);
for (const [cx, cy] of poissonDiscSampler(e[0], e[1], e[2], e[3], radius)) {
if (!d3.polygonContains(polygon, [cx, cy])) continue;
relief.push({i: icon, x: rn(cx-h, 2), y: rn(cy-h, 2), s: h*2});

View file

@ -5,9 +5,9 @@
}(this, (function () {'use strict';
// name generation approach and relative chance to be selected
const approach = {"Number":1, "Being":3, "Adjective":5, "Color + Animal":5,
"Adjective + Animal":5, "Adjective + Being":5, "Adjective + Genitive":1,
"Color + Being":3, "Color + Genitive":3, "Being + of + Genitive":2, "Being + of the + Genitive":1,
const approach = {"Number":1, "Being":3, "Adjective":5, "Color + Animal":5,
"Adjective + Animal":5, "Adjective + Being":5, "Adjective + Genitive":1,
"Color + Being":3, "Color + Genitive":3, "Being + of + Genitive":2, "Being + of the + Genitive":1,
"Animal + of + Genitive":1, "Adjective + Being + of + Genitive":2, "Adjective + Animal + of + Genitive":2};
// turn weighted array into simple array
@ -237,7 +237,7 @@
religions.filter(r => r.type === "Heresy").forEach(r => {
const b = cells.religion[r.center]; // "base" religion id
cells.religion[r.center] = r.i; // heresy id
queue.queue({e:r.center, p:0, r:r.i, b});
queue.queue({e:r.center, p:0, r:r.i, b});
cost[r.center] = 1;
});
@ -308,10 +308,10 @@
if (a === "Adjective + Being") return ra(base.adjective) + " " + ra(base.being);
if (a === "Adjective + Genitive") return ra(base.adjective) + " " + ra(base.genitive);
if (a === "Color + Being") return ra(base.color) + " " + ra(base.being);
if (a === "Color + Genitive") return ra(base.color) + " " + ra(base.genitive);
if (a === "Color + Genitive") return ra(base.color) + " " + ra(base.genitive);
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 === "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);
}

View file

@ -44,9 +44,9 @@
if (cells.r[i]) {
const to = [];
const min = Math.min(y, graphHeight - y, x, graphWidth - x);
if (min === y) {to[0] = x; to[1] = 0;} else
if (min === graphHeight - y) {to[0] = x; to[1] = graphHeight;} else
if (min === x) {to[0] = 0; to[1] = y;} else
if (min === y) {to[0] = x; to[1] = 0;} else
if (min === graphHeight - y) {to[0] = x; to[1] = graphHeight;} else
if (min === x) {to[0] = 0; to[1] = y;} else
if (min === graphWidth - x) {to[0] = graphWidth; to[1] = y;}
riversData.push({river: cells.r[i], cell: i, x: to[0], y: to[1]});
}
@ -59,14 +59,14 @@
// allow only one river can flow thought a lake
const cf = features[cells.f[i]]; // current cell feature
if (cf.river && cf.river !== cells.r[i]) {
cells.fl[i] = 0;
cells.fl[i] = 0;
}
if (cells.fl[i] < 30) {
if (h[min] >= 20) cells.fl[min] += cells.fl[i];
return; // flux is too small to operate as river
}
// Proclaim a new river
if (!cells.r[i]) {
cells.r[i] = riverNext;
@ -165,14 +165,14 @@
const addMeandring = function(segments, rndFactor = 0.3) {
const riverEnhanced = []; // to store enhanced segments
let side = 1; // to control meandring direction
for (let s = 0; s < segments.length; s++) {
const sX = segments[s].x, sY = segments[s].y; // segment start coordinates
const c = pack.cells.conf[segments[s].cell] || 0; // if segment is river confluence
riverEnhanced.push([sX, sY, c]);
if (s+1 === segments.length) break; // do not enhance last segment
const eX = segments[s+1].x, eY = segments[s+1].y; // segment end coordinates
const angle = Math.atan2(eY - sY, eX - sX);
const sin = Math.sin(angle), cos = Math.cos(angle);
@ -194,13 +194,13 @@
const p1y = (sY + eY) / 2 + side * cos * meandr;
riverEnhanced.push([p1x, p1y]);
}
}
return riverEnhanced;
}
const getPath = function(points, width = 1, increment = 1) {
let offset, extraOffset = .1; // starting river width (to make river source visible)
let offset, extraOffset = .1; // starting river width (to make river source visible)
const riverLength = points.reduce((s, v, i, p) => s + (i ? Math.hypot(v[0] - p[i-1][0], v[1] - p[i-1][1]) : 0), 0); // summ of segments length
const widening = rn((1000 + (riverLength * 30)) * increment);
const riverPointsLeft = [], riverPointsRight = []; // store points on both sides to build a valid polygon
@ -215,7 +215,7 @@
riverPointsLeft.push([xLeft, yLeft]);
let xRight = x + sin * extraOffset, yRight = y + -cos * extraOffset;
riverPointsRight.unshift([xRight, yRight]);
// middle points
for (let p = 1; p < last; p++) {
x = points[p][0], y = points[p][1], c = points[p][2] || 0;
@ -231,7 +231,7 @@
xRight = x + sin * offset, yRight = y + -cos * offset;
riverPointsRight.unshift([xRight, yRight]);
}
// end point
x = points[last][0], y = points[last][1], c = points[last][2];
if (c) extraOffset += Math.atan(c * 10 / widening); // add extra width on river confluence
@ -241,7 +241,7 @@
riverPointsLeft.push([xLeft, yLeft]);
xRight = x + sin * offset, yRight = y + -cos * offset;
riverPointsRight.unshift([xRight, yRight]);
// generate polygon path and return
lineGen.curve(d3.curveCatmullRom.alpha(0.1));
const right = lineGen(riverPointsRight);

View file

@ -115,7 +115,7 @@
// main routes
roads.selectAll("path").data(main).enter().append("path")
.attr("id", (d, i) => "road" + i)
.attr("id", (d, i) => "road" + i)
.attr("d", d => round(lineGen(d.map(c => {
const b = cells.burg[c];
const x = b ? burgs[b].x : cells.p[c][0];
@ -125,7 +125,7 @@
// small routes
trails.selectAll("path").data(small).enter().append("path")
.attr("id", (d, i) => "trail" + i)
.attr("id", (d, i) => "trail" + i)
.attr("d", d => round(lineGen(d.map(c => {
const b = cells.burg[c];
const x = b ? burgs[b].x : cells.p[c][0];
@ -136,7 +136,7 @@
// ocean routes
lineGen.curve(d3.curveBundle.beta(1));
searoutes.selectAll("path").data(ocean).enter().append("path")
.attr("id", (d, i) => "searoute" + i)
.attr("id", (d, i) => "searoute" + i)
.attr("d", d => round(lineGen(d.map(c => {
const b = cells.burg[c];
const x = b ? burgs[b].x : cells.p[c][0];

View file

@ -5,11 +5,11 @@
}(this, (function () {'use strict';
// set default options
const options = {scale: 50, lightness: .7, shadow: .5, sun: {x: 100, y: 600, z: 1000}, rotateMesh: 0, rotateGlobe: .5,
const options = {scale: 50, lightness: .7, shadow: .5, sun: {x: 100, y: 600, z: 1000}, rotateMesh: 0, rotateGlobe: .5,
skyColor: "#9ecef5", waterColor: "#53679f", extendedWater: 0, resolution: 2};
// set variables
let Renderer, scene, camera, controls, animationFrame, material, texture,
let Renderer, scene, camera, controls, animationFrame, material, texture,
geometry, mesh, ambientLight, spotLight, waterPlane, waterMaterial, waterMesh;
// initiate 3d scene
@ -157,7 +157,7 @@ async function newMesh(canvas) {
// controls
controls = await OrbitControls(camera, canvas);
controls.enableKeys = false;
controls.minDistance = 10;
controls.minDistance = 10;
controls.maxDistance = 1000;
controls.maxPolarAngle = Math.PI/2;
controls.autoRotate = Boolean(options.rotateMesh);

View file

@ -132,7 +132,7 @@ function editBiomes() {
const color = biomesData.color[biome];
biomes.select("#biome"+biome).transition().attr("stroke-width", .7).attr("stroke", color);
}
function biomeChangeColor(el) {
const currentFill = el.getAttribute("fill");
const biome = +el.parentNode.parentNode.dataset.id;
@ -145,7 +145,7 @@ function editBiomes() {
openPicker(currentFill, callback);
}
function biomeChangeName(el) {
const biome = +el.parentNode.dataset.id;
el.parentNode.dataset.name = el.value;
@ -200,12 +200,12 @@ function editBiomes() {
body.dataset.type = "percentage";
const totalCells = +biomesFooterCells.innerHTML;
const totalArea = +biomesFooterArea.dataset.area;
const totalPopulation = +biomesFooterPopulation.dataset.population;
const totalPopulation = +biomesFooterPopulation.dataset.population;
body.querySelectorAll(":scope> div").forEach(function(el) {
el.querySelector(".biomeCells").innerHTML = rn(+el.dataset.cells / totalCells * 100) + "%";
el.querySelector(".biomeArea").innerHTML = rn(+el.dataset.area / totalArea * 100) + "%";
el.querySelector(".biomePopulation").innerHTML = rn(+el.dataset.population / totalPopulation * 100) + "%";
el.querySelector(".biomePopulation").innerHTML = rn(+el.dataset.population / totalPopulation * 100) + "%";
});
} else {
body.dataset.type = "absolute";
@ -314,7 +314,7 @@ function editBiomes() {
const biome = assigned.size() ? +assigned.attr("data-biome") : pack.cells.biome[i];
body.querySelector("div.selected").classList.remove("selected");
body.querySelector("div[data-id='"+biome+"']").classList.add("selected");
body.querySelector("div[data-id='"+biome+"']").classList.add("selected");
}
function dragBiomeBrush() {
@ -324,7 +324,7 @@ function editBiomes() {
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) changeBiomeForSelection(selection);
@ -356,7 +356,7 @@ function editBiomes() {
const radius = +biomesManuallyBrush.value;
moveCircle(point[0], point[1], radius);
}
function applyBiomesChange() {
const changed = biomes.select("#temp").selectAll("polygon");
changed.each(function() {
@ -364,7 +364,7 @@ function editBiomes() {
const b = +this.dataset.biome;
pack.cells.biome[i] = b;
});
if (changed.size()) {
drawBiomes();
refreshBiomesEditor();
@ -390,7 +390,7 @@ function editBiomes() {
const selected = document.querySelector("#biomesBody > div.selected");
if (selected) selected.classList.remove("selected");
}
function restoreInitialBiomes() {
biomesData = applyDefaultBiomesSystem();
defineBiomes();

View file

@ -15,7 +15,7 @@ function editBurg(id) {
const of = id ? "svg" : d3.event.target;
$("#burgEditor").dialog({
title: "Edit Burg", resizable: false, close: closeBurgEditor,
title: "Edit Burg", resizable: false, close: closeBurgEditor,
position: {my, at, of, collision: "fit"}
});
@ -56,19 +56,19 @@ function editBurg(id) {
document.getElementById("burgEditAnchorStyle").style.display = +b.port ? "inline-block" : "none";
// toggle features
if (b.capital) document.getElementById("burgCapital").classList.remove("inactive");
if (b.capital) document.getElementById("burgCapital").classList.remove("inactive");
else document.getElementById("burgCapital").classList.add("inactive");
if (b.port) document.getElementById("burgPort").classList.remove("inactive");
if (b.port) document.getElementById("burgPort").classList.remove("inactive");
else document.getElementById("burgPort").classList.add("inactive");
if (b.citadel) document.getElementById("burgCitadel").classList.remove("inactive");
if (b.citadel) document.getElementById("burgCitadel").classList.remove("inactive");
else document.getElementById("burgCitadel").classList.add("inactive");
if (b.walls) document.getElementById("burgWalls").classList.remove("inactive");
if (b.walls) document.getElementById("burgWalls").classList.remove("inactive");
else document.getElementById("burgWalls").classList.add("inactive");
if (b.plaza) document.getElementById("burgPlaza").classList.remove("inactive");
if (b.plaza) document.getElementById("burgPlaza").classList.remove("inactive");
else document.getElementById("burgPlaza").classList.add("inactive");
if (b.temple) document.getElementById("burgTemple").classList.remove("inactive");
if (b.temple) document.getElementById("burgTemple").classList.remove("inactive");
else document.getElementById("burgTemple").classList.add("inactive");
if (b.shanty) document.getElementById("burgShanty").classList.remove("inactive");
if (b.shanty) document.getElementById("burgShanty").classList.remove("inactive");
else document.getElementById("burgShanty").classList.add("inactive");
// select group
@ -102,7 +102,7 @@ function editBurg(id) {
document.getElementById("burgGroupSection").style.display = "none";
document.getElementById("burgInputGroup").style.display = "none";
document.getElementById("burgInputGroup").value = "";
document.getElementById("burgSelectGroup").style.display = "inline-block";
document.getElementById("burgSelectGroup").style.display = "inline-block";
}
function changeGroup() {
@ -187,7 +187,7 @@ function editBurg(id) {
const burgsToRemove = burgsInGroup.filter(b => !pack.burgs[b].capital);
const capital = burgsToRemove.length < burgsInGroup.length;
alertMessage.innerHTML = `Are you sure you want to remove
alertMessage.innerHTML = `Are you sure you want to remove
${basic || capital ? "all elements in the group" : "the entire burg group"}?
<br>Please note that capital burgs will not be deleted.
<br><br>Burgs to be removed: ${burgsToRemove.length}`;
@ -243,7 +243,7 @@ function editBurg(id) {
const b = pack.burgs[id];
const feature = this.dataset.feature;
const turnOn = this.classList.contains("inactive");
if (feature === "port") togglePort(id);
if (feature === "port") togglePort(id);
else if(feature === "capital") toggleCapital(id);
else b[feature] = +turnOn;
if (b[feature]) this.classList.remove("inactive");
@ -284,7 +284,7 @@ function editBurg(id) {
const defSeed = seed + id.padStart(4, 0);
if (event.ctrlKey) {
const newSeed = prompt(`Please provide a Medieval Fantasy City Generator seed. `+
const newSeed = prompt(`Please provide a Medieval Fantasy City Generator seed. `+
`Seed should be a number. Default seed is FMG map seed + burg id padded to 4 chars with zeros (${defSeed}). `+
`Please note that if seed is custom, "Overworld" button from MFCG will open a different map`, burg.MFCG || defSeed);
if (newSeed) burg.MFCG = newSeed; else return;
@ -315,7 +315,7 @@ function editBurg(id) {
const defSeed = `${seed}-b${id}`;
if (event.ctrlKey) {
const newSeed = prompt(`Please provide an Iron Arachne Heraldry Generator seed. `+
const newSeed = prompt(`Please provide an Iron Arachne Heraldry Generator seed. `+
`Default seed is a combination of FMG map seed and burg id (${defSeed})`, burg.IAHG || defSeed);
if (newSeed) burg.IAHG = newSeed; else return;
}

View file

@ -344,8 +344,8 @@ function overviewBurgs() {
if (this.value === "provinces") return d.province;
}
const base = this.value === "states" ? getStatesData()
: this.value === "cultures" ? getCulturesData()
const base = this.value === "states" ? getStatesData()
: this.value === "cultures" ? getCulturesData()
: this.value === "parent" ? getParentData() : getProvincesData();
burgs.forEach(b => b.id = b.i+base.length-1);
@ -401,7 +401,7 @@ function overviewBurgs() {
}
function renameBurgsInBulk() {
const message = `Download burgs list as a text file, make changes and re-upload the file.
const message = `Download burgs list as a text file, make changes and re-upload the file.
If you do not want to change the name, just leave it as is`;
alertMessage.innerHTML = message;

View file

@ -82,7 +82,7 @@ function editCoastline(node = d3.event.target) {
document.getElementById("coastlineGroupsSelection").style.display = "none";
document.getElementById("coastlineGroupName").style.display = "none";
document.getElementById("coastlineGroupName").value = "";
document.getElementById("coastlineGroup").style.display = "inline-block";
document.getElementById("coastlineGroup").style.display = "inline-block";
}
function selectCoastlineGroup(node) {
@ -107,7 +107,7 @@ function editCoastline(node = d3.event.target) {
} else {
coastlineGroupName.style.display = "none";
coastlineGroup.style.display = "inline-block";
}
}
}
function createNewGroup() {
@ -146,7 +146,7 @@ function editCoastline(node = d3.event.target) {
toggleNewGroupInput();
document.getElementById("coastlineGroupName").value = "";
}
function removeCoastlineGroup() {
const group = elSelected.node().parentNode.id;
if (["sea_island", "lake_island"].includes(group)) {
@ -155,7 +155,7 @@ function editCoastline(node = d3.event.target) {
}
const count = elSelected.node().parentNode.childElementCount;
alertMessage.innerHTML = `Are you sure you want to remove the group?
alertMessage.innerHTML = `Are you sure you want to remove the group?
All coastline elements of the group (${count}) will be moved under <i>sea_island</i> group`;
$("#alert").dialog({resizable: false, title: "Remove coastline group", width:"26em",
buttons: {

View file

@ -142,13 +142,13 @@ function editCultures() {
types.forEach(t => options += `<option ${type === t ? "selected" : ""} value="${t}">${t}</option>`);
return options;
}
function getBaseOptions(base) {
let options = "";
nameBases.forEach((n, i) => options += `<option ${base === i ? "selected" : ""} value="${i}">${n.name}</option>`);
return options;
}
function cultureHighlightOn(event) {
const culture = +event.target.dataset.id;
const info = document.getElementById("cultureInfo");
@ -420,7 +420,7 @@ function editCultures() {
}
$("#alert").dialog({
title: "Cultures tree", width: fitContent(), resizable: false,
title: "Cultures tree", width: fitContent(), resizable: false,
position: {my: "left center", at: "left+10 center", of: "svg"}, buttons: {},
close: () => {alertMessage.innerHTML = "";}
});
@ -471,7 +471,7 @@ function editCultures() {
pack.burgs.forEach(b => b.culture = pack.cells.culture[b.cell]);
refreshCulturesEditor();
}
function enterCultureManualAssignent() {
if (!layerIsOn("toggleCultures")) toggleCultures();
customization = 4;
@ -521,7 +521,7 @@ function editCultures() {
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) changeCultureForSelection(selection);
@ -589,7 +589,7 @@ function editCultures() {
const selected = body.querySelector("div.selected");
if (selected) selected.classList.remove("selected");
}
function enterAddCulturesMode() {
if (this.classList.contains("pressed")) {exitAddCultureMode(); return;};
customization = 9;
@ -624,7 +624,7 @@ function editCultures() {
function downloadCulturesData() {
const unit = areaUnit.value === "square" ? distanceUnitInput.value + "2" : areaUnit.value;
let data = "Id,Culture,Color,Cells,Expansionism,Type,Area "+unit+",Population,Namesbase\n"; // headers
body.querySelectorAll(":scope > div").forEach(function(el) {
data += el.dataset.id + ",";
data += el.dataset.name + ",";

File diff suppressed because one or more lines are too long

View file

@ -7,7 +7,7 @@
var Voronoi = function Voronoi(delaunay, points, pointsN) {
const cells = {v: [], c: [], b: []}; // voronoi cells: v = cell vertices, c = adjacent cells, b = near-border cell
const vertices = {p: [], v: [], c: []}; // cells vertices: p = vertex coordinates, v = neighboring vertices, c = adjacent cells
for (let e=0; e < delaunay.triangles.length; e++) {
const p = delaunay.triangles[nextHalfedge(e)];
@ -25,11 +25,11 @@
vertices.c[t] = pointsOfTriangle(t); // vertex: adjacent cells
}
}
function pointsOfTriangle(t) {
return edgesOfTriangle(t).map(e => delaunay.triangles[e]);
}
}
function trianglesAdjacentToTriangle(t) {
let triangles = [];
for (let e of edgesOfTriangle(t)) {
@ -53,11 +53,11 @@
let vertices = pointsOfTriangle(t).map(p => points[p]);
return circumcenter(vertices[0], vertices[1], vertices[2]);
}
return {cells, vertices}
}
function edgesOfTriangle(t) {return [3*t, 3*t+1, 3*t+2];}
function triangleOfEdge(e) {return Math.floor(e/3);}