From d1cdfd2c9cb465532d63e9925be9c601f878ca25 Mon Sep 17 00:00:00 2001 From: thepaperpilot Date: Sat, 5 Mar 2022 16:42:55 -0600 Subject: [PATCH] Fixed layer tree node options --- src/data/common.tsx | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/src/data/common.tsx b/src/data/common.tsx index af85316..9ab32f5 100644 --- a/src/data/common.tsx +++ b/src/data/common.tsx @@ -18,6 +18,7 @@ import player from "game/player"; import Decimal from "util/bignum"; import { Computable, + GetComputableType, GetComputableTypeWithDefault, processComputable, ProcessedComputable @@ -118,39 +119,48 @@ export function createResetButton; // marking as required + display?: Computable; + append?: Computable; } export type LayerTreeNode = Replace< TreeNode, { - append: ProcessedComputable; + display: GetComputableTypeWithDefault; + append: GetComputableType; + } +>; +export type GenericLayerTreeNode = Replace< + LayerTreeNode, + { + display: ProcessedComputable; + append?: ProcessedComputable; } >; -export type GenericLayerTreeNode = LayerTreeNode; export function createLayerTreeNode( optionsFunc: () => T ): LayerTreeNode { return createTreeNode(() => { const options = optionsFunc(); + processComputable(options as T, "display"); + setDefault(options, "display", options.layerID); processComputable(options as T, "append"); return { ...options, display: options.layerID, - onClick: - options.append != null && options.append - ? function () { - if (player.tabs.includes(options.layerID)) { - const index = player.tabs.lastIndexOf(options.layerID); - player.tabs.splice(index, 1); - } else { - player.tabs.push(options.layerID); - } - } - : function () { - player.tabs.splice(1, 1, options.layerID); + onClick: unref((options as unknown as GenericLayerTreeNode).append) + ? function () { + if (player.tabs.includes(options.layerID)) { + const index = player.tabs.lastIndexOf(options.layerID); + player.tabs.splice(index, 1); + } else { + player.tabs.push(options.layerID); } + } + : function () { + player.tabs.splice(1, 1, options.layerID); + } }; }) as unknown as LayerTreeNode; }