mirror of
https://github.com/thepaperpilot/Advent-Incremental.git
synced 2024-11-21 16:13:57 +00:00
Implement energy that affects factory tick rate
This commit is contained in:
parent
ef4c0b606d
commit
7cbbf732fc
1 changed files with 23 additions and 4 deletions
|
@ -8,7 +8,7 @@ import { globalBus } from "game/events";
|
|||
import { createLayer } from "game/layers";
|
||||
import { Persistent, persistent, State } from "game/persistence";
|
||||
import player from "game/player";
|
||||
import { formatWhole } from "util/bignum";
|
||||
import Decimal, { formatWhole } from "util/bignum";
|
||||
import { Direction } from "util/common";
|
||||
import { computed, ComputedRef, reactive, ref, watchEffect } from "vue";
|
||||
import conveyor from "./factory-components/conveyor.png";
|
||||
|
@ -75,6 +75,16 @@ const factory = createLayer(id, () => {
|
|||
const name = "The Factory";
|
||||
const color = "grey";
|
||||
|
||||
const energy = computed(() => 100);
|
||||
const energyConsumption = computed(() =>
|
||||
Object.values(components.value)
|
||||
.map(c => FACTORY_COMPONENTS[c.type].energyCost ?? 0)
|
||||
.reduce((a, b) => a + b, 0)
|
||||
);
|
||||
const tickRate = computed(() =>
|
||||
Decimal.div(energyConsumption.value, energy.value).pow(2).min(1)
|
||||
);
|
||||
|
||||
// ---------------------------------------------- Components
|
||||
|
||||
const FACTORY_COMPONENTS = {
|
||||
|
@ -94,6 +104,7 @@ const factory = createLayer(id, () => {
|
|||
imageSrc: conveyor,
|
||||
name: "Conveyor",
|
||||
description: "Moves items at 1 block per second.",
|
||||
energyCost: 1,
|
||||
tick: 1,
|
||||
ports: {
|
||||
[Direction.Left]: {
|
||||
|
@ -108,6 +119,7 @@ const factory = createLayer(id, () => {
|
|||
imageSrc: square,
|
||||
name: "Producer",
|
||||
description: "Produces 1 square every 1 second.",
|
||||
energyCost: 10,
|
||||
tick: 1,
|
||||
outputs: {
|
||||
square: {
|
||||
|
@ -131,6 +143,7 @@ const factory = createLayer(id, () => {
|
|||
name: "Shrinker",
|
||||
description:
|
||||
"Converts 100 squares to 1 square. I don't know why you would want to do this but here you go anyways.",
|
||||
energyCost: 20,
|
||||
tick: 1,
|
||||
inputs: {
|
||||
square: {
|
||||
|
@ -178,6 +191,7 @@ const factory = createLayer(id, () => {
|
|||
imageSrc: string;
|
||||
name: string;
|
||||
description: string;
|
||||
energyCost?: number;
|
||||
|
||||
/** amount it consumes */
|
||||
inputs?: Record<
|
||||
|
@ -308,6 +322,9 @@ const factory = createLayer(id, () => {
|
|||
|
||||
globalBus.on("update", diff => {
|
||||
if (!loaded) return;
|
||||
|
||||
const factoryTicks = tickRate.value.times(diff).toNumber();
|
||||
|
||||
//debugger
|
||||
// make them produce
|
||||
for (const id in components.value) {
|
||||
|
@ -361,7 +378,8 @@ const factory = createLayer(id, () => {
|
|||
key--;
|
||||
} else {
|
||||
const change =
|
||||
dirAmt * Math.min(Math.abs(x + 1.3 * dirAmt - block.x), diff);
|
||||
dirAmt *
|
||||
Math.min(Math.abs(x + 1.3 * dirAmt - block.x), factoryTicks);
|
||||
block.x += change;
|
||||
block.sprite.x += change * blockSize;
|
||||
}
|
||||
|
@ -395,7 +413,8 @@ const factory = createLayer(id, () => {
|
|||
key--;
|
||||
} else {
|
||||
const change =
|
||||
dirAmt * Math.min(Math.abs(y + 1.3 * dirAmt - block.y), diff);
|
||||
dirAmt *
|
||||
Math.min(Math.abs(y + 1.3 * dirAmt - block.y), factoryTicks);
|
||||
block.y += change;
|
||||
block.sprite.y += change * blockSize;
|
||||
}
|
||||
|
@ -425,7 +444,7 @@ const factory = createLayer(id, () => {
|
|||
data.ticksDone -= cyclesDone * factoryData.tick;
|
||||
}
|
||||
} else {
|
||||
data.ticksDone += diff;
|
||||
data.ticksDone += factoryTicks;
|
||||
}
|
||||
// now look at each component direction and see if it accepts items coming in
|
||||
// components are 1x1 so simple math for now
|
||||
|
|
Loading…
Reference in a new issue