Handle board action changes

This commit is contained in:
thepaperpilot 2023-04-22 23:13:43 -05:00
parent 4a1abb7231
commit c813bc7513

View file

@ -1,10 +1,7 @@
import Modal from "components/Modal.vue"; import Modal from "components/Modal.vue";
import StickyVue from "components/layout/Sticky.vue"; import StickyVue from "components/layout/Sticky.vue";
import { import {
BoardData,
BoardNode, BoardNode,
GenericBoard,
GenericBoardNodeAction,
ProgressDisplay, ProgressDisplay,
Shape, Shape,
createBoard, createBoard,
@ -17,7 +14,7 @@ import Formula, { calculateCost } from "game/formulas/formulas";
import type { BaseLayer, GenericLayer } from "game/layers"; import type { BaseLayer, GenericLayer } from "game/layers";
import { createLayer } from "game/layers"; import { createLayer } from "game/layers";
import { createMultiplicativeModifier, createSequentialModifier } from "game/modifiers"; import { createMultiplicativeModifier, createSequentialModifier } from "game/modifiers";
import { Persistent, State, persistent } from "game/persistence"; import { State, persistent } from "game/persistence";
import type { Player } from "game/player"; import type { Player } from "game/player";
import player from "game/player"; import player from "game/player";
import settings from "game/settings"; import settings from "game/settings";
@ -180,21 +177,16 @@ export const main = createLayer("main", function (this: BaseLayer) {
id: "repair", id: "repair",
icon: "build", icon: "build",
tooltip: { text: "Repair - 1000 energy" }, tooltip: { text: "Repair - 1000 energy" },
onClick(this: GenericBoardNodeAction, node) { onClick(node) {
if (board.selectedAction.value === this) {
if (Decimal.gte(energy.value, 1000)) { if (Decimal.gte(energy.value, 1000)) {
node.type = "factory"; node.type = "factory";
energy.value = Decimal.sub(energy.value, 1000); energy.value = Decimal.sub(energy.value, 1000);
} }
} else { },
((board as GenericBoard).state as Persistent<BoardData>).value = { confirmationLabel: () =>
...((board as GenericBoard).state as Persistent<BoardData>) Decimal.gte(energy.value, 1000)
.value, ? { text: "Tap again to confirm" }
selectedAction: this.id : { text: "Cannot afford", color: "var(--danger)" }
};
}
return true;
}
} }
], ],
draggable: true draggable: true
@ -214,16 +206,7 @@ export const main = createLayer("main", function (this: BaseLayer) {
icon: "", icon: "",
tooltip: { text: "De-select material" }, tooltip: { text: "De-select material" },
onClick(node) { onClick(node) {
if (board.selectedAction.value === this) {
node.state = undefined; node.state = undefined;
} else {
((board as GenericBoard).state as Persistent<BoardData>).value = {
...((board as GenericBoard).state as Persistent<BoardData>)
.value,
selectedAction: this.id
};
}
return true;
}, },
visibility: node => node.state != null visibility: node => node.state != null
}, },
@ -232,16 +215,7 @@ export const main = createLayer("main", function (this: BaseLayer) {
icon: "", icon: "",
tooltip: node => ({ text: "Craft unknown item" }), tooltip: node => ({ text: "Craft unknown item" }),
onClick(node) { onClick(node) {
if (board.selectedAction.value === this) {
// TODO create tool // TODO create tool
} else {
((board as GenericBoard).state as Persistent<BoardData>).value = {
...((board as GenericBoard).state as Persistent<BoardData>)
.value,
selectedAction: this.id
};
}
return true;
}, },
visibility: node => node.state != null visibility: node => node.state != null
} }