1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2026-03-02 03:39:21 +00:00

Add belt reader building

This commit is contained in:
tobspr
2020-08-29 10:38:23 +02:00
parent bb739c80fa
commit 06e276f021
28 changed files with 1397 additions and 1069 deletions

View File

@@ -0,0 +1,40 @@
import { GameSystemWithFilter } from "../game_system_with_filter";
import { BeltReaderComponent } from "../components/belt_reader";
import { globalConfig } from "../../core/config";
import { BOOL_TRUE_SINGLETON, BOOL_FALSE_SINGLETON } from "../items/boolean_item";
export class BeltReaderSystem extends GameSystemWithFilter {
constructor(root) {
super(root, [BeltReaderComponent]);
}
update() {
const now = this.root.time.now();
const minimumTime = now - globalConfig.readerAnalyzeIntervalSeconds;
const minimumTimeForThroughput = now - 1;
for (let i = 0; i < this.allEntities.length; ++i) {
const entity = this.allEntities[i];
const readerComp = entity.components.BeltReader;
const pinsComp = entity.components.WiredPins;
// Remove outdated items
while (readerComp.lastItemTimes[0] < minimumTime) {
readerComp.lastItemTimes.shift();
}
pinsComp.slots[1].value = readerComp.lastItem;
pinsComp.slots[0].value =
(readerComp.lastItemTimes[readerComp.lastItemTimes.length - 1] || 0) >
minimumTimeForThroughput
? BOOL_TRUE_SINGLETON
: BOOL_FALSE_SINGLETON;
if (now - readerComp.lastThroughputComputation > 0.5) {
readerComp.lastThroughputComputation = now;
readerComp.lastThroughput =
readerComp.lastItemTimes.length / globalConfig.readerAnalyzeIntervalSeconds;
}
}
}
}