summaryrefslogtreecommitdiff
path: root/src/world
diff options
context:
space:
mode:
Diffstat (limited to 'src/world')
-rw-r--r--src/world/cell.js4
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];
}