mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-21 19:41:23 +01:00
Address the problem of potential data loss
Any errors while iterating the states or burgs could potentially lose the index 0 metadata stored in the arrays. This will instead track the index and ignore the 0th result.
This commit is contained in:
parent
f1141d6baf
commit
ce3a37a421
1 changed files with 10 additions and 9 deletions
|
|
@ -357,24 +357,25 @@
|
|||
// cell or center cell's (respectively) culture.
|
||||
const resetCultures = function () {
|
||||
console.time('resetCulturesForBurgsAndStates');
|
||||
// Pull out index 0 nodes so iterators don't touch them.
|
||||
const burgTreeNode = pack.burgs.shift();
|
||||
const neutralsStateNode = pack.states.shift();
|
||||
|
||||
// Assign the culture associated with the burgs cell.
|
||||
pack.burgs = pack.burgs.map( (burg) => {
|
||||
pack.burgs = pack.burgs.map( (burg, index) => {
|
||||
// Ignore metadata burg
|
||||
if(index === 0) {
|
||||
return burg;
|
||||
}
|
||||
return {...burg, culture: pack.cells.culture[burg.cell]};
|
||||
});
|
||||
|
||||
// Assign the culture associated with the states' center cell.
|
||||
pack.states = pack.states.map( (state) => {
|
||||
pack.states = pack.states.map( (state, index) => {
|
||||
// Ignore neutrals state
|
||||
if(index === 0) {
|
||||
return state;
|
||||
}
|
||||
return {...state, culture: pack.cells.culture[state.center]};
|
||||
});
|
||||
|
||||
// Prepend the index 0 nodes back onto the packgroups.
|
||||
pack.burgs.unshift(burgTreeNode);
|
||||
pack.states.unshift(neutralsStateNode);
|
||||
|
||||
console.timeEnd('resetCulturesForBurgsAndStates');
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue