Fixed issue with registering things out of order

This commit is contained in:
thepaperpilot 2021-08-25 08:41:49 -05:00
parent e642b0e420
commit 1ee8d2a41c

View file

@ -28,6 +28,53 @@ export type ActionNodeData = {
log: LogEntry[]; 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<string, Resource>;
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 = { export type LogEntry = {
description: string; description: string;
effectDescription?: string; effectDescription?: string;
@ -148,53 +195,6 @@ const pinAction = {
} }
} as BoardNodeAction; } 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<string, Resource>;
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 { export default {
id: "main", id: "main",
display: Main, display: Main,