From 1ee8d2a41c5d5dcb711f7aae697a201831d186f4 Mon Sep 17 00:00:00 2001 From: thepaperpilot Date: Wed, 25 Aug 2021 08:41:49 -0500 Subject: [PATCH] Fixed issue with registering things out of order --- src/data/layers/main.ts | 94 ++++++++++++++++++++--------------------- 1 file changed, 47 insertions(+), 47 deletions(-) diff --git a/src/data/layers/main.ts b/src/data/layers/main.ts index 29d4506..269a4e4 100644 --- a/src/data/layers/main.ts +++ b/src/data/layers/main.ts @@ -28,6 +28,53 @@ export type ActionNodeData = { log: LogEntry[]; }; +type Resource = { + readonly name: string; + readonly color: string; + readonly node: BoardNode | undefined; + amount: DecimalSource | undefined; + readonly maxAmount: DecimalSource; +}; + +const resources = { + time: createResource("time", "#3EB48933", 24 * 60 * 60), + energy: createResource("energy", "#FFA50033", 100), + social: createResource("social", "#80008033", 100), + mental: createResource("mental", "#32CD3233", 100), + focus: createResource("focus", "#0000FF33", 100) +} as Record; + +function createResource(name: string, color: string, maxAmount: DecimalSource): Resource { + const node = computed(() => + player.layers.main?.boards.main.nodes.find( + node => + node.type === "resource" && (node.data as ResourceNodeData).resourceType === name + ) + ); + const data = computed(() => node.value?.data as ResourceNodeData); + return { + name, + color, + get node() { + return node.value; + }, + get amount() { + return data.value?.amount; + }, + set amount(amount: DecimalSource) { + data.value.amount = Decimal.clamp(amount, 0, maxAmount); + }, + maxAmount + }; +} + +function getResource(node: BoardNode): Resource | undefined { + return Object.values(resources).find(resource => resource.node === node); +} + +const selectedNode = computed(() => layers.main?.boards?.data.main.selectedNode); +const selectedAction = computed(() => layers.main?.boards?.data.main.selectedAction); + export type LogEntry = { description: string; effectDescription?: string; @@ -148,53 +195,6 @@ const pinAction = { } } as BoardNodeAction; -type Resource = { - readonly name: string; - readonly color: string; - readonly node: BoardNode | undefined; - amount: DecimalSource | undefined; - readonly maxAmount: DecimalSource; -}; - -const resources = { - time: createResource("time", "#3EB48933", 24 * 60 * 60), - energy: createResource("energy", "#FFA50033", 100), - social: createResource("social", "#80008033", 100), - mental: createResource("mental", "#32CD3233", 100), - focus: createResource("focus", "#0000FF33", 100) -} as Record; - -function createResource(name: string, color: string, maxAmount: DecimalSource): Resource { - const node = computed(() => - player.layers.main?.boards.main.nodes.find( - node => - node.type === "resource" && (node.data as ResourceNodeData).resourceType === name - ) - ); - const data = computed(() => node.value?.data as ResourceNodeData); - return { - name, - color, - get node() { - return node.value; - }, - get amount() { - return data.value?.amount; - }, - set amount(amount: DecimalSource) { - data.value.amount = Decimal.clamp(amount, 0, maxAmount); - }, - maxAmount - }; -} - -function getResource(node: BoardNode): Resource | undefined { - return Object.values(resources).find(resource => resource.node === node); -} - -const selectedNode = computed(() => layers.main?.boards?.data.main.selectedNode); -const selectedAction = computed(() => layers.main?.boards?.data.main.selectedAction); - export default { id: "main", display: Main,