mirror of
https://github.com/thepaperpilot/Advent-Incremental.git
synced 2024-11-25 18:00:25 +00:00
remove unused imports
This commit is contained in:
parent
91015b4652
commit
39bbbe0c25
1 changed files with 74 additions and 72 deletions
|
@ -15,7 +15,6 @@ import player from "game/player";
|
||||||
import "./styles/factory.css";
|
import "./styles/factory.css";
|
||||||
import { globalBus } from "game/events";
|
import { globalBus } from "game/events";
|
||||||
import { Container } from "@pixi/display";
|
import { Container } from "@pixi/display";
|
||||||
import { Matrix } from "@pixi/math";
|
|
||||||
|
|
||||||
const id = "factory";
|
const id = "factory";
|
||||||
|
|
||||||
|
@ -42,27 +41,12 @@ function getRelativeCoords(e: MouseEvent) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const factorySize = {
|
||||||
|
width: 50,
|
||||||
|
height: 50
|
||||||
|
};
|
||||||
const blockSize = 50;
|
const blockSize = 50;
|
||||||
|
|
||||||
interface FactoryComponent {
|
|
||||||
directionIn: Direction | undefined;
|
|
||||||
directionOut: Direction | undefined;
|
|
||||||
imageSrc: string;
|
|
||||||
name: string;
|
|
||||||
description: string;
|
|
||||||
type: string;
|
|
||||||
sprite: Sprite;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function positionSprite(name: string, y: number, x: number, width: number, height: number) {
|
|
||||||
const sprite = await createSprite(name);
|
|
||||||
sprite.width = width;
|
|
||||||
sprite.height = height;
|
|
||||||
sprite.y = y;
|
|
||||||
sprite.x = x;
|
|
||||||
return sprite;
|
|
||||||
}
|
|
||||||
|
|
||||||
const factory = createLayer(id, () => {
|
const factory = createLayer(id, () => {
|
||||||
// layer display
|
// layer display
|
||||||
const name = "The Factory";
|
const name = "The Factory";
|
||||||
|
@ -107,11 +91,9 @@ const factory = createLayer(id, () => {
|
||||||
square: Infinity
|
square: Infinity
|
||||||
},
|
},
|
||||||
consumption: {},
|
consumption: {},
|
||||||
consumptionStock: {},
|
consumptionStock: {}
|
||||||
onProduce(times) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} as Record<string, FactoryComponentDeclaration>;
|
} as Record<"cursor" | "conveyor" | "square", FactoryComponentDeclaration>;
|
||||||
|
|
||||||
type FactoryCompNames = keyof typeof FACTORY_COMPONENTS;
|
type FactoryCompNames = keyof typeof FACTORY_COMPONENTS;
|
||||||
type BuildableCompName = Exclude<FactoryCompNames, "cursor">;
|
type BuildableCompName = Exclude<FactoryCompNames, "cursor">;
|
||||||
|
@ -165,11 +147,14 @@ const factory = createLayer(id, () => {
|
||||||
const isMouseHoverShown = ref(false);
|
const isMouseHoverShown = ref(false);
|
||||||
const whatIsHovered = ref<FactoryCompNames | "">("");
|
const whatIsHovered = ref<FactoryCompNames | "">("");
|
||||||
const compSelected = ref<FactoryCompNames>("cursor");
|
const compSelected = ref<FactoryCompNames>("cursor");
|
||||||
const components: Ref<unknown[][]> = persistent(
|
const components: Ref<(FactoryComponent | null)[][]> = persistent(
|
||||||
Array(blockAmts.h)
|
Array(factorySize.width)
|
||||||
.fill(undefined)
|
.fill(undefined)
|
||||||
.map(() => Array(blockAmts.w).fill(undefined))
|
.map(() => Array(factorySize.height).fill(null))
|
||||||
);
|
);
|
||||||
|
const compInternalData: (FactoryInternal | null)[][] = Array(factorySize.width)
|
||||||
|
.fill(undefined)
|
||||||
|
.map(() => Array(factorySize.height).fill(null));
|
||||||
|
|
||||||
// pixi
|
// pixi
|
||||||
const app = new Application({
|
const app = new Application({
|
||||||
|
@ -184,18 +169,16 @@ const factory = createLayer(id, () => {
|
||||||
app.stage.sortableChildren = true;
|
app.stage.sortableChildren = true;
|
||||||
|
|
||||||
globalBus.on("update", diff => {
|
globalBus.on("update", diff => {
|
||||||
|
|
||||||
// will change soon:tm:
|
// will change soon:tm:
|
||||||
const tick = diff;
|
const tick = diff;
|
||||||
for (const y of components.keys()) {
|
for (const y of components.value.keys()) {
|
||||||
for (const x of components[y].keys()) {
|
for (const x of components.value[y].keys()) {
|
||||||
const data = componentData.value[y][x];
|
const data = components.value[y][x];
|
||||||
const compData = components[y][x];
|
const compData = compInternalData[y][x];
|
||||||
//console.log(compData, data)
|
//console.log(compData, data)
|
||||||
if (data === null || compData === null) continue;
|
if (data === null || compData === null) continue;
|
||||||
const factoryData = FACTORY_COMPONENTS[data.type];
|
const factoryData = FACTORY_COMPONENTS[data.type];
|
||||||
if (data.ticksDone >= factoryData.tick) {
|
if (data.ticksDone >= factoryData.tick) {
|
||||||
console.log(compData.canProduce);
|
|
||||||
if (!compData.canProduce.value) continue;
|
if (!compData.canProduce.value) continue;
|
||||||
const cyclesDone = Math.floor(data.ticksDone / factoryData.tick);
|
const cyclesDone = Math.floor(data.ticksDone / factoryData.tick);
|
||||||
console.log("produce", data.ticksDone, factoryData.tick);
|
console.log("produce", data.ticksDone, factoryData.tick);
|
||||||
|
@ -214,9 +197,7 @@ const factory = createLayer(id, () => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/*async function changeFactoryComponent(y: number, x: number) {
|
||||||
|
|
||||||
async function changeFactoryComponent(y: number, x: number) {
|
|
||||||
const comp = componentData.value[y][x];
|
const comp = componentData.value[y][x];
|
||||||
if (comp === null) return;
|
if (comp === null) return;
|
||||||
const data = FACTORY_COMPONENTS[comp.type];
|
const data = FACTORY_COMPONENTS[comp.type];
|
||||||
|
@ -243,16 +224,7 @@ const factory = createLayer(id, () => {
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
spriteContainer.addChild(sprite);
|
spriteContainer.addChild(sprite);
|
||||||
}
|
}*/
|
||||||
|
|
||||||
function removeFactoryComponent(y: number, x: number) {
|
|
||||||
const comp = components[y][x];
|
|
||||||
if (comp === null) return;
|
|
||||||
comp.sprite.destroy();
|
|
||||||
componentData.value[y][x] = null;
|
|
||||||
components[y][x] = null;
|
|
||||||
spriteContainer.removeChild(comp.sprite);
|
|
||||||
}
|
|
||||||
|
|
||||||
// draw graphics
|
// draw graphics
|
||||||
function updateGraphics() {
|
function updateGraphics() {
|
||||||
|
@ -262,8 +234,8 @@ const factory = createLayer(id, () => {
|
||||||
spriteContainer.x = mapOffset.x * blockSize + app.view.width / 2;
|
spriteContainer.x = mapOffset.x * blockSize + app.view.width / 2;
|
||||||
spriteContainer.y = mapOffset.y * blockSize + app.view.height / 2;
|
spriteContainer.y = mapOffset.y * blockSize + app.view.height / 2;
|
||||||
|
|
||||||
if (isMouseHoverShown.value) {
|
if (isMouseHoverShown.value && compSelected.value === "cursor") {
|
||||||
let { tx, ty } = spriteContainer.localTransform;
|
const { tx, ty } = spriteContainer.localTransform;
|
||||||
graphicContainer.beginFill(0x808080);
|
graphicContainer.beginFill(0x808080);
|
||||||
graphicContainer.drawRect(
|
graphicContainer.drawRect(
|
||||||
roundDownTo(mouseCoords.x - tx, blockSize) + tx,
|
roundDownTo(mouseCoords.x - tx, blockSize) + tx,
|
||||||
|
@ -275,45 +247,74 @@ const factory = createLayer(id, () => {
|
||||||
}
|
}
|
||||||
watchEffect(updateGraphics);
|
watchEffect(updateGraphics);
|
||||||
|
|
||||||
let pointerDown = ref(false), pointerDrag = ref(false);
|
const pointerDown = ref(false),
|
||||||
|
pointerDrag = ref(false);
|
||||||
|
|
||||||
function onFactoryPointerMove(e: PointerEvent) {
|
function onFactoryPointerMove(e: PointerEvent) {
|
||||||
|
|
||||||
const { x, y } = getRelativeCoords(e);
|
const { x, y } = getRelativeCoords(e);
|
||||||
mouseCoords.x = x;
|
mouseCoords.x = x;
|
||||||
mouseCoords.y = y;
|
mouseCoords.y = y;
|
||||||
|
|
||||||
if (pointerDown.value && (pointerDrag.value || Math.abs(e.movementX) > 2 || Math.abs(e.movementY) > 2)) {
|
if (
|
||||||
|
pointerDown.value &&
|
||||||
|
compSelected.value === "cursor" &&
|
||||||
|
(pointerDrag.value || Math.abs(e.movementX) > 2 || Math.abs(e.movementY) > 2)
|
||||||
|
) {
|
||||||
pointerDrag.value = true;
|
pointerDrag.value = true;
|
||||||
mapOffset.x += e.movementX / blockSize;
|
mapOffset.x += e.movementX / blockSize;
|
||||||
mapOffset.y += e.movementY / blockSize;
|
mapOffset.y += e.movementY / blockSize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async function onFactoryPointerDown(e: PointerEvent) {
|
async function onFactoryPointerDown() {
|
||||||
window.addEventListener("pointerup", onFactoryPointerUp);
|
window.addEventListener("pointerup", onFactoryPointerUp);
|
||||||
pointerDown.value = true;
|
pointerDown.value = true;
|
||||||
}
|
}
|
||||||
async function onFactoryPointerUp(e: PointerEvent) {
|
async function onFactoryPointerUp(e: PointerEvent) {
|
||||||
if (!pointerDrag.value) {
|
// make sure they're not dragging and that
|
||||||
if (compSelected.value !== "") {
|
// they aren't trying to put down a cursor
|
||||||
let { tx, ty } = spriteContainer.localTransform;
|
if (!pointerDrag.value && compSelected.value !== "cursor") {
|
||||||
let { x, y } = getRelativeCoords(e);
|
const { tx, ty } = spriteContainer.localTransform;
|
||||||
x = roundDownTo(x - tx, blockSize) / blockSize;
|
let { x, y } = getRelativeCoords(e);
|
||||||
y = roundDownTo(y - ty, blockSize) / blockSize;
|
x = roundDownTo(x - tx, blockSize) / blockSize;
|
||||||
|
y = roundDownTo(y - ty, blockSize) / blockSize;
|
||||||
|
const factoryBaseData = FACTORY_COMPONENTS[compSelected.value];
|
||||||
|
const sheet = await Assets.load(factoryBaseData.imageSrc);
|
||||||
|
const sprite = new Sprite(sheet);
|
||||||
|
|
||||||
const basicData = structuredClone(
|
console.log(x, y);
|
||||||
FACTORY_COMPONENTS[compSelected.value]
|
|
||||||
) as FactoryComponent;
|
|
||||||
basicData.type = compSelected.value;
|
|
||||||
const sheet = await Assets.load(basicData.imageSrc);
|
|
||||||
basicData.sprite = new Sprite(sheet);
|
|
||||||
|
|
||||||
basicData.sprite.x = x * blockSize;
|
sprite.x = x * blockSize;
|
||||||
basicData.sprite.y = y * blockSize;
|
sprite.y = y * blockSize;
|
||||||
basicData.sprite.width = blockSize;
|
sprite.width = blockSize;
|
||||||
basicData.sprite.height = blockSize;
|
sprite.height = blockSize;
|
||||||
spriteContainer.addChild(basicData.sprite);
|
components.value[y][x] = {
|
||||||
}
|
type: compSelected.value,
|
||||||
|
ticksDone: 0,
|
||||||
|
consumptionStock: structuredClone(factoryBaseData.consumptionStock),
|
||||||
|
productionStock: structuredClone(factoryBaseData.productionStock)
|
||||||
|
};
|
||||||
|
compInternalData[y][x] = {
|
||||||
|
canProduce: computed(() => {
|
||||||
|
if (!(factoryBaseData.canProduce?.value ?? true)) return false;
|
||||||
|
// this should NEVER be null
|
||||||
|
const compData = components.value[y][x] as FactoryComponent;
|
||||||
|
for (const [key, res] of Object.entries(compData.productionStock)) {
|
||||||
|
// if the current stock + production is more than you can handle
|
||||||
|
if (
|
||||||
|
res + factoryBaseData.production[key] >
|
||||||
|
factoryBaseData.productionStock[key]
|
||||||
|
)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for (const [key, res] of Object.entries(compData.consumptionStock)) {
|
||||||
|
// make sure you have enough to produce
|
||||||
|
if (res < factoryBaseData.consumptionStock[key]) return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}),
|
||||||
|
sprite
|
||||||
|
};
|
||||||
|
spriteContainer.addChild(sprite);
|
||||||
}
|
}
|
||||||
|
|
||||||
window.removeEventListener("pointerup", onFactoryPointerUp);
|
window.removeEventListener("pointerup", onFactoryPointerUp);
|
||||||
|
@ -343,6 +344,7 @@ const factory = createLayer(id, () => {
|
||||||
minWidth: 700,
|
minWidth: 700,
|
||||||
minimizable: false,
|
minimizable: false,
|
||||||
style: { overflow: "hidden" },
|
style: { overflow: "hidden" },
|
||||||
|
components,
|
||||||
display: jsx(() => (
|
display: jsx(() => (
|
||||||
<div class="layer-container">
|
<div class="layer-container">
|
||||||
<button class="goBack" onClick={goBack}>
|
<button class="goBack" onClick={goBack}>
|
||||||
|
|
Loading…
Reference in a new issue