Skip to content

Commit

Permalink
refactor(#902): locked states cells to be assigned on start
Browse files Browse the repository at this point in the history
  • Loading branch information
Azgaar committed Dec 15, 2022
1 parent e984c70 commit aa29f69
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion modules/burgs-and-states.js
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ window.BurgsAndStates = (function () {
TIME && console.time("expandStates");
const {cells, states, cultures, burgs} = pack;

cells.state = new Uint16Array(cells.i.length);
cells.state = cells.state || new Uint16Array(cells.i.length);
const queue = new PriorityQueue({comparator: (a, b) => a.p - b.p});
const cost = [];
const neutral = (cells.i.length / 5000) * 2500 * neutralInput.value * statesNeutral; // limit cost for state growth
Expand Down
12 changes: 7 additions & 5 deletions modules/ui/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,18 +238,20 @@ function recreateStates() {
// pack.provinces[id].should_restore = true;
});

for (const i of pack.cells.i) {
const stateId = pack.cells.state[i];
if (stateId === s.i) pack.cells.state[i] = newId;
}

const {x, y} = validBurgs[s.capital];
capitalsTree.add([x, y]);

s.i = newId;
newStates.push(s);
});

for (const i of pack.cells.i) {
const stateId = pack.cells.state[i];
const lockedStateIndex = lockedStatesIds.indexOf(stateId) + 1;
// lockedStateIndex is an index of locked state of 0 if state is not locked
pack.cells.state[i] = lockedStateIndex;
}

for (let i = newStates.length; i < count; i++) {
let capital = null;

Expand Down

0 comments on commit aa29f69

Please sign in to comment.