mirror of
https://github.com/thepaperpilot/Advent-Incremental.git
synced 2024-11-22 08:31:35 +00:00
Resource declarations
This commit is contained in:
parent
712a549b78
commit
49c170448a
1 changed files with 122 additions and 47 deletions
|
@ -11,19 +11,6 @@ import { noPersist, Persistent, persistent, State } from "game/persistence";
|
||||||
import Decimal, { format, formatWhole } from "util/bignum";
|
import Decimal, { format, formatWhole } from "util/bignum";
|
||||||
import { Direction } from "util/common";
|
import { Direction } from "util/common";
|
||||||
import { computed, ComputedRef, reactive, ref, watchEffect } from "vue";
|
import { computed, ComputedRef, reactive, ref, watchEffect } from "vue";
|
||||||
import _conveyor from "./factory-components/conveyor.png";
|
|
||||||
import _cursor from "./factory-components/cursor.svg";
|
|
||||||
import _delete from "./factory-components/delete.svg";
|
|
||||||
import _rotateLeft from "./factory-components/rotateLeft.svg";
|
|
||||||
import _rotateRight from "./factory-components/rotateRight.svg";
|
|
||||||
import _wood from "./factory-components/log.svg";
|
|
||||||
import _block from "./factory-components/block.svg";
|
|
||||||
import _cloth from "./factory-components/rotate_rectangle.png";
|
|
||||||
import _dye from "./factory-components/rotate_rectangle.png";
|
|
||||||
import _clothes from "./factory-components/rotate_rectangle.png";
|
|
||||||
import _plastic from "./factory-components/rotate_rectangle.png";
|
|
||||||
import _metal from "./factory-components/rotate_rectangle.png";
|
|
||||||
import _truck from "./factory-components/rotate_rectangle.png";
|
|
||||||
import Factory from "./Factory.vue";
|
import Factory from "./Factory.vue";
|
||||||
import "./styles/factory.css";
|
import "./styles/factory.css";
|
||||||
import coal from "./coal";
|
import coal from "./coal";
|
||||||
|
@ -39,6 +26,20 @@ import HotkeyVue from "components/Hotkey.vue";
|
||||||
import { createHotkey, GenericHotkey } from "features/hotkey";
|
import { createHotkey, GenericHotkey } from "features/hotkey";
|
||||||
import Tooltip from "features/tooltips/Tooltip.vue";
|
import Tooltip from "features/tooltips/Tooltip.vue";
|
||||||
|
|
||||||
|
import _conveyor from "./factory-components/conveyor.png";
|
||||||
|
import _cursor from "./factory-components/cursor.svg";
|
||||||
|
import _delete from "./factory-components/delete.svg";
|
||||||
|
import _rotateLeft from "./factory-components/rotateLeft.svg";
|
||||||
|
import _rotateRight from "./factory-components/rotateRight.svg";
|
||||||
|
import _wood from "./factory-components/log.svg";
|
||||||
|
import _block from "./factory-components/block.svg";
|
||||||
|
import _cloth from "./factory-components/rotate_rectangle.png";
|
||||||
|
import _dye from "./factory-components/rotate_rectangle.png";
|
||||||
|
import _clothes from "./factory-components/rotate_rectangle.png";
|
||||||
|
import _plastic from "./factory-components/rotate_rectangle.png";
|
||||||
|
import _metal from "./factory-components/rotate_rectangle.png";
|
||||||
|
import _truck from "./factory-components/rotate_rectangle.png";
|
||||||
|
|
||||||
const id = "factory";
|
const id = "factory";
|
||||||
|
|
||||||
// what is the actual day?
|
// what is the actual day?
|
||||||
|
@ -351,21 +352,47 @@ const factory = createLayer(id, () => {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
outputs: {
|
outputs: {
|
||||||
trucks: {
|
truck: {
|
||||||
amount: 1
|
amount: 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} as Record<FactoryCompNames, FactoryComponentDeclaration>;
|
} as Record<string, FactoryComponentDeclaration>;
|
||||||
const RESOURCES = {
|
|
||||||
wood: _wood,
|
const FACTORY_RESOURCES = {
|
||||||
block: _block,
|
wood: {
|
||||||
cloth: _cloth,
|
name: "Wood",
|
||||||
dye: _dye,
|
imageSrc: _wood
|
||||||
clothes: _clothes,
|
},
|
||||||
plastic: _plastic,
|
block: {
|
||||||
metal: _metal
|
name: "Blocks",
|
||||||
} as Record<string, string>;
|
imageSrc: _block
|
||||||
|
},
|
||||||
|
cloth: {
|
||||||
|
name: "Cloth",
|
||||||
|
imageSrc: _cloth
|
||||||
|
},
|
||||||
|
dye: {
|
||||||
|
name: "Dye",
|
||||||
|
imageSrc: _dye
|
||||||
|
},
|
||||||
|
clothes: {
|
||||||
|
name: "Clothes",
|
||||||
|
imageSrc: _clothes
|
||||||
|
},
|
||||||
|
plastic: {
|
||||||
|
name: "Plastic",
|
||||||
|
imageSrc: _plastic
|
||||||
|
},
|
||||||
|
metal: {
|
||||||
|
name: "Metal",
|
||||||
|
imageSrc: _metal
|
||||||
|
},
|
||||||
|
truck: {
|
||||||
|
name: "Trucks",
|
||||||
|
imageSrc: _truck
|
||||||
|
}
|
||||||
|
} as Record<string, FactoryResourceDeclaration>;
|
||||||
|
|
||||||
const hotkeys = (Object.keys(FACTORY_COMPONENTS) as FactoryCompNames[]).reduce((acc, comp) => {
|
const hotkeys = (Object.keys(FACTORY_COMPONENTS) as FactoryCompNames[]).reduce((acc, comp) => {
|
||||||
acc[comp] = createHotkey(() => ({
|
acc[comp] = createHotkey(() => ({
|
||||||
|
@ -379,20 +406,7 @@ const factory = createLayer(id, () => {
|
||||||
return acc;
|
return acc;
|
||||||
}, {} as Record<FactoryCompNames, GenericHotkey>);
|
}, {} as Record<FactoryCompNames, GenericHotkey>);
|
||||||
|
|
||||||
type FactoryCompNames =
|
type FactoryCompNames = keyof typeof FACTORY_COMPONENTS;
|
||||||
| "cursor"
|
|
||||||
| "delete"
|
|
||||||
| "rotateLeft"
|
|
||||||
| "rotateRight"
|
|
||||||
| "conveyor"
|
|
||||||
| "wood"
|
|
||||||
| "blocks"
|
|
||||||
| "cloth"
|
|
||||||
| "dye"
|
|
||||||
| "clothes"
|
|
||||||
| "plastic"
|
|
||||||
| "metal"
|
|
||||||
| "trucks";
|
|
||||||
type BuildableCompName = Exclude<FactoryCompNames, "cursor">;
|
type BuildableCompName = Exclude<FactoryCompNames, "cursor">;
|
||||||
|
|
||||||
interface FactoryComponentBase extends Record<string, State> {
|
interface FactoryComponentBase extends Record<string, State> {
|
||||||
|
@ -426,7 +440,7 @@ const factory = createLayer(id, () => {
|
||||||
|
|
||||||
/** amount it consumes */
|
/** amount it consumes */
|
||||||
inputs?: Record<
|
inputs?: Record<
|
||||||
string,
|
FactoryResNames,
|
||||||
{
|
{
|
||||||
amount: number;
|
amount: number;
|
||||||
capacity?: number;
|
capacity?: number;
|
||||||
|
@ -434,7 +448,7 @@ const factory = createLayer(id, () => {
|
||||||
>;
|
>;
|
||||||
/** amount it produces */
|
/** amount it produces */
|
||||||
outputs?: Record<
|
outputs?: Record<
|
||||||
string,
|
FactoryResNames,
|
||||||
{
|
{
|
||||||
amount: number;
|
amount: number;
|
||||||
capacity?: number;
|
capacity?: number;
|
||||||
|
@ -464,6 +478,13 @@ const factory = createLayer(id, () => {
|
||||||
}
|
}
|
||||||
type FactoryInternal = FactoryInternalConveyor | FactoryInternalProcessor;
|
type FactoryInternal = FactoryInternalConveyor | FactoryInternalProcessor;
|
||||||
|
|
||||||
|
type FactoryResNames = keyof typeof FACTORY_RESOURCES;
|
||||||
|
|
||||||
|
interface FactoryResourceDeclaration {
|
||||||
|
imageSrc: string;
|
||||||
|
name: string;
|
||||||
|
}
|
||||||
|
|
||||||
interface Block {
|
interface Block {
|
||||||
sprite: Sprite;
|
sprite: Sprite;
|
||||||
type: string;
|
type: string;
|
||||||
|
@ -726,7 +747,7 @@ const factory = createLayer(id, () => {
|
||||||
}
|
}
|
||||||
// there is nothing to move
|
// there is nothing to move
|
||||||
if (itemToMove === undefined) continue;
|
if (itemToMove === undefined) continue;
|
||||||
const texture = Assets.get(RESOURCES[itemToMove[0]]);
|
const texture = Assets.get(FACTORY_RESOURCES[itemToMove[0]].imageSrc);
|
||||||
const sprite = new Sprite(texture);
|
const sprite = new Sprite(texture);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1010,12 +1031,13 @@ const factory = createLayer(id, () => {
|
||||||
for (const [key, comp] of Object.entries(compInternalData)) {
|
for (const [key, comp] of Object.entries(compInternalData)) {
|
||||||
if (comp == null) continue;
|
if (comp == null) continue;
|
||||||
if (comp.type === "conveyor") {
|
if (comp.type === "conveyor") {
|
||||||
for (const pkg of [...comp.nextPackages, ...comp.packages]) {
|
const cComp = comp as FactoryInternalConveyor;
|
||||||
|
for (const pkg of [...cComp.nextPackages, ...cComp.packages]) {
|
||||||
pkg.sprite.destroy();
|
pkg.sprite.destroy();
|
||||||
movingBlocks.removeChild(pkg.sprite);
|
movingBlocks.removeChild(pkg.sprite);
|
||||||
}
|
}
|
||||||
comp.nextPackages = [];
|
cComp.nextPackages = [];
|
||||||
comp.packages = [];
|
cComp.packages = [];
|
||||||
} else {
|
} else {
|
||||||
const producerComp = components.value[key] as FactoryComponentProcessor;
|
const producerComp = components.value[key] as FactoryComponentProcessor;
|
||||||
if (producerComp.outputStock !== undefined) {
|
if (producerComp.outputStock !== undefined) {
|
||||||
|
@ -1123,11 +1145,62 @@ const factory = createLayer(id, () => {
|
||||||
FACTORY_COMPONENTS[whatIsHovered.value]
|
FACTORY_COMPONENTS[whatIsHovered.value]
|
||||||
.description
|
.description
|
||||||
}
|
}
|
||||||
|
<br />
|
||||||
|
{FACTORY_COMPONENTS[whatIsHovered.value].inputs !==
|
||||||
|
undefined ? (
|
||||||
|
<>
|
||||||
|
<br />
|
||||||
|
<h5>Inputs:</h5>
|
||||||
|
{Object.entries(
|
||||||
|
FACTORY_COMPONENTS[whatIsHovered.value]
|
||||||
|
.inputs as {
|
||||||
|
[s: FactoryResNames]: {
|
||||||
|
amount: number;
|
||||||
|
capacity?: number | undefined;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
).map(x => (
|
||||||
|
<div>
|
||||||
|
{FACTORY_RESOURCES[x[0]].name}:{" "}
|
||||||
|
{formatWhole(x[1].amount)}
|
||||||
|
{x[1].capacity !== undefined
|
||||||
|
? " / " +
|
||||||
|
formatWhole(x[1].capacity)
|
||||||
|
: ""}
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</>
|
||||||
|
) : undefined}
|
||||||
|
{FACTORY_COMPONENTS[whatIsHovered.value].outputs !==
|
||||||
|
undefined ? (
|
||||||
|
<>
|
||||||
|
<br />
|
||||||
|
<h5>Outputs:</h5>
|
||||||
|
{Object.entries(
|
||||||
|
FACTORY_COMPONENTS[whatIsHovered.value]
|
||||||
|
.outputs as {
|
||||||
|
[s: FactoryResNames]: {
|
||||||
|
amount: number;
|
||||||
|
capacity?: number | undefined;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
).map(x => (
|
||||||
|
<div>
|
||||||
|
{FACTORY_RESOURCES[x[0]].name}:{" "}
|
||||||
|
{formatWhole(x[1].amount)}
|
||||||
|
{x[1].capacity !== undefined
|
||||||
|
? " / " +
|
||||||
|
formatWhole(x[1].capacity)
|
||||||
|
: ""}
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</>
|
||||||
|
) : undefined}
|
||||||
{FACTORY_COMPONENTS[whatIsHovered.value]
|
{FACTORY_COMPONENTS[whatIsHovered.value]
|
||||||
.energyCost ?? 0 ? (
|
.energyCost ?? 0 ? (
|
||||||
<>
|
<>
|
||||||
<br />
|
<br />
|
||||||
Energy Consumption:{" "}
|
<h5>Energy Consumption:</h5>
|
||||||
{formatWhole(
|
{formatWhole(
|
||||||
FACTORY_COMPONENTS[whatIsHovered.value]
|
FACTORY_COMPONENTS[whatIsHovered.value]
|
||||||
.energyCost ?? 0
|
.energyCost ?? 0
|
||||||
|
@ -1187,7 +1260,8 @@ const factory = createLayer(id, () => {
|
||||||
compHovered.value.inputStock
|
compHovered.value.inputStock
|
||||||
).map(x => (
|
).map(x => (
|
||||||
<div>
|
<div>
|
||||||
{x[0]}: {formatWhole(x[1])}
|
{FACTORY_RESOURCES[x[0]].name}:{" "}
|
||||||
|
{formatWhole(x[1])}
|
||||||
{FACTORY_COMPONENTS[
|
{FACTORY_COMPONENTS[
|
||||||
compHovered.value?.type ??
|
compHovered.value?.type ??
|
||||||
"cursor"
|
"cursor"
|
||||||
|
@ -1228,7 +1302,8 @@ const factory = createLayer(id, () => {
|
||||||
compHovered.value.outputStock
|
compHovered.value.outputStock
|
||||||
).map(x => (
|
).map(x => (
|
||||||
<div>
|
<div>
|
||||||
{x[0]}: {formatWhole(x[1])}
|
{FACTORY_RESOURCES[x[0]].name}:{" "}
|
||||||
|
{formatWhole(x[1])}
|
||||||
{FACTORY_COMPONENTS[
|
{FACTORY_COMPONENTS[
|
||||||
compHovered.value?.type ??
|
compHovered.value?.type ??
|
||||||
"cursor"
|
"cursor"
|
||||||
|
|
Loading…
Reference in a new issue