From 3ae8f476f3865982ca69d0e39b05b5aa8ec43694 Mon Sep 17 00:00:00 2001 From: sanine Date: Mon, 6 Nov 2023 02:39:12 -0600 Subject: improve cell.js comments --- src/world/cell.js | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') 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]; } -- cgit v1.2.1