mirror of
https://github.com/tobspr/shapez.io.git
synced 2024-10-27 20:34:29 +00:00
Add ability to edit constant signals, bump version
This commit is contained in:
parent
4b088980f3
commit
82aaf7f037
@ -1,4 +1,9 @@
|
||||
export const CHANGELOG = [
|
||||
{
|
||||
version: "1.2.2",
|
||||
date: "07.12.2020",
|
||||
entries: ["Added the ability to edit constant signals by left clicking them"],
|
||||
},
|
||||
{
|
||||
version: "1.2.1",
|
||||
date: "31.10.2020",
|
||||
|
@ -48,6 +48,7 @@ import { HUDBetaOverlay } from "./parts/beta_overlay";
|
||||
import { HUDStandaloneAdvantages } from "./parts/standalone_advantages";
|
||||
import { HUDCatMemes } from "./parts/cat_memes";
|
||||
import { HUDTutorialVideoOffer } from "./parts/tutorial_video_offer";
|
||||
import { HUDConstantSignalEdit } from "./parts/constant_signal_edit";
|
||||
|
||||
export class GameHUD {
|
||||
/**
|
||||
@ -86,6 +87,7 @@ export class GameHUD {
|
||||
waypoints: new HUDWaypoints(this.root),
|
||||
wireInfo: new HUDWireInfo(this.root),
|
||||
leverToggle: new HUDLeverToggle(this.root),
|
||||
constantSignalEdit: new HUDConstantSignalEdit(this.root),
|
||||
|
||||
// Must always exist
|
||||
pinnedShapes: new HUDPinnedShapes(this.root),
|
||||
|
33
src/js/game/hud/parts/constant_signal_edit.js
Normal file
33
src/js/game/hud/parts/constant_signal_edit.js
Normal file
@ -0,0 +1,33 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -17,7 +17,9 @@ export class ConstantSignalSystem extends GameSystemWithFilter {
|
||||
constructor(root) {
|
||||
super(root, [ConstantSignalComponent]);
|
||||
|
||||
this.root.signals.entityManuallyPlaced.add(this.querySigalValue, this);
|
||||
this.root.signals.entityManuallyPlaced.add(entity =>
|
||||
this.editConstantSignal(entity, { deleteOnCancel: true })
|
||||
);
|
||||
}
|
||||
|
||||
update() {
|
||||
@ -33,8 +35,10 @@ export class ConstantSignalSystem extends GameSystemWithFilter {
|
||||
/**
|
||||
* Asks the entity to enter a valid signal code
|
||||
* @param {Entity} entity
|
||||
* @param {object} param0
|
||||
* @param {boolean=} param0.deleteOnCancel
|
||||
*/
|
||||
querySigalValue(entity) {
|
||||
editConstantSignal(entity, { deleteOnCancel = true }) {
|
||||
if (!entity.components.ConstantSignal) {
|
||||
return;
|
||||
}
|
||||
@ -110,26 +114,28 @@ export class ConstantSignalSystem extends GameSystemWithFilter {
|
||||
dialog.valueChosen.add(closeHandler);
|
||||
|
||||
// When cancelled, destroy the entity again
|
||||
dialog.buttonSignals.cancel.add(() => {
|
||||
if (!this.root || !this.root.entityMgr) {
|
||||
// Game got stopped
|
||||
return;
|
||||
}
|
||||
if (deleteOnCancel) {
|
||||
dialog.buttonSignals.cancel.add(() => {
|
||||
if (!this.root || !this.root.entityMgr) {
|
||||
// Game got stopped
|
||||
return;
|
||||
}
|
||||
|
||||
const entityRef = this.root.entityMgr.findByUid(uid, false);
|
||||
if (!entityRef) {
|
||||
// outdated
|
||||
return;
|
||||
}
|
||||
const entityRef = this.root.entityMgr.findByUid(uid, false);
|
||||
if (!entityRef) {
|
||||
// outdated
|
||||
return;
|
||||
}
|
||||
|
||||
const constantComp = entityRef.components.ConstantSignal;
|
||||
if (!constantComp) {
|
||||
// no longer interesting
|
||||
return;
|
||||
}
|
||||
const constantComp = entityRef.components.ConstantSignal;
|
||||
if (!constantComp) {
|
||||
// no longer interesting
|
||||
return;
|
||||
}
|
||||
|
||||
this.root.logic.tryDeleteBuilding(entityRef);
|
||||
});
|
||||
this.root.logic.tryDeleteBuilding(entityRef);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user