From f7b0ed22b2fd0ddafc4a84dde1ad8e3208144844 Mon Sep 17 00:00:00 2001 From: sanine Date: Sat, 11 Nov 2023 15:04:36 -0600 Subject: gol changes make sound --- src/world/lattice.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'src/world/lattice.js') 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; } -- cgit v1.2.1