34 lines
1.2 KiB
JavaScript
34 lines
1.2 KiB
JavaScript
import { STOP_PROPAGATION } from "../../../core/signal";
|
|
import { Vector } from "../../../core/vector";
|
|
import { enumMouseButton } from "../../camera";
|
|
import { BaseHUDPart } from "../base_hud_part";
|
|
|
|
export class HUDConstantSignalEdit extends BaseHUDPart {
|
|
initialize() {
|
|
this.root.camera.downPreHandler.add(this.downPreHandler, this);
|
|
}
|
|
|
|
/**
|
|
* @param {Vector} pos
|
|
* @param {enumMouseButton} button
|
|
*/
|
|
downPreHandler(pos, button) {
|
|
const tile = this.root.camera.screenToWorld(pos).toTileSpace();
|
|
const contents = this.root.map.getLayerContentXY(tile.x, tile.y, "wires");
|
|
if (contents) {
|
|
const constantComp = contents.components.ConstantSignal;
|
|
if (constantComp) {
|
|
if (button === enumMouseButton.left) {
|
|
this.root.systemMgr.systems.constantSignal.editConstantSignal(contents, {
|
|
deleteOnCancel: false,
|
|
});
|
|
return STOP_PROPAGATION;
|
|
} else if (button === enumMouseButton.right) {
|
|
this.root.logic.tryDeleteBuilding(contents);
|
|
return STOP_PROPAGATION;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|