2021-03-22 14:21:20 +00:00
|
|
|
/* typehints:start */
|
|
|
|
import { GameRoot } from "../root";
|
|
|
|
/* typehints:end */
|
|
|
|
|
|
|
|
import { enumItemProducerType, 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]);
|
|
|
|
}
|
|
|
|
|
|
|
|
update() {
|
|
|
|
for (let i = 0; i < this.allEntities.length; ++i) {
|
|
|
|
const entity = this.allEntities[i];
|
|
|
|
|
2021-03-22 14:21:20 +00:00
|
|
|
if (entity.components.ItemProducer.type === enumItemProducerType.wired) {
|
|
|
|
const pinsComp = entity.components.WiredPins;
|
|
|
|
const pin = pinsComp.slots[0];
|
|
|
|
const network = pin.linkedNetwork;
|
2020-09-29 08:52:25 +00:00
|
|
|
|
2021-03-22 14:21:20 +00:00
|
|
|
if (!network || !network.hasValue()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
const ejectorComp = entity.components.ItemEjector;
|
|
|
|
ejectorComp.tryEject(0, network.currentValue);
|
|
|
|
} else {
|
|
|
|
// TODO: entity w/ wireless item producer (e.g. ConstantProducer)
|
|
|
|
}
|
2020-09-29 08:52:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|