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:
40
src/js/game/systems/belt_reader.js
Normal file
40
src/js/game/systems/belt_reader.js
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user