diff options
author | sanine <sanine.not@pm.me> | 2023-11-06 02:39:12 -0600 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2023-11-06 02:39:12 -0600 |
commit | 3ae8f476f3865982ca69d0e39b05b5aa8ec43694 (patch) | |
tree | a0b29760544c25db62bd82fcb1bb42a6412a6eae | |
parent | 2e2d9c400335b677297a68883b94bb98526b45ac (diff) |
improve cell.js comments
-rw-r--r-- | src/world/cell.js | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/src/world/cell.js b/src/world/cell.js index 6e013c6..8795623 100644 --- a/src/world/cell.js +++ b/src/world/cell.js @@ -1,5 +1,6 @@ 'use strict'; +// get the proposals for cell updates export function cells_update(cells, update_rules) { return cells .map((row, y) => row.map((cell, x) => [x, y, cell.type])) @@ -9,6 +10,7 @@ export function cells_update(cells, update_rules) { } +// check if, given the current cells configuration, a proposal is valid export function cells_valid(cells, proposal) { if (!proposal.world_updates) { return true; } return proposal.world_updates.reduce( @@ -24,6 +26,7 @@ export function cells_valid(cells, proposal) { } +// apply a set of proposals, returning the new cells export function cells_apply(cells, proposals) { return proposals.reduce( (acc, prop) => { @@ -33,6 +36,7 @@ export function cells_apply(cells, proposals) { 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]; } |