mirror of
https://github.com/thepaperpilot/Planar-Pioneers.git
synced 2024-11-22 00:21:31 +00:00
Implement repair action
This commit is contained in:
parent
dff499fd69
commit
b37d00409b
1 changed files with 34 additions and 4 deletions
|
@ -1,7 +1,10 @@
|
||||||
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,
|
||||||
|
@ -14,9 +17,11 @@ 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, persistent } from "game/persistence";
|
||||||
import { State } from "game/persistence";
|
import { State } 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 Decimal, { DecimalSource } from "lib/break_eternity";
|
import Decimal, { DecimalSource } from "lib/break_eternity";
|
||||||
import { format, formatWhole } from "util/bignum";
|
import { format, formatWhole } from "util/bignum";
|
||||||
import { camelToTitle } from "util/common";
|
import { camelToTitle } from "util/common";
|
||||||
|
@ -25,7 +30,6 @@ import { ComputedRef, computed, nextTick, reactive, ref, watch } from "vue";
|
||||||
import { useToast } from "vue-toastification";
|
import { useToast } from "vue-toastification";
|
||||||
import { createCollapsibleModifierSections } from "./common";
|
import { createCollapsibleModifierSections } from "./common";
|
||||||
import "./main.css";
|
import "./main.css";
|
||||||
import settings from "game/settings";
|
|
||||||
|
|
||||||
const toast = useToast();
|
const toast = useToast();
|
||||||
|
|
||||||
|
@ -60,6 +64,7 @@ export type Resources = keyof typeof mineLootTable;
|
||||||
*/
|
*/
|
||||||
export const main = createLayer("main", function (this: BaseLayer) {
|
export const main = createLayer("main", function (this: BaseLayer) {
|
||||||
const energy = createResource<DecimalSource>(0, "energy");
|
const energy = createResource<DecimalSource>(0, "energy");
|
||||||
|
const hasForged = persistent<boolean>(false);
|
||||||
|
|
||||||
const resourceLevelFormula = Formula.variable(0).add(1);
|
const resourceLevelFormula = Formula.variable(0).add(1);
|
||||||
|
|
||||||
|
@ -142,7 +147,7 @@ export const main = createLayer("main", function (this: BaseLayer) {
|
||||||
const board = createBoard(board => ({
|
const board = createBoard(board => ({
|
||||||
startNodes: () => [
|
startNodes: () => [
|
||||||
{ position: { x: 0, y: 0 }, type: "mine", state: 0 },
|
{ position: { x: 0, y: 0 }, type: "mine", state: 0 },
|
||||||
{ position: { x: 400, y: -400 }, type: "brokenFactory" }
|
{ position: { x: 0, y: -200 }, type: "brokenFactory" }
|
||||||
],
|
],
|
||||||
types: {
|
types: {
|
||||||
mine: {
|
mine: {
|
||||||
|
@ -167,10 +172,30 @@ export const main = createLayer("main", function (this: BaseLayer) {
|
||||||
shape: Shape.Diamond,
|
shape: Shape.Diamond,
|
||||||
size: 50,
|
size: 50,
|
||||||
title: "🛠️",
|
title: "🛠️",
|
||||||
label: node => (node === board.selectedNode.value ? { text: "Repair me!" } : null),
|
label: node =>
|
||||||
|
node === board.selectedNode.value ? { text: "Broken Forge" } : null,
|
||||||
actionDistance: 80,
|
actionDistance: 80,
|
||||||
actions: [
|
actions: [
|
||||||
{ id: "repair", icon: "build", tooltip: "Costs 1000 energy", onClick() {} }
|
{
|
||||||
|
id: "repair",
|
||||||
|
icon: "build",
|
||||||
|
tooltip: { text: "Repair - 1000 energy" },
|
||||||
|
onClick(this: GenericBoardNodeAction, node) {
|
||||||
|
if (board.selectedAction.value === this) {
|
||||||
|
if (Decimal.gte(energy.value, 1000)) {
|
||||||
|
node.type = "factory";
|
||||||
|
energy.value = Decimal.sub(energy.value, 1000);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
((board as GenericBoard).state as Persistent<BoardData>).value = {
|
||||||
|
...((board as GenericBoard).state as Persistent<BoardData>)
|
||||||
|
.value,
|
||||||
|
selectedAction: this.id
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
],
|
],
|
||||||
draggable: true
|
draggable: true
|
||||||
},
|
},
|
||||||
|
@ -178,6 +203,10 @@ export const main = createLayer("main", function (this: BaseLayer) {
|
||||||
shape: Shape.Diamond,
|
shape: Shape.Diamond,
|
||||||
size: 50,
|
size: 50,
|
||||||
title: "🛠️",
|
title: "🛠️",
|
||||||
|
label: node =>
|
||||||
|
node === board.selectedNode.value
|
||||||
|
? { text: hasForged.value ? "Forge" : "Forge - Drag a material to me!" }
|
||||||
|
: null,
|
||||||
draggable: true
|
draggable: true
|
||||||
},
|
},
|
||||||
resource: {
|
resource: {
|
||||||
|
@ -343,6 +372,7 @@ export const main = createLayer("main", function (this: BaseLayer) {
|
||||||
board,
|
board,
|
||||||
energy,
|
energy,
|
||||||
modifierTabs,
|
modifierTabs,
|
||||||
|
hasForged,
|
||||||
display: jsx(() => (
|
display: jsx(() => (
|
||||||
<>
|
<>
|
||||||
<StickyVue class="nav-container">
|
<StickyVue class="nav-container">
|
||||||
|
|
Loading…
Reference in a new issue