1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2025-06-13 13:04:03 +00:00
tobspr_shapez.io/src/js/game/systems/item_producer.js
Greg Considine 212ea67125 [WIP] Add building, component, and systems for producing and
accepting user-specified items and checking goal criteria
2021-03-23 19:53:52 -04:00

38 lines
1.1 KiB
JavaScript

/* typehints:start */
import { GameRoot } from "../root";
/* typehints:end */
import { ItemProducerComponent } from "../components/item_producer";
import { GameSystemWithFilter } from "../game_system_with_filter";
export class ItemProducerSystem extends GameSystemWithFilter {
/** @param {GameRoot} root */
constructor(root) {
super(root, [ItemProducerComponent]);
this.item = null;
}
update() {
for (let i = 0; i < this.allEntities.length; ++i) {
const entity = this.allEntities[i];
const producerComp = entity.components.ItemProducer;
const ejectorComp = entity.components.ItemEjector;
if (producerComp.isWireless()) {
continue;
}
const pinsComp = entity.components.WiredPins;
const pin = pinsComp.slots[0];
const network = pin.linkedNetwork;
if (!network || !network.hasValue()) {
continue;
}
this.item = network.currentValue;
ejectorComp.tryEject(0, this.item);
}
}
}