From 0ced1d7cd7de9066d21ecb9e2108e8a8916885f3 Mon Sep 17 00:00:00 2001
From: thepaperpilot <thepaperpilot@gmail.com>
Date: Fri, 20 Aug 2021 22:07:34 -0500
Subject: [PATCH] Added update() method to nodes

---
 src/game/gameLoop.ts            | 8 ++++++++
 src/typings/features/board.d.ts | 6 ++++--
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/src/game/gameLoop.ts b/src/game/gameLoop.ts
index f197526..3016185 100644
--- a/src/game/gameLoop.ts
+++ b/src/game/gameLoop.ts
@@ -68,6 +68,14 @@ function updateLayers(diff: DecimalSource) {
             );
         }
         layers[layer].update?.(diff);
+        if (layers[layer].boards) {
+            Reflect.ownKeys(player.layers[layer].boards).forEach(board => {
+                player.layers[layer].boards[board.toString()].forEach(node => {
+                    const nodeType = layers[layer].boards!.data[board.toString()].types[node.type];
+                    nodeType.update?.(node, diff);
+                });
+            });
+        }
     });
     // Automate each active layer
     activeLayers.forEach(layer => {
diff --git a/src/typings/features/board.d.ts b/src/typings/features/board.d.ts
index 6346516..bea8579 100644
--- a/src/typings/features/board.d.ts
+++ b/src/typings/features/board.d.ts
@@ -1,3 +1,4 @@
+import { DecimalSource } from "@/lib/break_eternity";
 import { State } from "../state";
 import { Feature, RawFeature } from "./feature";
 
@@ -41,7 +42,8 @@ export interface NodeType extends Feature {
     fillColor?: string | ((node: BoardNode) => string);
     outlineColor?: string | ((node: BoardNode) => string);
     titleColor?: string | ((node: BoardNode) => string);
-    onClick: (node: BoardNode) => void;
-    onDrop: (node: BoardNode, otherNode: BoardNode) => void;
+    onClick?: (node: BoardNode) => void;
+    onDrop?: (node: BoardNode, otherNode: BoardNode) => void;
+    update?: (node: BoardNode, diff: DecimalSource) => void;
     nodes: BoardNode[];
 }