From 7c06c1972bc75849efb3eb7f22448e9808c5dca9 Mon Sep 17 00:00:00 2001 From: circle-gon <97845741+circle-gon@users.noreply.github.com> Date: Thu, 22 Dec 2022 16:55:16 -0500 Subject: [PATCH 01/11] changes seconds to tick --- src/data/layers/factory.tsx | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/data/layers/factory.tsx b/src/data/layers/factory.tsx index ecf1ca1..8be14c5 100644 --- a/src/data/layers/factory.tsx +++ b/src/data/layers/factory.tsx @@ -249,7 +249,7 @@ const factory = createLayer(id, () => { key: "0", name: "Conveyor", type: "conveyor", - description: "Moves items at 1 block per second.", + description: "Moves items at 1 block per tick.", energyCost: 1, tick: 1, ports: { @@ -267,7 +267,7 @@ const factory = createLayer(id, () => { key: "1", name: "Wood Machine", type: "processor", - description: "Produces 1 wood every 1 second.", + description: "Produces 1 wood per tick.", energyCost: 10, tick: 1, outputs: { @@ -282,7 +282,7 @@ const factory = createLayer(id, () => { key: "2", name: "Cloth Machine", type: "processor", - description: "Produces 1 cloth every 1 second.", + description: "Produces 1 cloth per tick.", energyCost: 10, tick: 1, outputs: { @@ -297,7 +297,7 @@ const factory = createLayer(id, () => { key: "3", name: "Dye Machine", type: "processor", - description: "Produces 1 dye every 1 second.", + description: "Produces 1 dye per tick.", energyCost: 10, tick: 1, outputs: { @@ -312,7 +312,7 @@ const factory = createLayer(id, () => { key: "4", name: "Metal Machine", type: "processor", - description: "Produces 1 metal every 1 second.", + description: "Produces 1 metal per tick.", energyCost: 10, tick: 1, outputs: { @@ -327,7 +327,7 @@ const factory = createLayer(id, () => { key: "5", name: "Plastic Machine", type: "processor", - description: "Produces 1 plastic every 1 second.", + description: "Produces 1 plastic per tick.", energyCost: 10, tick: 1, outputs: { @@ -341,7 +341,7 @@ const factory = createLayer(id, () => { key: "shift+1", name: "Sawmill", type: "processor", - description: "Turns 1 wood into 1 plank every second.", + description: "Turns 1 wood into 1 plank per tick.", energyCost: 2, tick: 1, inputs: { @@ -360,7 +360,7 @@ const factory = createLayer(id, () => { key: "shift+2", name: "Thread Spinner", type: "processor", - description: "Turns 1 cloth into 1 thread every second.", + description: "Turns 1 cloth into 1 thread per tick.", energyCost: 2, tick: 1, inputs: { @@ -384,7 +384,7 @@ const factory = createLayer(id, () => { () => `Turns 1 plastic into ${ toys.milestones.milestone5.earned.value ? "2 wheels" : "1 wheel" - } every second.` + } per tick.` ), energyCost: 2, tick: 1, @@ -404,7 +404,7 @@ const factory = createLayer(id, () => { key: "ctrl+shift+1", name: "Wooden Block Maker", type: "processor", - description: "Turns 1 plank into 1 wooden block every second.", + description: "Turns 1 plank into 1 wooden block per tick.", energyCost: 20, tick: 1, inputs: { @@ -424,7 +424,7 @@ const factory = createLayer(id, () => { key: "ctrl+shift+2", name: "Clothes Maker", type: "processor", - description: "Turns 2 threads, 3 cloth, and 1 dye into 1 clothes every second.", + description: "Turns 2 threads, 3 cloth, and 1 dye into 1 clothes per tick.", energyCost: 20, tick: 1, inputs: { @@ -450,7 +450,7 @@ const factory = createLayer(id, () => { key: "ctrl+shift+3", name: "Trucks Maker", type: "processor", - description: "Turns 2 metal and 4 wheels into 1 truck every second.", + description: "Turns 2 metal and 4 wheels into 1 truck per tick.", energyCost: 20, tick: 1, inputs: { From 255ecea3e1bc7a5634b983adaafae1405169c1cc Mon Sep 17 00:00:00 2001 From: circle-gon <97845741+circle-gon@users.noreply.github.com> Date: Thu, 22 Dec 2022 20:33:33 -0500 Subject: [PATCH 02/11] adds efficency display --- src/data/layers/factory.tsx | 81 ++++++++++++++++++++++++++++++------- 1 file changed, 67 insertions(+), 14 deletions(-) diff --git a/src/data/layers/factory.tsx b/src/data/layers/factory.tsx index 8be14c5..388d6de 100644 --- a/src/data/layers/factory.tsx +++ b/src/data/layers/factory.tsx @@ -29,8 +29,8 @@ import { noPersist, Persistent, persistent, State } from "game/persistence"; import Decimal, { DecimalSource, format, formatWhole } from "util/bignum"; import { Direction } from "util/common"; import { ProcessedComputable } from "util/computed"; -import { render, renderRow } from "util/vue"; -import { computed, ComputedRef, reactive, ref, unref, watchEffect } from "vue"; +import { render, renderRow, VueFeature } from "util/vue"; +import { computed, ComputedRef, reactive, ref, shallowRef, unref, watchEffect } from "vue"; import coal from "./coal"; import _block from "./factory-components/block.svg"; import _blockMaker from "./factory-components/blockmaker.svg"; @@ -601,6 +601,10 @@ const factory = createLayer(id, () => { } interface FactoryInternalProcessor extends FactoryInternalBase { type: Exclude; + lastProdTimes: number[]; + + lastFactoryProd: number; + average: ComputedRef; } type FactoryInternal = FactoryInternalConveyor | FactoryInternalProcessor; @@ -743,9 +747,6 @@ const factory = createLayer(id, () => { loaded = true; watchEffect(updateGraphics); }); - (window as any).internal = compInternalData; - (window as any).comp = components; - (window as any).blocks = movingBlocks; function moveBlock(block: Block, newBlock: FactoryInternal, blockData: FactoryComponent) { // empty spot @@ -865,6 +866,12 @@ const factory = createLayer(id, () => { } } data.ticksDone -= cyclesDone * factoryData.tick; + const now = Date.now(); + const diff = (now - compData.lastFactoryProd) / 1000; + compData.lastProdTimes.push(diff); + console.log(compData.lastProdTimes); + if (compData.lastProdTimes.length > 10) compData.lastProdTimes.shift(); + compData.lastFactoryProd = now; } } else { data.ticksDone += factoryTicks; @@ -1009,6 +1016,26 @@ const factory = createLayer(id, () => { type: data.type, packages: isConveyor ? [] : undefined, nextPackages: isConveyor ? [] : undefined, + lastProdTimes: !isConveyor ? (reactive([]) as number[]) : undefined, + lastFactoryProd: !isConveyor + ? Date.now() - + 1000 * Decimal.div(data.ticksDone ?? 0, computedTickRate.value).toNumber() + : undefined, + average: !isConveyor + ? computed(() => { + const times = (compInternalData[x + "x" + y] as FactoryInternalProcessor) + .lastProdTimes; + if (times.length === 0) return undefined; + + // times is in SECONDS, not ticks + // seconds * Ticks per second -> ticks taken + + return Decimal.mul(times.length, factoryBaseData.tick) + .div(times.reduce((x, n) => x + n, 0)) + .div(computedTickRate.value) + .toNumber(); + }) + : undefined, canProduce: computed(() => { if (data.type === "conveyor") return true; if (!(factoryBaseData.canProduce?.value ?? true)) return false; @@ -1088,6 +1115,7 @@ const factory = createLayer(id, () => { const pointerDown = ref(false), pointerDrag = ref(false), compHovered = ref(undefined), + compInternalHovered = shallowRef(undefined), paused = ref(false); function onFactoryPointerMove(e: PointerEvent) { @@ -1117,12 +1145,12 @@ const factory = createLayer(id, () => { } if (!pointerDown.value && !pointerDrag.value) { const { tx, ty } = spriteContainer.localTransform; - compHovered.value = - components.value[ - Math.round(roundDownTo(x - tx, blockSize) / blockSize) + - "x" + - Math.round(roundDownTo(y - ty, blockSize) / blockSize) - ]; + const xyPos = + Math.round(roundDownTo(x - tx, blockSize) / blockSize) + + "x" + + Math.round(roundDownTo(y - ty, blockSize) / blockSize); + compHovered.value = components.value[xyPos]; + compInternalHovered.value = compInternalData[xyPos]; } } function onFactoryPointerDown(e: PointerEvent) { @@ -1217,6 +1245,7 @@ const factory = createLayer(id, () => { cComp.packages = []; } else { const producerComp = components.value[key] as FactoryComponentProcessor; + const cComp = comp as FactoryInternalProcessor; if (producerComp.outputStock !== undefined) { for (const key in producerComp.outputStock) { delete producerComp.outputStock[key as ResourceNames]; @@ -1228,6 +1257,8 @@ const factory = createLayer(id, () => { } } producerComp.ticksDone = 0; + cComp.lastFactoryProd = Date.now(); + cComp.lastProdTimes.splice(0, Infinity); } } } @@ -1339,7 +1370,7 @@ const factory = createLayer(id, () => { } const hoveredComponent = jsx(() => - compHovered.value !== undefined ? ( + compHovered.value !== undefined && compInternalHovered.value !== undefined ? (
{
{unref(FACTORY_COMPONENTS[compHovered.value.type].description)}
- {compHovered.value.type !== "conveyor" ? ( + {compHovered.value.type !== "conveyor" && + compInternalHovered.value.type !== "conveyor" ? ( <> {showStockAmount( compHovered.value.inputStock, @@ -1373,6 +1405,27 @@ const factory = createLayer(id, () => { "Outputs:", false )} +
+ Efficency:{" "} + {compInternalHovered.value.average.value !== undefined ? ( + 1 + ? "purple" + : compInternalHovered.value.average.value >= 0.9 + ? "green" + : compInternalHovered.value.average.value >= 0.5 + ? "yellow" + : "red" + }} + > + {formatWhole(compInternalHovered.value.average.value * 100)} + + ) : ( + "--" + )} + % ) : undefined}
@@ -1533,7 +1586,7 @@ const factory = createLayer(id, () => { display: jsx(() => ( <> {render(modifiersModal)} - {render(tabs)} + {render(tabs as VueFeature)} )) }; From 6be44c3a0a489906411e187bcb06a2e473996f73 Mon Sep 17 00:00:00 2001 From: Chunkybanana <62921243+chunkybanana@users.noreply.github.com> Date: Fri, 23 Dec 2022 13:13:13 +1000 Subject: [PATCH 03/11] Add some present images --- .../layers/factory-components/present.svg | 51 +++ .../factory-components/presentmaker.svg | 60 +++ .../layers/factory-components/ribbonmaker.svg | 412 ++++++++++++++++++ 3 files changed, 523 insertions(+) create mode 100644 src/data/layers/factory-components/present.svg create mode 100644 src/data/layers/factory-components/presentmaker.svg create mode 100644 src/data/layers/factory-components/ribbonmaker.svg diff --git a/src/data/layers/factory-components/present.svg b/src/data/layers/factory-components/present.svg new file mode 100644 index 0000000..8689a5f --- /dev/null +++ b/src/data/layers/factory-components/present.svg @@ -0,0 +1,51 @@ + + + + diff --git a/src/data/layers/factory-components/presentmaker.svg b/src/data/layers/factory-components/presentmaker.svg new file mode 100644 index 0000000..75093c5 --- /dev/null +++ b/src/data/layers/factory-components/presentmaker.svg @@ -0,0 +1,60 @@ + + + + diff --git a/src/data/layers/factory-components/ribbonmaker.svg b/src/data/layers/factory-components/ribbonmaker.svg new file mode 100644 index 0000000..a16086e --- /dev/null +++ b/src/data/layers/factory-components/ribbonmaker.svg @@ -0,0 +1,412 @@ + + + + From d2d397e4fcf26664219522c054ff720cf62bc91f Mon Sep 17 00:00:00 2001 From: Chunkybanana <62921243+chunkybanana@users.noreply.github.com> Date: Fri, 23 Dec 2022 08:32:10 +0000 Subject: [PATCH 04/11] Fixed persistent ref issues --- src/data/layers/factory.tsx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/data/layers/factory.tsx b/src/data/layers/factory.tsx index 2e6cde0..d079744 100644 --- a/src/data/layers/factory.tsx +++ b/src/data/layers/factory.tsx @@ -671,7 +671,7 @@ const factory = createLayer(id, () => { outputs: { bear: { amount: computed(() => (upgrades[1][3].bought.value ? 2 : 1)), - resource: bears + resource: noPersist(bears) } }, visible: main.days[advancedDay - 1].opened @@ -695,7 +695,7 @@ const factory = createLayer(id, () => { outputs: { shovelBucket: { amount: 1, - resource: bucketAndShovels + resource: noPersist(bucketAndShovels) } }, visible: main.days[advancedDay - 1].opened @@ -723,7 +723,7 @@ const factory = createLayer(id, () => { outputs: { console: { amount: computed(() => (upgrades[1][3].bought.value ? 3 : 1)), - resource: consoles + resource: noPersist(consoles) } }, visible: main.days[advancedDay - 1].opened @@ -958,7 +958,7 @@ const factory = createLayer(id, () => { style: "width: 110px" })); const bearsBuyable = createBuyable(() => ({ - resource: bears, + resource: noPersist(bears), cost() { return Decimal.pow(2, Decimal.add(this.amount.value, 5)); }, @@ -970,7 +970,7 @@ const factory = createLayer(id, () => { visible: () => showIf(main.days[advancedDay - 1].opened.value) })); const bucketBuyable = createBuyable(() => ({ - resource: bucketAndShovels, + resource: noPersist(bucketAndShovels), cost() { return Decimal.pow(2, Decimal.add(this.amount.value, 5)); }, @@ -982,7 +982,7 @@ const factory = createLayer(id, () => { visible: () => showIf(main.days[advancedDay - 1].opened.value) })); const consolesBuyable = createBuyable(() => ({ - resource: consoles, + resource: noPersist(consoles), cost() { return Decimal.pow(2, Decimal.add(this.amount.value, 5)); }, From 08434d44be95c8da97e2799ecde29dcd8639be85 Mon Sep 17 00:00:00 2001 From: Chunkybanana <62921243+chunkybanana@users.noreply.github.com> Date: Fri, 23 Dec 2022 08:41:52 +0000 Subject: [PATCH 05/11] Added a little padding to the component list --- src/data/layers/styles/factory.css | 1 + 1 file changed, 1 insertion(+) diff --git a/src/data/layers/styles/factory.css b/src/data/layers/styles/factory.css index 6a0b3df..9a02626 100644 --- a/src/data/layers/styles/factory.css +++ b/src/data/layers/styles/factory.css @@ -141,6 +141,7 @@ overflow-x: hidden; padding-right: 370px; direction: rtl; + padding-left: 10px; } .comp-list-child { From 72d13db963c32c80661d59a5007f5323038bfac6 Mon Sep 17 00:00:00 2001 From: ducdat0507 <62660527+ducdat0507@users.noreply.github.com> Date: Fri, 23 Dec 2022 16:29:17 +0700 Subject: [PATCH 06/11] --- src/data/layers/factory.tsx | 56 +++++++++++++++++------- src/data/layers/styles/day-gradients.css | 15 +++++++ 2 files changed, 56 insertions(+), 15 deletions(-) diff --git a/src/data/layers/factory.tsx b/src/data/layers/factory.tsx index 151b368..c6f6265 100644 --- a/src/data/layers/factory.tsx +++ b/src/data/layers/factory.tsx @@ -208,7 +208,7 @@ const factory = createLayer(id, () => { ? 1 : Decimal.sub(2, Decimal.div(energyConsumption.value, computedEnergy.value)), description: "Brighter work rooms", - enabled: () => upgrades[2][1].bought.value + enabled: () => upgrades[2][0].bought.value })), createMultiplicativeModifier(() => ({ multiplier: 1.5, @@ -217,6 +217,8 @@ const factory = createLayer(id, () => { })) ]); const computedTickRate = computed(() => tickRate.apply(1)); + const computedActualTickRate = computed(() => Decimal.min(computedTickRate.value, 5)); + const computedToyMultiplier = computed(() => Decimal.div(computedTickRate.value, 5).max(1)); const factorySize = createSequentialModifier(() => [ createAdditiveModifier(() => ({ addend: expandFactory.amount, @@ -578,7 +580,7 @@ const factory = createLayer(id, () => { } as FactoryComponentDeclaration, blocks: { imageSrc: _blockMaker, - key: "ctrl+shift+1", + key: "ctrl+1", name: "Wooden Block Maker", type: "processor", description: "Turns 1 plank into 1 wooden block per tick.", @@ -598,7 +600,7 @@ const factory = createLayer(id, () => { } as FactoryComponentDeclaration, clothes: { imageSrc: _clothesMaker, - key: "ctrl+shift+2", + key: "ctrl+2", name: "Clothes Maker", type: "processor", description: "Turns 2 threads, 3 cloth, and 1 dye into 1 clothes per tick.", @@ -624,7 +626,7 @@ const factory = createLayer(id, () => { } as FactoryComponentDeclaration, trucks: { imageSrc: _truckMaker, - key: "ctrl+shift+3", + key: "ctrl+3", name: "Trucks Maker", type: "processor", description: "Turns 2 metal and 4 wheels into 1 truck per tick.", @@ -647,7 +649,7 @@ const factory = createLayer(id, () => { } as FactoryComponentDeclaration, bear: { imageSrc: _bearMaker, - key: "ctrl+shift+4", + key: "ctrl+4", name: "Teddy Bear Maker", type: "processor", description: @@ -678,7 +680,7 @@ const factory = createLayer(id, () => { } as FactoryComponentDeclaration, bucketShovel: { imageSrc: _bucketShovelMaker, - key: "ctrl+shift+5", + key: "ctrl+5", name: "Shovel and Pail Maker", type: "processor", description: "Turns 1 bucket and 1 shovel into 1 shovel and pail every second.", @@ -702,7 +704,7 @@ const factory = createLayer(id, () => { } as FactoryComponentDeclaration, console: { imageSrc: _consoleMaker, - key: "ctrl+shift+6", + key: "ctrl+6", name: "Game Console Maker", type: "processor", description: @@ -1281,7 +1283,7 @@ const factory = createLayer(id, () => { globalBus.on("update", diff => { if (!loaded || paused.value) return; - const factoryTicks = Decimal.times(computedTickRate.value, diff).toNumber(); + const factoryTicks = Decimal.times(computedActualTickRate.value, diff).toNumber(); //debugger // make them produce @@ -1362,7 +1364,10 @@ const factory = createLayer(id, () => { if (val.resource != null) { val.resource.value = Decimal.add( val.resource.value, - unref(val.amount) + Decimal.times( + computedToyMultiplier.value, + unref(val.amount) + ) ); } else { data.outputStock[key as ResourceNames] = @@ -1444,9 +1449,17 @@ const factory = createLayer(id, () => { // however it needs to be aligned if Y is being moved // vice-versa sprite.x = - (x + xInc * 0.3 + (xInc == 0 ? Math.random() * 0.4 - 0.2 : 0)) * blockSize; + (x + xInc * 0.3 + (xInc == 0 ? Math.random() * 0.4 - 0.2 : 0) + 0.5) * + blockSize; sprite.y = - (y + yInc * 0.3 + (yInc == 0 ? Math.random() * 0.4 - 0.2 : 0)) * blockSize; + (y + yInc * 0.3 + (yInc == 0 ? Math.random() * 0.4 - 0.2 : 0) + 0.5) * + blockSize; + + if (computedFactorySize.value % 2 !== 0) { + sprite.x -= 0.5 * blockSize; + sprite.y -= 0.5 * blockSize; + } + sprite.anchor.set(0.5); sprite.width = blockSize / 2.5; sprite.height = blockSize / 2.5; @@ -1532,7 +1545,7 @@ const factory = createLayer(id, () => { lastProdTimes: !isConveyor ? (reactive([]) as number[]) : undefined, lastFactoryProd: !isConveyor ? Date.now() - - 1000 * Decimal.div(data.ticksDone ?? 0, computedTickRate.value).toNumber() + 1000 * Decimal.div(data.ticksDone ?? 0, computedActualTickRate.value).toNumber() : undefined, average: !isConveyor ? computed(() => { @@ -1545,7 +1558,7 @@ const factory = createLayer(id, () => { return Decimal.mul(times.length, factoryBaseData.tick) .div(times.reduce((x, n) => x + n, 0)) - .div(computedTickRate.value) + .div(computedActualTickRate.value) .toNumber(); }) : undefined, @@ -2050,7 +2063,20 @@ const factory = createLayer(id, () => { onUpdate:modelValue={(value: boolean) => (showModifiersModal.value = value)} v-slots={{ header: () =>

{name} Modifiers

, - body: generalTab + body: () => ( + <> + {render(generalTab)} + {Decimal.gte(computedTickRate.value, 5) ? ( + <> +
+ Note: the actual tick rate is capped at 5 TPS, but you'll gain extra + toys based on excessive tick rate as a compensation. + + ) : ( + "" + )} + + ) }} /> )); @@ -2059,7 +2085,7 @@ const factory = createLayer(id, () => { direction: Direction.Right, width: 600, height: 25, - fillStyle: `backgroundColor: ${color}`, + fillStyle: `animation: 15s factory-bar linear infinite`, progress: () => main.day.value === day ? Decimal.div(toys.clothes.value, toyGoal) diff --git a/src/data/layers/styles/day-gradients.css b/src/data/layers/styles/day-gradients.css index e35a4d3..b540378 100644 --- a/src/data/layers/styles/day-gradients.css +++ b/src/data/layers/styles/day-gradients.css @@ -62,4 +62,19 @@ green 10px 20px ); } +} + +@keyframes factory-bar { + from { + background: 0 0 / 114px 114px repeat repeating-linear-gradient(-45deg, + grey 0 10px, + yellow 10px 20px + ); + } + to { + background: 114px 0px / 114px 114px repeat repeating-linear-gradient(-45deg, + grey 0 10px, + yellow 10px 20px + ); + } } \ No newline at end of file From d1a02cd394e669e6cff09d4cad035e017ec1edc1 Mon Sep 17 00:00:00 2001 From: ducdat0507 <62660527+ducdat0507@users.noreply.github.com> Date: Fri, 23 Dec 2022 18:52:03 +0700 Subject: [PATCH 07/11] Automatically generate factory component desciptions --- src/data/layers/factory.tsx | 67 +++++++++++++++++------------- src/data/layers/styles/factory.css | 10 +++-- src/util/bignum.ts | 5 ++- src/util/break_eternity.ts | 6 +++ 4 files changed, 54 insertions(+), 34 deletions(-) diff --git a/src/data/layers/factory.tsx b/src/data/layers/factory.tsx index b32ceb0..d0b3b07 100644 --- a/src/data/layers/factory.tsx +++ b/src/data/layers/factory.tsx @@ -28,7 +28,7 @@ import { Modifier } from "game/modifiers"; import { noPersist, Persistent, persistent, State } from "game/persistence"; -import Decimal, { DecimalSource, format, formatWhole } from "util/bignum"; +import Decimal, { DecimalSource, format, formatList, formatWhole } from "util/bignum"; import { Direction, WithRequired } from "util/common"; import { ProcessedComputable } from "util/computed"; import { render, renderGrid, renderRow, VueFeature } from "util/vue"; @@ -287,6 +287,21 @@ const factory = createLayer(id, () => { // ---------------------------------------------- Components + + function generateComponentDescription(declaration: FactoryComponentDeclaration) { + + let str = declaration.inputs === undefined ? "Produces " : "Turns "; + if (declaration.inputs !== undefined) { + str += formatList(Object.entries(declaration.inputs) + .map(x => formatWhole(unref(x[1].amount)) + " " + RESOURCES[x[0] as ResourceNames].name)) + " into "; + } + if (declaration.outputs !== undefined) { + str += formatList(Object.entries(declaration.outputs) + .map(x => formatWhole(unref(x[1].amount)) + " " + RESOURCES[x[0] as ResourceNames].name)) + " per tick."; + } + return str; + } + const FACTORY_COMPONENTS = { cursor: { imageSrc: _cursor, @@ -343,7 +358,7 @@ const factory = createLayer(id, () => { key: "1", name: "Wood Machine", type: "processor", - description: "Produces 1 wood per tick.", + description: computed(() => generateComponentDescription(FACTORY_COMPONENTS.wood)), energyCost: 10, tick: 1, outputs: { @@ -358,7 +373,7 @@ const factory = createLayer(id, () => { key: "2", name: "Cloth Machine", type: "processor", - description: "Produces 1 cloth per tick.", + description: computed(() => generateComponentDescription(FACTORY_COMPONENTS.cloth)), energyCost: 10, tick: 1, outputs: { @@ -373,7 +388,7 @@ const factory = createLayer(id, () => { key: "3", name: "Dye Machine", type: "processor", - description: "Produces 1 dye per tick.", + description: computed(() => generateComponentDescription(FACTORY_COMPONENTS.dye)), energyCost: 10, tick: 1, outputs: { @@ -388,7 +403,7 @@ const factory = createLayer(id, () => { key: "4", name: "Metal Machine", type: "processor", - description: "Produces 1 metal per tick.", + description: computed(() => generateComponentDescription(FACTORY_COMPONENTS.metal)), energyCost: 10, tick: 1, outputs: { @@ -403,7 +418,7 @@ const factory = createLayer(id, () => { key: "5", name: "Plastic Machine", type: "processor", - description: "Produces 1 plastic per tick.", + description: computed(() => generateComponentDescription(FACTORY_COMPONENTS.plastic)), energyCost: 10, tick: 1, outputs: { @@ -417,7 +432,7 @@ const factory = createLayer(id, () => { key: "shift+1", name: "Sawmill", type: "processor", - description: "Turns 1 wood into 1 plank per tick.", + description: computed(() => generateComponentDescription(FACTORY_COMPONENTS.plank)), energyCost: 2, tick: 1, inputs: { @@ -436,7 +451,7 @@ const factory = createLayer(id, () => { key: "shift+2", name: "Thread Spinner", type: "processor", - description: "Turns 1 cloth into 1 thread per tick.", + description: computed(() => generateComponentDescription(FACTORY_COMPONENTS.thread)), energyCost: 2, tick: 1, inputs: { @@ -455,13 +470,7 @@ const factory = createLayer(id, () => { key: "shift+3", name: "Wheel Crafter", type: "processor", - // TODO construct descriptions dynamically better - description: computed( - () => - `Turns 1 plastic into ${ - toys.milestones.milestone5.earned.value ? "2 wheels" : "1 wheel" - } per tick.` - ), + description: computed(() => generateComponentDescription(FACTORY_COMPONENTS.wheel)), energyCost: 2, tick: 1, inputs: { @@ -480,7 +489,7 @@ const factory = createLayer(id, () => { key: "shift+4", name: "Button Maker", type: "processor", - description: "Turns 1 plastic into 2 buttons every second.", + description: computed(() => generateComponentDescription(FACTORY_COMPONENTS.button)), energyCost: 2, tick: 1, inputs: { @@ -500,7 +509,7 @@ const factory = createLayer(id, () => { key: "shift+5", name: "Cloth Shredder", type: "processor", - description: "Turns 1 cloth into 1 stuffing every second.", + description: computed(() => generateComponentDescription(FACTORY_COMPONENTS.stuffing)), energyCost: 2, tick: 1, inputs: { @@ -520,7 +529,7 @@ const factory = createLayer(id, () => { key: "shift+6", name: "Shovel Maker", type: "processor", - description: "Turns 2 plastic into 1 shovel every second.", + description: computed(() => generateComponentDescription(FACTORY_COMPONENTS.shovel)), energyCost: 2, tick: 1, inputs: { @@ -540,7 +549,7 @@ const factory = createLayer(id, () => { key: "shift+7", name: "Bucket Maker", type: "processor", - description: "Turns 3 plastic into 1 bucket every second.", + description: computed(() => generateComponentDescription(FACTORY_COMPONENTS.bucket)), energyCost: 2, tick: 1, inputs: { @@ -560,7 +569,7 @@ const factory = createLayer(id, () => { key: "shift+8", name: "Circuit Board Manufacturer", type: "processor", - description: "Turns 1 metal and 1 plastic into 1 circuit board every second.", + description: computed(() => generateComponentDescription(FACTORY_COMPONENTS.circuitBoard)), energyCost: 2, tick: 1, inputs: { @@ -583,7 +592,7 @@ const factory = createLayer(id, () => { key: "ctrl+1", name: "Wooden Block Maker", type: "processor", - description: "Turns 1 plank into 1 wooden block per tick.", + description: computed(() => generateComponentDescription(FACTORY_COMPONENTS.blocks)), energyCost: 20, tick: 1, inputs: { @@ -603,7 +612,7 @@ const factory = createLayer(id, () => { key: "ctrl+2", name: "Clothes Maker", type: "processor", - description: "Turns 2 threads, 3 cloth, and 1 dye into 1 clothes per tick.", + description: computed(() => generateComponentDescription(FACTORY_COMPONENTS.clothes)), energyCost: 20, tick: 1, inputs: { @@ -629,7 +638,7 @@ const factory = createLayer(id, () => { key: "ctrl+3", name: "Trucks Maker", type: "processor", - description: "Turns 2 metal and 4 wheels into 1 truck per tick.", + description: computed(() => generateComponentDescription(FACTORY_COMPONENTS.trucks)), energyCost: 20, tick: 1, inputs: { @@ -652,8 +661,7 @@ const factory = createLayer(id, () => { key: "ctrl+4", name: "Teddy Bear Maker", type: "processor", - description: - "Turns 1 thread, 1 stuffing, 1 dye, and 3 buttons into 1 teddy bear every second.", + description: computed(() => generateComponentDescription(FACTORY_COMPONENTS.bear)), energyCost: 20, tick: 1, inputs: { @@ -683,7 +691,7 @@ const factory = createLayer(id, () => { key: "ctrl+5", name: "Shovel and Pail Maker", type: "processor", - description: "Turns 1 bucket and 1 shovel into 1 shovel and pail every second.", + description: computed(() => generateComponentDescription(FACTORY_COMPONENTS.bucketShovel)), energyCost: 20, tick: 1, inputs: { @@ -707,8 +715,7 @@ const factory = createLayer(id, () => { key: "ctrl+6", name: "Game Console Maker", type: "processor", - description: - "Turns 1 metal, 3 plastic, and 1 circuit board into 1 game console every second.", + description: computed(() => generateComponentDescription(FACTORY_COMPONENTS.console)), energyCost: 20, tick: 1, inputs: { @@ -730,7 +737,7 @@ const factory = createLayer(id, () => { }, visible: main.days[advancedDay - 1].opened } as FactoryComponentDeclaration - } as const; + } as Record; const RESOURCES = { // Raw resources wood: { @@ -1486,6 +1493,7 @@ const factory = createLayer(id, () => { const factoryBaseData = FACTORY_COMPONENTS[data.type]; if (factoryBaseData == undefined) return; const sheet = Assets.get(factoryBaseData.imageSrc); + const sprite = new Sprite(sheet); watchEffect(() => { @@ -1507,6 +1515,7 @@ const factory = createLayer(id, () => { ) * Math.PI) / 2; + if (factoryBaseData.extraImage != null) { const sheet = Assets.get(factoryBaseData.extraImage); const extraSprite = new Sprite(sheet); diff --git a/src/data/layers/styles/factory.css b/src/data/layers/styles/factory.css index 9a02626..7cedc3a 100644 --- a/src/data/layers/styles/factory.css +++ b/src/data/layers/styles/factory.css @@ -64,7 +64,7 @@ left: 0px; right: 0px; position: absolute; - background-color: var(--raised-background); + background-color: snow; overflow: hidden; z-index: 1; } @@ -109,7 +109,7 @@ .comp-info { position: absolute; top: 0; - right: -10px; + right: 0px; padding: 5px 10px; width: max-content; @@ -125,13 +125,14 @@ pointer-events: none; transition: transform 0.3s; - z-index: -1; + z-index: -2; } .comp-list .comp:nth-child(2n - 1) .comp-info { - right: -85px; + right: -75px; } .comp-list .comp:hover .comp-info { transform: translateX(calc(20px + 100%)); + z-index: -1; } .comp-list { @@ -159,6 +160,7 @@ position: absolute; border-right: solid 2px var(--locked); background: var(--raised-background); + box-shadow: 0 2px 10px #0007; top: 0; bottom: 0; left: 0; diff --git a/src/util/bignum.ts b/src/util/bignum.ts index 64bbeb2..1529e92 100644 --- a/src/util/bignum.ts +++ b/src/util/bignum.ts @@ -14,7 +14,8 @@ export const { formatSmall, formatLimit, invertOOM, - formatGain + formatGain, + formatList } = numberUtils; export type DecimalSource = RawDecimalSource; @@ -34,6 +35,7 @@ declare global { formatLimit: (list: [DecimalSource, string][], unit: string) => string; invertOOM: (x: DecimalSource) => Decimal; formatGain: (x: DecimalSource) => string; + formatList: (x: string[]) => string; } } window.Decimal = Decimal; @@ -48,5 +50,6 @@ window.formatSmall = formatSmall; window.formatLimit = formatLimit; window.invertOOM = invertOOM; window.formatGain = formatGain; +window.formatList = formatList; export default Decimal; diff --git a/src/util/break_eternity.ts b/src/util/break_eternity.ts index a3fc5aa..a8d83e3 100644 --- a/src/util/break_eternity.ts +++ b/src/util/break_eternity.ts @@ -219,3 +219,9 @@ export function formatGain(gain: DecimalSource) { 1: `+${format(gain)}/s` }[Decimal.compare(gain, 0)]; } + +export function formatList(list: string[]) { + if (list.length <= 0) return ""; + if (list.length == 1) return list[0]; + return list.slice(0, -1).join(", ") + " and " + list[list.length - 1]; +} From ec71587eabf25128417a8184a407a47b58ab5b1a Mon Sep 17 00:00:00 2001 From: ducdat0507 <62660527+ducdat0507@users.noreply.github.com> Date: Fri, 23 Dec 2022 20:40:31 +0700 Subject: [PATCH 08/11] NaNi? --- src/data/layers/factory.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/data/layers/factory.tsx b/src/data/layers/factory.tsx index d0b3b07..0eeda6f 100644 --- a/src/data/layers/factory.tsx +++ b/src/data/layers/factory.tsx @@ -206,7 +206,7 @@ const factory = createLayer(id, () => { createMultiplicativeModifier(() => ({ multiplier: Decimal.lt(energyEfficiency.value, 1) ? 1 - : Decimal.sub(2, Decimal.div(energyConsumption.value, computedEnergy.value)), + : Decimal.sub(2, Decimal.div(energyConsumption.value, Decimal.max(computedEnergy.value, 1))), description: "Brighter work rooms", enabled: () => upgrades[2][0].bought.value })), @@ -1387,7 +1387,6 @@ const factory = createLayer(id, () => { const now = Date.now(); const diff = (now - compData.lastFactoryProd) / 1000; compData.lastProdTimes.push(diff); - console.log(compData.lastProdTimes); if (compData.lastProdTimes.length > 10) compData.lastProdTimes.shift(); compData.lastFactoryProd = now; } From c1f6741c754c20181bb0d2df750febeacf4597d1 Mon Sep 17 00:00:00 2001 From: circle-gon <97845741+circle-gon@users.noreply.github.com> Date: Fri, 23 Dec 2022 09:28:14 -0500 Subject: [PATCH 09/11] fixes computed inputs/outputs not actually checking properly --- src/data/layers/factory.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/data/layers/factory.tsx b/src/data/layers/factory.tsx index 0eeda6f..1884ca7 100644 --- a/src/data/layers/factory.tsx +++ b/src/data/layers/factory.tsx @@ -1572,7 +1572,7 @@ const factory = createLayer(id, () => { const compData = components.value[x + "x" + y] as FactoryComponentProcessor; if (factoryBaseData.inputs !== undefined) { for (const [res, val] of Object.entries(factoryBaseData.inputs)) - if ((compData.inputStock?.[res as ResourceNames] ?? 0) < val.amount) + if ((compData.inputStock?.[res as ResourceNames] ?? 0) < unref(val.amount)) return false; } if (factoryBaseData.outputs !== undefined) { From dcabdac385e88c5836cddef5fd2cfe245dbfa264 Mon Sep 17 00:00:00 2001 From: thepaperpilot Date: Fri, 23 Dec 2022 08:48:17 -0600 Subject: [PATCH 10/11] Fixed random error I started getting about main being undefined?? --- src/components/Options.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Options.vue b/src/components/Options.vue index 657388f..08245dc 100644 --- a/src/components/Options.vue +++ b/src/components/Options.vue @@ -98,7 +98,7 @@ const isPaused = computed({ }); const canAutoSave = computed( - () => (layers as any).main.days[(layers as any).main.day.value - 1].opened.value + () => (layers as any).main?.days[(layers as any).main?.day.value - 1].opened.value ); const autosaveTitle = jsx(() => ( From d43899e938237bec2f1a2471b3fe1d37d4e204d4 Mon Sep 17 00:00:00 2001 From: thepaperpilot Date: Fri, 23 Dec 2022 08:55:36 -0600 Subject: [PATCH 11/11] Fix build errors --- src/data/layers/factory.tsx | 66 +++++++++++++++++++++++++++---------- 1 file changed, 49 insertions(+), 17 deletions(-) diff --git a/src/data/layers/factory.tsx b/src/data/layers/factory.tsx index 1884ca7..f7f6b51 100644 --- a/src/data/layers/factory.tsx +++ b/src/data/layers/factory.tsx @@ -206,7 +206,10 @@ const factory = createLayer(id, () => { createMultiplicativeModifier(() => ({ multiplier: Decimal.lt(energyEfficiency.value, 1) ? 1 - : Decimal.sub(2, Decimal.div(energyConsumption.value, Decimal.max(computedEnergy.value, 1))), + : Decimal.sub( + 2, + Decimal.div(energyConsumption.value, Decimal.max(computedEnergy.value, 1)) + ), description: "Brighter work rooms", enabled: () => upgrades[2][0].bought.value })), @@ -287,17 +290,29 @@ const factory = createLayer(id, () => { // ---------------------------------------------- Components - function generateComponentDescription(declaration: FactoryComponentDeclaration) { - let str = declaration.inputs === undefined ? "Produces " : "Turns "; if (declaration.inputs !== undefined) { - str += formatList(Object.entries(declaration.inputs) - .map(x => formatWhole(unref(x[1].amount)) + " " + RESOURCES[x[0] as ResourceNames].name)) + " into "; + str += + formatList( + Object.entries(declaration.inputs).map( + x => + formatWhole(unref(x[1].amount)) + + " " + + RESOURCES[x[0] as ResourceNames].name + ) + ) + " into "; } if (declaration.outputs !== undefined) { - str += formatList(Object.entries(declaration.outputs) - .map(x => formatWhole(unref(x[1].amount)) + " " + RESOURCES[x[0] as ResourceNames].name)) + " per tick."; + str += + formatList( + Object.entries(declaration.outputs).map( + x => + formatWhole(unref(x[1].amount)) + + " " + + RESOURCES[x[0] as ResourceNames].name + ) + ) + " per tick."; } return str; } @@ -569,7 +584,9 @@ const factory = createLayer(id, () => { key: "shift+8", name: "Circuit Board Manufacturer", type: "processor", - description: computed(() => generateComponentDescription(FACTORY_COMPONENTS.circuitBoard)), + description: computed(() => + generateComponentDescription(FACTORY_COMPONENTS.circuitBoard) + ), energyCost: 2, tick: 1, inputs: { @@ -691,7 +708,9 @@ const factory = createLayer(id, () => { key: "ctrl+5", name: "Shovel and Pail Maker", type: "processor", - description: computed(() => generateComponentDescription(FACTORY_COMPONENTS.bucketShovel)), + description: computed(() => + generateComponentDescription(FACTORY_COMPONENTS.bucketShovel) + ), energyCost: 20, tick: 1, inputs: { @@ -1548,7 +1567,11 @@ const factory = createLayer(id, () => { lastProdTimes: !isConveyor ? (reactive([]) as number[]) : undefined, lastFactoryProd: !isConveyor ? Date.now() - - 1000 * Decimal.div(data.ticksDone ?? 0, computedActualTickRate.value).toNumber() + 1000 * + Decimal.div( + (data as FactoryComponentProcessor).ticksDone ?? 0, + computedActualTickRate.value + ).toNumber() : undefined, average: !isConveyor ? computed(() => { @@ -1914,32 +1937,41 @@ const factory = createLayer(id, () => { compInternalHovered.value.type !== "conveyor" ? ( <> {showStockAmount( - compHovered.value.inputStock, + (compHovered.value as FactoryComponentProcessor).inputStock, FACTORY_COMPONENTS[compHovered.value.type].inputs, "Inputs:" )} {showStockAmount( - compHovered.value.outputStock, + (compHovered.value as FactoryComponentProcessor).outputStock, FACTORY_COMPONENTS[compHovered.value.type].outputs, "Outputs:", false )}
Efficency:{" "} - {compInternalHovered.value.average.value !== undefined ? ( + {(compInternalHovered.value as FactoryInternalProcessor).average.value !== + undefined ? ( 1 + (compInternalHovered.value as FactoryInternalProcessor) + .average.value! > 1 ? "purple" - : compInternalHovered.value.average.value >= 0.9 + : ( + compInternalHovered.value as FactoryInternalProcessor + ).average.value! >= 0.9 ? "green" - : compInternalHovered.value.average.value >= 0.5 + : ( + compInternalHovered.value as FactoryInternalProcessor + ).average.value! >= 0.5 ? "yellow" : "red" }} > - {formatWhole(compInternalHovered.value.average.value * 100)} + {formatWhole( + (compInternalHovered.value as FactoryInternalProcessor).average + .value! * 100 + )} ) : ( "--"