mirror of
https://github.com/thepaperpilot/Advent-Incremental.git
synced 2024-11-24 01:11:49 +00:00
adds efficency display
This commit is contained in:
parent
7c06c1972b
commit
255ecea3e1
1 changed files with 67 additions and 14 deletions
|
@ -29,8 +29,8 @@ import { noPersist, Persistent, persistent, State } from "game/persistence";
|
||||||
import Decimal, { DecimalSource, format, formatWhole } from "util/bignum";
|
import Decimal, { DecimalSource, format, formatWhole } from "util/bignum";
|
||||||
import { Direction } from "util/common";
|
import { Direction } from "util/common";
|
||||||
import { ProcessedComputable } from "util/computed";
|
import { ProcessedComputable } from "util/computed";
|
||||||
import { render, renderRow } from "util/vue";
|
import { render, renderRow, VueFeature } from "util/vue";
|
||||||
import { computed, ComputedRef, reactive, ref, unref, watchEffect } from "vue";
|
import { computed, ComputedRef, reactive, ref, shallowRef, unref, watchEffect } from "vue";
|
||||||
import coal from "./coal";
|
import coal from "./coal";
|
||||||
import _block from "./factory-components/block.svg";
|
import _block from "./factory-components/block.svg";
|
||||||
import _blockMaker from "./factory-components/blockmaker.svg";
|
import _blockMaker from "./factory-components/blockmaker.svg";
|
||||||
|
@ -601,6 +601,10 @@ const factory = createLayer(id, () => {
|
||||||
}
|
}
|
||||||
interface FactoryInternalProcessor extends FactoryInternalBase {
|
interface FactoryInternalProcessor extends FactoryInternalBase {
|
||||||
type: Exclude<BuildableCompName, "conveyor">;
|
type: Exclude<BuildableCompName, "conveyor">;
|
||||||
|
lastProdTimes: number[];
|
||||||
|
|
||||||
|
lastFactoryProd: number;
|
||||||
|
average: ComputedRef<number | undefined>;
|
||||||
}
|
}
|
||||||
type FactoryInternal = FactoryInternalConveyor | FactoryInternalProcessor;
|
type FactoryInternal = FactoryInternalConveyor | FactoryInternalProcessor;
|
||||||
|
|
||||||
|
@ -743,9 +747,6 @@ const factory = createLayer(id, () => {
|
||||||
loaded = true;
|
loaded = true;
|
||||||
watchEffect(updateGraphics);
|
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) {
|
function moveBlock(block: Block, newBlock: FactoryInternal, blockData: FactoryComponent) {
|
||||||
// empty spot
|
// empty spot
|
||||||
|
@ -865,6 +866,12 @@ const factory = createLayer(id, () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
data.ticksDone -= cyclesDone * factoryData.tick;
|
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 {
|
} else {
|
||||||
data.ticksDone += factoryTicks;
|
data.ticksDone += factoryTicks;
|
||||||
|
@ -1009,6 +1016,26 @@ const factory = createLayer(id, () => {
|
||||||
type: data.type,
|
type: data.type,
|
||||||
packages: isConveyor ? [] : undefined,
|
packages: isConveyor ? [] : undefined,
|
||||||
nextPackages: 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(() => {
|
canProduce: computed(() => {
|
||||||
if (data.type === "conveyor") return true;
|
if (data.type === "conveyor") return true;
|
||||||
if (!(factoryBaseData.canProduce?.value ?? true)) return false;
|
if (!(factoryBaseData.canProduce?.value ?? true)) return false;
|
||||||
|
@ -1088,6 +1115,7 @@ const factory = createLayer(id, () => {
|
||||||
const pointerDown = ref(false),
|
const pointerDown = ref(false),
|
||||||
pointerDrag = ref(false),
|
pointerDrag = ref(false),
|
||||||
compHovered = ref<FactoryComponent | undefined>(undefined),
|
compHovered = ref<FactoryComponent | undefined>(undefined),
|
||||||
|
compInternalHovered = shallowRef<FactoryInternal | undefined>(undefined),
|
||||||
paused = ref(false);
|
paused = ref(false);
|
||||||
|
|
||||||
function onFactoryPointerMove(e: PointerEvent) {
|
function onFactoryPointerMove(e: PointerEvent) {
|
||||||
|
@ -1117,12 +1145,12 @@ const factory = createLayer(id, () => {
|
||||||
}
|
}
|
||||||
if (!pointerDown.value && !pointerDrag.value) {
|
if (!pointerDown.value && !pointerDrag.value) {
|
||||||
const { tx, ty } = spriteContainer.localTransform;
|
const { tx, ty } = spriteContainer.localTransform;
|
||||||
compHovered.value =
|
const xyPos =
|
||||||
components.value[
|
Math.round(roundDownTo(x - tx, blockSize) / blockSize) +
|
||||||
Math.round(roundDownTo(x - tx, blockSize) / blockSize) +
|
"x" +
|
||||||
"x" +
|
Math.round(roundDownTo(y - ty, blockSize) / blockSize);
|
||||||
Math.round(roundDownTo(y - ty, blockSize) / blockSize)
|
compHovered.value = components.value[xyPos];
|
||||||
];
|
compInternalHovered.value = compInternalData[xyPos];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function onFactoryPointerDown(e: PointerEvent) {
|
function onFactoryPointerDown(e: PointerEvent) {
|
||||||
|
@ -1217,6 +1245,7 @@ const factory = createLayer(id, () => {
|
||||||
cComp.packages = [];
|
cComp.packages = [];
|
||||||
} else {
|
} else {
|
||||||
const producerComp = components.value[key] as FactoryComponentProcessor;
|
const producerComp = components.value[key] as FactoryComponentProcessor;
|
||||||
|
const cComp = comp as FactoryInternalProcessor;
|
||||||
if (producerComp.outputStock !== undefined) {
|
if (producerComp.outputStock !== undefined) {
|
||||||
for (const key in producerComp.outputStock) {
|
for (const key in producerComp.outputStock) {
|
||||||
delete producerComp.outputStock[key as ResourceNames];
|
delete producerComp.outputStock[key as ResourceNames];
|
||||||
|
@ -1228,6 +1257,8 @@ const factory = createLayer(id, () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
producerComp.ticksDone = 0;
|
producerComp.ticksDone = 0;
|
||||||
|
cComp.lastFactoryProd = Date.now();
|
||||||
|
cComp.lastProdTimes.splice(0, Infinity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1339,7 +1370,7 @@ const factory = createLayer(id, () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const hoveredComponent = jsx(() =>
|
const hoveredComponent = jsx(() =>
|
||||||
compHovered.value !== undefined ? (
|
compHovered.value !== undefined && compInternalHovered.value !== undefined ? (
|
||||||
<div
|
<div
|
||||||
class="info-container"
|
class="info-container"
|
||||||
id="factory-info"
|
id="factory-info"
|
||||||
|
@ -1360,7 +1391,8 @@ const factory = createLayer(id, () => {
|
||||||
<br />
|
<br />
|
||||||
{unref(FACTORY_COMPONENTS[compHovered.value.type].description)}
|
{unref(FACTORY_COMPONENTS[compHovered.value.type].description)}
|
||||||
<br />
|
<br />
|
||||||
{compHovered.value.type !== "conveyor" ? (
|
{compHovered.value.type !== "conveyor" &&
|
||||||
|
compInternalHovered.value.type !== "conveyor" ? (
|
||||||
<>
|
<>
|
||||||
{showStockAmount(
|
{showStockAmount(
|
||||||
compHovered.value.inputStock,
|
compHovered.value.inputStock,
|
||||||
|
@ -1373,6 +1405,27 @@ const factory = createLayer(id, () => {
|
||||||
"Outputs:",
|
"Outputs:",
|
||||||
false
|
false
|
||||||
)}
|
)}
|
||||||
|
<br />
|
||||||
|
Efficency:{" "}
|
||||||
|
{compInternalHovered.value.average.value !== undefined ? (
|
||||||
|
<span
|
||||||
|
style={{
|
||||||
|
color:
|
||||||
|
compInternalHovered.value.average.value > 1
|
||||||
|
? "purple"
|
||||||
|
: compInternalHovered.value.average.value >= 0.9
|
||||||
|
? "green"
|
||||||
|
: compInternalHovered.value.average.value >= 0.5
|
||||||
|
? "yellow"
|
||||||
|
: "red"
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{formatWhole(compInternalHovered.value.average.value * 100)}
|
||||||
|
</span>
|
||||||
|
) : (
|
||||||
|
"--"
|
||||||
|
)}
|
||||||
|
%
|
||||||
</>
|
</>
|
||||||
) : undefined}
|
) : undefined}
|
||||||
</div>
|
</div>
|
||||||
|
@ -1533,7 +1586,7 @@ const factory = createLayer(id, () => {
|
||||||
display: jsx(() => (
|
display: jsx(() => (
|
||||||
<>
|
<>
|
||||||
{render(modifiersModal)}
|
{render(modifiersModal)}
|
||||||
{render(tabs)}
|
{render(tabs as VueFeature)}
|
||||||
</>
|
</>
|
||||||
))
|
))
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue