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