mirror of
https://github.com/thepaperpilot/Planar-Pioneers.git
synced 2025-03-20 13:20:33 +00:00
Add trash can node with portal generator
This commit is contained in:
parent
efd44847a9
commit
8dfc9149d9
2 changed files with 61 additions and 15 deletions
|
@ -6,7 +6,7 @@ import {
|
|||
Shape,
|
||||
getUniqueNodeID
|
||||
} from "features/boards/board";
|
||||
import { addLayer, layers } from "game/layers";
|
||||
import { addLayer, layers, removeLayer } from "game/layers";
|
||||
import player from "game/player";
|
||||
import Decimal from "lib/break_eternity";
|
||||
import { format, formatWhole } from "util/break_eternity";
|
||||
|
@ -166,6 +166,15 @@ export const factory = {
|
|||
};
|
||||
main.board.placeInAvailableSpace(newNode);
|
||||
main.board.nodes.value.push(newNode);
|
||||
if (node.state === "iron") {
|
||||
const newNode = {
|
||||
id: getUniqueNodeID(main.board as GenericBoard),
|
||||
position: { ...node.position },
|
||||
type: "trashCan"
|
||||
};
|
||||
main.board.placeInAvailableSpace(newNode);
|
||||
main.board.nodes.value.push(newNode);
|
||||
}
|
||||
main.board.selectedAction.value = null;
|
||||
main.board.selectedNode.value = null;
|
||||
node.state = undefined;
|
||||
|
@ -829,3 +838,37 @@ export const investments = {
|
|||
}),
|
||||
draggable: true
|
||||
} as NodeTypeOptions;
|
||||
|
||||
export const trashCan = {
|
||||
shape: Shape.Diamond,
|
||||
size: 50,
|
||||
title: "🗑️",
|
||||
label: node => {
|
||||
if (node === main.board.selectedNode.value) {
|
||||
return {
|
||||
text: "Trash Can - Drag a portal to me!"
|
||||
};
|
||||
}
|
||||
if (main.board.draggingNode.value?.type === "portal") {
|
||||
const portal = (main.board.draggingNode.value.state as unknown as PortalState).id;
|
||||
return {
|
||||
text: `Delete ${(layers[portal] as GenericPlane).name}!`,
|
||||
color: "var(--danger)"
|
||||
};
|
||||
}
|
||||
return null;
|
||||
},
|
||||
canAccept: (node: BoardNode, otherNode: BoardNode) => {
|
||||
return otherNode.type === "portal";
|
||||
},
|
||||
onDrop: (node, otherNode) => {
|
||||
const portal = (otherNode.state as unknown as PortalState).id;
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
removeLayer(layers[portal]!);
|
||||
delete player.layers[portal];
|
||||
main.board.state.value.nodes = main.board.state.value.nodes.filter(
|
||||
node => node !== otherNode
|
||||
);
|
||||
},
|
||||
draggable: true
|
||||
} as NodeTypeOptions;
|
||||
|
|
|
@ -74,6 +74,7 @@ import {
|
|||
portalGenerator,
|
||||
quarry,
|
||||
resource,
|
||||
trashCan,
|
||||
upgrader
|
||||
} from "./nodeTypes";
|
||||
import { GenericPlane, createPlane } from "./planes";
|
||||
|
@ -95,7 +96,8 @@ const types = {
|
|||
booster,
|
||||
upgrader,
|
||||
automator,
|
||||
investments
|
||||
investments,
|
||||
trashCan
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -1017,19 +1019,20 @@ export const getInitialLayers = (
|
|||
player: Partial<Player>
|
||||
): Array<GenericLayer> => {
|
||||
const layers: GenericLayer[] = [main];
|
||||
let id = 0;
|
||||
while (`portal-${id}` in (player.layers ?? {})) {
|
||||
const layer = player.layers?.[`portal-${id}`] as LayerData<GenericPlane>;
|
||||
layers.push(
|
||||
createPlane(
|
||||
`portal-${id}`,
|
||||
layer.tier ?? "dirt",
|
||||
layer.seed ?? Math.floor(Math.random() * 4294967296),
|
||||
(layer.influences ?? []) as unknown as InfluenceState[]
|
||||
)
|
||||
);
|
||||
id++;
|
||||
}
|
||||
(player.layers?.main as LayerData<typeof main>)?.board?.state?.nodes
|
||||
?.filter(node => node?.type === "portal")
|
||||
.map(node => (node?.state as PortalState | undefined)?.id ?? "")
|
||||
.forEach(id => {
|
||||
const layer = player.layers?.[id] as LayerData<GenericPlane>;
|
||||
layers.push(
|
||||
createPlane(
|
||||
id,
|
||||
layer.tier ?? "dirt",
|
||||
layer.seed ?? Math.floor(Math.random() * 4294967296),
|
||||
(layer.influences ?? []) as unknown as InfluenceState[]
|
||||
)
|
||||
);
|
||||
});
|
||||
return layers;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue