2020-06-28 17:34:10 +00:00
|
|
|
import { globalConfig } from "../../core/config";
|
2020-06-24 20:23:10 +00:00
|
|
|
import { DrawParameters } from "../../core/draw_parameters";
|
2020-06-28 17:34:10 +00:00
|
|
|
import { WiredPinsComponent, enumPinSlotType } from "../components/wired_pins";
|
2020-06-24 20:23:10 +00:00
|
|
|
import { Entity } from "../entity";
|
2020-06-28 17:34:10 +00:00
|
|
|
import { GameSystemWithFilter } from "../game_system_with_filter";
|
|
|
|
import { MapChunkView } from "../map_chunk_view";
|
2020-06-28 09:44:30 +00:00
|
|
|
import { Loader } from "../../core/loader";
|
2020-06-24 20:23:10 +00:00
|
|
|
|
|
|
|
export class WiredPinsSystem extends GameSystemWithFilter {
|
|
|
|
constructor(root) {
|
|
|
|
super(root, [WiredPinsComponent]);
|
2020-06-28 09:44:30 +00:00
|
|
|
|
|
|
|
this.pinSprites = {
|
2020-06-28 17:34:10 +00:00
|
|
|
[enumPinSlotType.positiveEnergyEjector]: Loader.getSprite(
|
|
|
|
"sprites/wires/pin-positive-energy.png"
|
|
|
|
),
|
|
|
|
[enumPinSlotType.negativeEnergyAcceptor]: Loader.getSprite(
|
|
|
|
"sprites/wires/pin-negative-energy.png"
|
|
|
|
),
|
2020-06-28 09:44:30 +00:00
|
|
|
};
|
2020-06-24 20:23:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
update() {
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
2020-06-28 17:34:10 +00:00
|
|
|
/**
|
|
|
|
* Draws the given layer
|
|
|
|
* @param {DrawParameters} parameters
|
|
|
|
*/
|
|
|
|
draw(parameters) {
|
|
|
|
this.forEachMatchingEntityOnScreen(parameters, this.drawSingleEntity.bind(this));
|
2020-06-24 20:23:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-06-28 17:34:10 +00:00
|
|
|
* Draws a given chunk
|
2020-06-24 20:23:10 +00:00
|
|
|
* @param {DrawParameters} parameters
|
|
|
|
* @param {Entity} entity
|
|
|
|
*/
|
2020-06-28 17:34:10 +00:00
|
|
|
drawSingleEntity(parameters, entity) {
|
2020-06-24 20:23:10 +00:00
|
|
|
const staticComp = entity.components.StaticMapEntity;
|
2020-06-28 17:34:10 +00:00
|
|
|
const slots = entity.components.WiredPins.slots;
|
2020-06-24 20:23:10 +00:00
|
|
|
|
|
|
|
for (let i = 0; i < slots.length; ++i) {
|
|
|
|
const slot = slots[i];
|
|
|
|
const tile = staticComp.localTileToWorld(slot.pos);
|
|
|
|
|
|
|
|
const worldPos = tile.toWorldSpaceCenterOfTile();
|
|
|
|
|
2020-06-28 17:34:10 +00:00
|
|
|
this.pinSprites[slot.type].drawCachedCentered(
|
2020-06-28 09:44:30 +00:00
|
|
|
parameters,
|
|
|
|
worldPos.x,
|
|
|
|
worldPos.y,
|
|
|
|
globalConfig.tileSize
|
|
|
|
);
|
2020-06-24 20:23:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|