summaryrefslogtreecommitdiff
path: root/src/world/lattice.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/world/lattice.js')
-rw-r--r--src/world/lattice.js16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/world/lattice.js b/src/world/lattice.js
index 243a47d..066a5ca 100644
--- a/src/world/lattice.js
+++ b/src/world/lattice.js
@@ -28,18 +28,19 @@ export function lattice_valid(lattice, proposal) {
// apply a set of proposals, returning the new lattice
export function lattice_apply(lattice, proposals) {
- return proposals.reduce(
+ const result = proposals.reduce(
(acc, prop) => {
const change = (prop.world_updates || []).reduce(
(acc_, update) => {
const cell = acc_[update.y][update.x];
if (update.to) { cell.type = update.to; }
if (update.flags) {
- cell.flags = cell.flags || {}
- // this is very side-effect-y but i couldn't think of a nicer compatible way of doing it 😔
- for (let k of Object.keys(update.flags)) {
- cell.flags[k] = update.flags[k];
- }
+ cell.flags = { ...(cell.flags || {}), ...update.flags };
+ //cell.flags = cell.flags || {}
+ //// this is very side-effect-y but i couldn't think of a nicer compatible way of doing it 😔
+ //for (let k of Object.keys(update.flags)) {
+ // cell.flags[k] = update.flags[k];
+ //}
}
return acc_
},
@@ -47,6 +48,7 @@ export function lattice_apply(lattice, proposals) {
);
return change;
},
- [...lattice].map(row => row.map(cell => ({ ...cell, flags: {}, })))
+ [...lattice]
);
+ return result;
}