You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
2.1 KiB
61 lines
2.1 KiB
import { globalConfig } from "../../core/config";
|
|
import { DrawParameters } from "../../core/draw_parameters";
|
|
import { Vector } from "../../core/vector";
|
|
import { ConstantSignalComponent } from "../components/constant_signal";
|
|
import { ItemProducerComponent } from "../components/item_producer";
|
|
import { GameSystemWithFilter } from "../game_system_with_filter";
|
|
import { MapChunk } from "../map_chunk";
|
|
|
|
export class ConstantProducerSystem extends GameSystemWithFilter {
|
|
constructor(root) {
|
|
super(root, [ConstantSignalComponent, ItemProducerComponent]);
|
|
}
|
|
|
|
update() {
|
|
for (let i = 0; i < this.allEntities.length; ++i) {
|
|
const entity = this.allEntities[i];
|
|
const signalComp = entity.components.ConstantSignal;
|
|
const ejectorComp = entity.components.ItemEjector;
|
|
if (!ejectorComp) {
|
|
continue;
|
|
}
|
|
ejectorComp.tryEject(0, signalComp.signal);
|
|
}
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param {DrawParameters} parameters
|
|
* @param {MapChunk} chunk
|
|
* @returns
|
|
*/
|
|
drawChunk(parameters, chunk) {
|
|
const contents = chunk.containedEntitiesByLayer.regular;
|
|
for (let i = 0; i < contents.length; ++i) {
|
|
const producerComp = contents[i].components.ItemProducer;
|
|
const signalComp = contents[i].components.ConstantSignal;
|
|
|
|
if (!producerComp || !signalComp) {
|
|
continue;
|
|
}
|
|
|
|
const staticComp = contents[i].components.StaticMapEntity;
|
|
const item = signalComp.signal;
|
|
|
|
if (!item) {
|
|
continue;
|
|
}
|
|
|
|
const center = staticComp.getTileSpaceBounds().getCenter().toWorldSpace();
|
|
|
|
const localOffset = new Vector(0, 1).rotateFastMultipleOf90(staticComp.rotation);
|
|
item.drawItemCenteredClipped(
|
|
center.x + localOffset.x,
|
|
center.y + localOffset.y,
|
|
parameters,
|
|
globalConfig.tileSize * 0.65
|
|
);
|
|
}
|
|
}
|
|
}
|