Merge remote-tracking branch 'origin/day-20-factory' into day-18-toy-factory

This commit is contained in:
thepaperpilot 2022-12-22 12:40:43 -06:00
commit 65180adb13

View file

@ -214,7 +214,7 @@ const factory = createLayer(id, () => {
type: "command", type: "command",
description: "Drag while equipping this to move around.", description: "Drag while equipping this to move around.",
tick: 0 tick: 0
}, } as FactoryComponentDeclaration,
delete: { delete: {
imageSrc: _delete, imageSrc: _delete,
key: "Backspace", key: "Backspace",
@ -222,7 +222,7 @@ const factory = createLayer(id, () => {
type: "command", type: "command",
description: "Remove components from the board.", description: "Remove components from the board.",
tick: 0 tick: 0
}, } as FactoryComponentDeclaration,
rotateLeft: { rotateLeft: {
imageSrc: _rotateLeft, imageSrc: _rotateLeft,
key: "t", key: "t",
@ -230,7 +230,7 @@ const factory = createLayer(id, () => {
type: "command", type: "command",
description: "Use this to rotate components counter-clockwise.", description: "Use this to rotate components counter-clockwise.",
tick: 0 tick: 0
}, } as FactoryComponentDeclaration,
rotateRight: { rotateRight: {
imageSrc: _rotateRight, imageSrc: _rotateRight,
key: "shift+T", key: "shift+T",
@ -238,7 +238,7 @@ const factory = createLayer(id, () => {
type: "command", type: "command",
description: "Use this to rotate components clockwise.", description: "Use this to rotate components clockwise.",
tick: 0 tick: 0
}, } as FactoryComponentDeclaration,
conveyor: { conveyor: {
imageSrc: _conveyor, imageSrc: _conveyor,
key: "0", key: "0",
@ -255,7 +255,7 @@ const factory = createLayer(id, () => {
type: "output" type: "output"
} }
} }
}, } as FactoryComponentDeclaration,
wood: { wood: {
imageSrc: _wood, imageSrc: _wood,
key: "1", key: "1",
@ -269,7 +269,7 @@ const factory = createLayer(id, () => {
amount: 1 amount: 1
} }
} }
}, } as FactoryComponentDeclaration,
cloth: { cloth: {
imageSrc: _cloth, imageSrc: _cloth,
key: "2", key: "2",
@ -283,7 +283,7 @@ const factory = createLayer(id, () => {
amount: 1 amount: 1
} }
} }
}, } as FactoryComponentDeclaration,
dye: { dye: {
imageSrc: _dye, imageSrc: _dye,
key: "3", key: "3",
@ -297,7 +297,7 @@ const factory = createLayer(id, () => {
amount: 1 amount: 1
} }
} }
}, } as FactoryComponentDeclaration,
metal: { metal: {
imageSrc: _metal, imageSrc: _metal,
key: "4", key: "4",
@ -311,7 +311,7 @@ const factory = createLayer(id, () => {
amount: 1 amount: 1
} }
} }
}, } as FactoryComponentDeclaration,
plastic: { plastic: {
imageSrc: _plastic, imageSrc: _plastic,
key: "5", key: "5",
@ -325,7 +325,7 @@ const factory = createLayer(id, () => {
amount: 1 amount: 1
} }
} }
}, } as FactoryComponentDeclaration,
plank: { plank: {
imageSrc: _plankMaker, imageSrc: _plankMaker,
key: "shift+1", key: "shift+1",
@ -344,7 +344,7 @@ const factory = createLayer(id, () => {
amount: 1 amount: 1
} }
} }
}, } as FactoryComponentDeclaration,
thread: { thread: {
imageSrc: _threadMaker, imageSrc: _threadMaker,
key: "shift+2", key: "shift+2",
@ -363,7 +363,7 @@ const factory = createLayer(id, () => {
amount: 1 amount: 1
} }
} }
}, } as FactoryComponentDeclaration,
wheel: { wheel: {
imageSrc: _wheelMaker, imageSrc: _wheelMaker,
key: "shift+3", key: "shift+3",
@ -382,7 +382,7 @@ const factory = createLayer(id, () => {
amount: 1 amount: 1
} }
} }
}, } as FactoryComponentDeclaration,
blocks: { blocks: {
imageSrc: _blockMaker, imageSrc: _blockMaker,
key: "ctrl+shift+1", key: "ctrl+shift+1",
@ -402,7 +402,7 @@ const factory = createLayer(id, () => {
resource: toys.woodenBlocks resource: toys.woodenBlocks
} }
} }
}, } as FactoryComponentDeclaration,
clothes: { clothes: {
imageSrc: _clothesMaker, imageSrc: _clothesMaker,
key: "ctrl+shift+2", key: "ctrl+shift+2",
@ -425,7 +425,7 @@ const factory = createLayer(id, () => {
resource: toys.clothes resource: toys.clothes
} }
} }
}, } as FactoryComponentDeclaration,
trucks: { trucks: {
imageSrc: _truckMaker, imageSrc: _truckMaker,
key: "ctrl+shift+3", key: "ctrl+shift+3",
@ -448,23 +448,56 @@ const factory = createLayer(id, () => {
resource: toys.trucks resource: toys.trucks
} }
} }
} } as FactoryComponentDeclaration
} as Record<FactoryCompNames, FactoryComponentDeclaration>; } as const;
const RESOURCES = { const RESOURCES = {
// Raw resources // Raw resources
wood: _wood, wood: {
cloth: _cloth, name: "Wood",
dye: _dye, imageSrc: _wood
plastic: _plastic, },
metal: _metal, cloth: {
name: "Cloth",
imageSrc: _cloth
},
dye: {
name: "Dye",
imageSrc: _dye
},
plastic: {
name: "Plastic",
imageSrc: _plastic
},
metal: {
name: "Metal",
imageSrc: _metal
},
// Processed resources // Processed resources
plank: _plank, plank: {
thread: _thread, name: "Planks",
wheel: _wheel, imageSrc: _plank
},
thread: {
name: "Thread",
imageSrc: _thread
},
wheel: {
name: "Wheels",
imageSrc: _wheel
},
// Toys // Toys
block: _block, block: {
clothes: _clothes, name: "Wooden Blocks",
truck: _truck imageSrc: _block
},
clothes: {
name: "Clothes",
imageSrc: _clothes
},
truck: {
name: "Trucks",
imageSrc: _truck
}
} as const; } as const;
const hotkeys = (Object.keys(FACTORY_COMPONENTS) as FactoryCompNames[]).reduce((acc, comp) => { const hotkeys = (Object.keys(FACTORY_COMPONENTS) as FactoryCompNames[]).reduce((acc, comp) => {
@ -479,20 +512,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">;
type ResourceNames = keyof typeof RESOURCES; type ResourceNames = keyof typeof RESOURCES;
@ -639,7 +659,7 @@ const factory = createLayer(id, () => {
// load every sprite here so pixi doesn't complain about loading multiple times // load every sprite here so pixi doesn't complain about loading multiple times
const assetsLoading = Promise.all([ const assetsLoading = Promise.all([
Assets.load(Object.values(FACTORY_COMPONENTS).map(x => x.imageSrc)), Assets.load(Object.values(FACTORY_COMPONENTS).map(x => x.imageSrc)),
Assets.load(Object.values(RESOURCES)) Assets.load(Object.values(RESOURCES).map(x => x.imageSrc))
]); ]);
const app = new Application({ const app = new Application({
@ -867,7 +887,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(RESOURCES[itemToMove[0]].imageSrc);
const sprite = new Sprite(texture); const sprite = new Sprite(texture);
/* /*
@ -1152,12 +1172,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) {
@ -1260,7 +1281,7 @@ const factory = createLayer(id, () => {
<h5>{title}</h5> <h5>{title}</h5>
{(Object.keys(stockData) as ResourceNames[]).map(res => ( {(Object.keys(stockData) as ResourceNames[]).map(res => (
<div> <div>
{res}:{" "} {RESOURCES[res].name}:{" "}
{stockData[res]?.resource != null {stockData[res]?.resource != null
? formatWhole(stockData[res]!.resource!.value) ? formatWhole(stockData[res]!.resource!.value)
: formatWhole(stocks[res] ?? 0)} : formatWhole(stocks[res] ?? 0)}