diff --git a/main.js b/main.js index f0ba76b3..514c0939 100644 --- a/main.js +++ b/main.js @@ -323,10 +323,12 @@ function applyDefaultBiomesSystem() { ]; // parse icons weighted array into a simple array - for (let i=0; i < icons.length; i++) { + var iconsNum = icons.length; + for (let i=0; i < iconsNum; i++) { const parsed = []; for (const icon in icons[i]) { - for (let j = 0; j < icons[i][icon]; j++) {parsed.push(icon);} + var iconVal = icons[i][icon]; + for (let j = 0; j < iconVal; j++) {parsed.push(icon);} } icons[i] = parsed; } @@ -763,7 +765,8 @@ function calculateTemperatures() { const y = grid.points[r][1]; const lat = Math.abs(mapCoordinates.latN - y / graphHeight * mapCoordinates.latT); // [0; 90] const initTemp = tEq - int(lat / 90) * tDelta; - for (let i = r; i < r+grid.cellsX; i++) { + let rPlusCellsX = r+grid.cellsX; + for (let i = r; i < rPlusCellsX; i++) { cells.temp[i] = Math.max(Math.min(initTemp - convertToFriendly(cells.h[i]), 127), -128); } }); @@ -1030,8 +1033,8 @@ function drawCoastline() { // move vertices that are too close to already added ones function relax(vchain, r) { const p = vertices.p, tree = d3.quadtree(); - - for (let i=0; i < vchain.length; i++) { + var vchainLength = vchain.length; + for (let i=0; i < vchainLength; i++) { const v = vchain[i]; let [x, y] = [p[v][0], p[v][1]]; if (i && vchain[i+1] && tree.find(x, y, r) !== undefined) { @@ -1302,7 +1305,8 @@ function addMarkers(number = 1) { const animal = ["Antelope", "Ape", "Badger", "Bear", "Beaver", "Bison", "Boar", "Buffalo", "Cat", "Crane", "Crocodile", "Crow", "Deer", "Dog", "Eagle", "Elk", "Fox", "Goat", "Goose", "Hare", "Hawk", "Heron", "Horse", "Hyena", "Ibis", "Jackal", "Jaguar", "Lark", "Leopard", "Lion", "Mantis", "Marten", "Moose", "Mule", "Narwhal", "Owl", "Panther", "Rat", "Raven", "Rook", "Scorpion", "Shark", "Sheep", "Snake", "Spider", "Swan", "Tiger", "Turtle", "Wolf", "Wolverine", "Camel", "Falcon", "Hound", "Ox"]; const adj = ["New", "Good", "High", "Old", "Great", "Big", "Major", "Happy", "Main", "Huge", "Far", "Beautiful", "Fair", "Prime", "Ancient", "Golden", "Proud", "Lucky", "Fat", "Honest", "Giant", "Distant", "Friendly", "Loud", "Hungry", "Magical", "Superior", "Peaceful", "Frozen", "Divine", "Favorable", "Brave", "Sunny", "Flying"]; - for (let i=0; i < taverns.length && i < count; i++) { + let numberOfTaverns = taverns.length; + for (let i=0; i < numberOfTaverns && i < count; i++) { const cell = taverns.splice(Math.floor(Math.random() * taverns.length), 1); const id = appendMarker(cell, "inn"); const type = P(.3) ? "inn" : "tavern"; @@ -1317,7 +1321,8 @@ function addMarkers(number = 1) { if (lighthouses.length) addMarker("lighthouse", "🚨", 50, 50, 16); const count = Math.ceil(4 * number); - for (let i=0; i < lighthouses.length && i < count; i++) { + let numberOfLighthouses = lighthouses.length; + for (let i=0; i < numberOfLighthouses && i < count; i++) { const cell = lighthouses[i][0], vertex = lighthouses[i][1]; const id = appendMarker(cell, "lighthouse"); const proper = cells.burg[cell] ? pack.burgs[cells.burg[cell]].name : Names.getCulture(cells.culture[cell]); @@ -1330,7 +1335,8 @@ function addMarkers(number = 1) { if (waterfalls.length) addMarker("waterfall", "⟱", 50, 54, 16.5); const count = Math.ceil(3 * number); - for (let i=0; i < waterfalls.length && i < count; i++) { + let numberOfWaterfalls = waterfalls.length; + for (let i=0; i < numberOfWaterfalls && i < count; i++) { const cell = waterfalls[i]; const id = appendMarker(cell, "waterfall"); const proper = cells.burg[cell] ? pack.burgs[cells.burg[cell]].name : Names.getCulture(cells.culture[cell]); diff --git a/modules/burgs-and-states.js b/modules/burgs-and-states.js index abe8e1c7..a0420c58 100644 --- a/modules/burgs-and-states.js +++ b/modules/burgs-and-states.js @@ -112,7 +112,8 @@ let spacing = (graphWidth + graphHeight) / 150 / (burgsNumber ** .7 / 66); // min distance between towns while (burgsAdded < burgsNumber && spacing > 1) { - for (let i=0; burgsAdded < burgsNumber && i < sorted.length; i++) { + let sortedArrayLength = sorted.length; + for (let i=0; burgsAdded < burgsNumber && i < sortedArrayLength; i++) { if (cells.burg[sorted[i]]) continue; const cell = sorted[i], x = cells.p[cell][0], y = cells.p[cell][1]; const s = spacing * gauss(1, .3, .2, 2, 2); // randomize to make placement not uniform @@ -656,18 +657,19 @@ const areaMean = d3.mean(valid.map(s => s.area)); // avarage state area // generic relations - for (let f=1; f < states.length; f++) { + let numberOfStates = states.length; + for (let f=1; f < numberOfStates; f++) { if (states[f].removed) continue; if (states[f].diplomacy.includes("Vassal")) { // Vassals copy relations from their Suzerains const suzerain = states[f].diplomacy.indexOf("Vassal"); - for (let i=1; i < states.length; i++) { + for (let i=1; i < numberOfStates; i++) { if (i === f || i === suzerain) continue; states[f].diplomacy[i] = states[suzerain].diplomacy[i]; if (states[suzerain].diplomacy[i] === "Suzerain") states[f].diplomacy[i] = "Ally"; - for (let e=1; e < states.length; e++) { + for (let e=1; e < numberOfStates; e++) { if (e === f || e === suzerain) continue; if (states[e].diplomacy[suzerain] === "Suzerain" || states[e].diplomacy[suzerain] === "Vassal") continue; states[e].diplomacy[f] = states[e].diplomacy[suzerain]; @@ -676,7 +678,7 @@ continue; } - for (let t=f+1; t < states.length; t++) { + for (let t=f+1; t < numberOfStates; t++) { if (states[t].removed) continue; if (states[t].diplomacy.includes("Vassal")) { @@ -699,7 +701,7 @@ } // declare wars - for (let attacker=1; attacker < states.length; attacker++) { + for (let attacker=1; attacker < numberOfStates; attacker++) { const ad = states[attacker].diplomacy; // attacker relations; if (states[attacker].removed) continue; if (!ad.includes("Rival")) continue; // no rivals to attack diff --git a/modules/cultures-generator.js b/modules/cultures-generator.js index 67763f7e..040cdd27 100644 --- a/modules/cultures-generator.js +++ b/modules/cultures-generator.js @@ -115,7 +115,8 @@ function getCode(name) { const words = name.split(" "), letters = words.join(""); let code = words.length === 2 ? words[0][0]+words[1][0] : letters.slice(0,2); - for (let i=1; i < letters.length-1 && pack.cultures.some(c => c.code === code); i++) { + let numberOfLetters = letters.length; + for (let i=1; i < numberOfLetters-1 && pack.cultures.some(c => c.code === code); i++) { code = letters[0] + letters[i].toUpperCase(); } return code; diff --git a/modules/names-generator.js b/modules/names-generator.js index 32367be1..93375437 100644 --- a/modules/names-generator.js +++ b/modules/names-generator.js @@ -15,7 +15,8 @@ const basic = !(/[^\u0000-\u007f]/.test(name)); // basic chars and English rules can be applied // split word into pseudo-syllables - for (let i=-1, syllable = ""; i < name.length; i += (syllable.length||1), syllable = "") { + let nameLength = name.length; + for (let i=-1, syllable = ""; i < nameLength; i += (syllable.length||1), syllable = "") { let prev = name[i] || ""; // pre-onset letter let v = 0; // 0 if no vowels in syllable diff --git a/modules/ocean-layers.js b/modules/ocean-layers.js index 50f4849c..7a230d05 100644 --- a/modules/ocean-layers.js +++ b/modules/ocean-layers.js @@ -66,7 +66,8 @@ // Define grid ocean cells type based on distance form land function markupOcean(limits) { - for (let t = -2; t >= limits[0]-1; t--) { + let limits0 = limits[0]; + for (let t = -2; t >= limits0-1; t--) { for (let i = 0; i < pointsN; i++) { if (cells.t[i] !== t+1) continue; cells.c[i].forEach(function(e) {if (!cells.t[e]) cells.t[e] = t;}); diff --git a/modules/religions-generator.js b/modules/religions-generator.js index ee22e38e..e92757b3 100644 --- a/modules/religions-generator.js +++ b/modules/religions-generator.js @@ -13,7 +13,8 @@ // turn weighted array into simple array const approaches = []; for (const a in approach) { - for (let j=0; j < approach[a]; j++) { + let approachA = approach[a]; + for (let j=0; j < approachA; j++) { approaches.push(a); } } @@ -295,7 +296,8 @@ const name = rawName.replace("Old ", ""); // remove Old prefix const words = name.split(" "), letters = words.join(""); let code = words.length === 2 ? words[0][0]+words[1][0] : letters.slice(0,2); - for (let i=1; i < letters.length-1 && pack.religions.some(r => r.code === code); i++) { + let numberOfLetters = letters.length; + for (let i=1; i < numberOfLetters-1 && pack.religions.some(r => r.code === code); i++) { code = letters[0] + letters[i].toUpperCase(); } return code; diff --git a/modules/river-generator.js b/modules/river-generator.js index db799885..cc44610a 100644 --- a/modules/river-generator.js +++ b/modules/river-generator.js @@ -167,7 +167,8 @@ const riverEnhanced = []; // to store enhanced segments let side = 1; // to control meandring direction - for (let s = 0; s < segments.length; s++) { + let numberOfSegments = segments.length; + for (let s = 0; s < numberOfSegments; 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]); diff --git a/modules/routes-generator.js b/modules/routes-generator.js index 2e6d0159..74ce9b3d 100644 --- a/modules/routes-generator.js +++ b/modules/routes-generator.js @@ -70,13 +70,14 @@ bodies.forEach(function(f) { const ports = allPorts.filter(b => b.port === f); // all ports on the same feature - if (ports.length < 2) return; + let numberOfPorts = ports.length; + if (numberOfPorts < 2) return; - for (let s=0; s < ports.length; s++) { + for (let s=0; s < numberOfPorts; s++) { const source = ports[s].cell; if (connected[source]) continue; - for (let t=s+1; t < ports.length; t++) { + for (let t=s+1; t < numberOfPorts; t++) { const target = ports[t].cell; if (connected[target]) continue; diff --git a/modules/save-and-load.js b/modules/save-and-load.js index 76f48efd..97b1660d 100644 --- a/modules/save-and-load.js +++ b/modules/save-and-load.js @@ -138,7 +138,8 @@ function inlineStyle(clone) { const compStyle = window.getComputedStyle(this); let style = ""; - for (let i=0; i < compStyle.length; i++) { + let compStyleLength = compStyle.length; + for (let i=0; i < compStyleLength; i++) { const key = compStyle[i]; const value = compStyle.getPropertyValue(key); @@ -602,7 +603,8 @@ function parseLoadedData(data) { biomesData.name = biomes[2].split(","); // push custom biomes if any - for (let i=biomesData.i.length; i < biomesData.name.length; i++) { + let biomeNamesLength = biomesData.name.length; + for (let i=biomesData.i.length; i < biomeNamesLength; i++) { biomesData.i.push(biomesData.i.length); biomesData.iconsDensity.push(0); biomesData.icons.push([]); diff --git a/modules/ui/burg-editor.js b/modules/ui/burg-editor.js index 0691fa3e..03f074a7 100644 --- a/modules/ui/burg-editor.js +++ b/modules/ui/burg-editor.js @@ -181,7 +181,8 @@ function editBurg(id) { const basic = group.id === "cities" || group.id === "towns"; const burgsInGroup = []; - for (let i=0; i < group.children.length; i++) { + let numberOfChildren = group.children.length; + for (let i=0; i < numberOfChildren; i++) { burgsInGroup.push(+group.children[i].dataset.id); } const burgsToRemove = burgsInGroup.filter(b => !pack.burgs[b].capital); diff --git a/modules/ui/burgs-overview.js b/modules/ui/burgs-overview.js index 35d668a6..13f1625e 100644 --- a/modules/ui/burgs-overview.js +++ b/modules/ui/burgs-overview.js @@ -422,12 +422,14 @@ function overviewBurgs() { function importBurgNames(dataLoaded) { if (!dataLoaded) {tip("Cannot load the file, please check the format", false, "error"); return;} const data = dataLoaded.split("\r\n"); - if (!data.length) {tip("Cannot parse the list, please check the file format", false, "error"); return;} + let dataLength = data.length; + let numberOfBurgs = burgs.length; + if (!dataLength) {tip("Cannot parse the list, please check the file format", false, "error"); return;} let change = [], message = `Burgs will be renamed as below. Please confirm`; message += `
| Id | Current name | New Name |
|---|