Fixed layer tree node options
This commit is contained in:
parent
79dd822b3a
commit
d1cdfd2c9c
1 changed files with 26 additions and 16 deletions
|
@ -18,6 +18,7 @@ import player from "game/player";
|
||||||
import Decimal from "util/bignum";
|
import Decimal from "util/bignum";
|
||||||
import {
|
import {
|
||||||
Computable,
|
Computable,
|
||||||
|
GetComputableType,
|
||||||
GetComputableTypeWithDefault,
|
GetComputableTypeWithDefault,
|
||||||
processComputable,
|
processComputable,
|
||||||
ProcessedComputable
|
ProcessedComputable
|
||||||
|
@ -118,39 +119,48 @@ export function createResetButton<T extends ClickableOptions & ResetButtonOption
|
||||||
|
|
||||||
export interface LayerTreeNodeOptions extends TreeNodeOptions {
|
export interface LayerTreeNodeOptions extends TreeNodeOptions {
|
||||||
layerID: string;
|
layerID: string;
|
||||||
color: string;
|
color: Computable<string>; // marking as required
|
||||||
append?: boolean;
|
display?: Computable<string>;
|
||||||
|
append?: Computable<boolean>;
|
||||||
}
|
}
|
||||||
export type LayerTreeNode<T extends LayerTreeNodeOptions> = Replace<
|
export type LayerTreeNode<T extends LayerTreeNodeOptions> = Replace<
|
||||||
TreeNode<T>,
|
TreeNode<T>,
|
||||||
{
|
{
|
||||||
append: ProcessedComputable<boolean>;
|
display: GetComputableTypeWithDefault<T["display"], T["layerID"]>;
|
||||||
|
append: GetComputableType<T["append"]>;
|
||||||
|
}
|
||||||
|
>;
|
||||||
|
export type GenericLayerTreeNode = Replace<
|
||||||
|
LayerTreeNode<LayerTreeNodeOptions>,
|
||||||
|
{
|
||||||
|
display: ProcessedComputable<string>;
|
||||||
|
append?: ProcessedComputable<boolean>;
|
||||||
}
|
}
|
||||||
>;
|
>;
|
||||||
export type GenericLayerTreeNode = LayerTreeNode<LayerTreeNodeOptions>;
|
|
||||||
|
|
||||||
export function createLayerTreeNode<T extends LayerTreeNodeOptions>(
|
export function createLayerTreeNode<T extends LayerTreeNodeOptions>(
|
||||||
optionsFunc: () => T
|
optionsFunc: () => T
|
||||||
): LayerTreeNode<T> {
|
): LayerTreeNode<T> {
|
||||||
return createTreeNode(() => {
|
return createTreeNode(() => {
|
||||||
const options = optionsFunc();
|
const options = optionsFunc();
|
||||||
|
processComputable(options as T, "display");
|
||||||
|
setDefault(options, "display", options.layerID);
|
||||||
processComputable(options as T, "append");
|
processComputable(options as T, "append");
|
||||||
return {
|
return {
|
||||||
...options,
|
...options,
|
||||||
display: options.layerID,
|
display: options.layerID,
|
||||||
onClick:
|
onClick: unref((options as unknown as GenericLayerTreeNode).append)
|
||||||
options.append != null && options.append
|
? function () {
|
||||||
? function () {
|
if (player.tabs.includes(options.layerID)) {
|
||||||
if (player.tabs.includes(options.layerID)) {
|
const index = player.tabs.lastIndexOf(options.layerID);
|
||||||
const index = player.tabs.lastIndexOf(options.layerID);
|
player.tabs.splice(index, 1);
|
||||||
player.tabs.splice(index, 1);
|
} else {
|
||||||
} else {
|
player.tabs.push(options.layerID);
|
||||||
player.tabs.push(options.layerID);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
: function () {
|
|
||||||
player.tabs.splice(1, 1, options.layerID);
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
: function () {
|
||||||
|
player.tabs.splice(1, 1, options.layerID);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}) as unknown as LayerTreeNode<T>;
|
}) as unknown as LayerTreeNode<T>;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue