Allow copying wire values
This commit is contained in:
parent
7ed36daac0
commit
d5f7a78386
Binary file not shown.
|
@ -28,6 +28,15 @@ export class BaseItem extends BasicSerializableObject {
|
||||||
return "shape";
|
return "shape";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a string id of the item
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
getAsCopyableKey() {
|
||||||
|
abstract;
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns if the item equals the other itme
|
* Returns if the item equals the other itme
|
||||||
* @param {BaseItem} other
|
* @param {BaseItem} other
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
|
import { globalConfig } from "../core/config";
|
||||||
import { DrawParameters } from "../core/draw_parameters";
|
import { DrawParameters } from "../core/draw_parameters";
|
||||||
import { Loader } from "../core/loader";
|
|
||||||
import { createLogger } from "../core/logging";
|
import { createLogger } from "../core/logging";
|
||||||
|
import { findNiceIntegerValue } from "../core/utils";
|
||||||
import { Vector } from "../core/vector";
|
import { Vector } from "../core/vector";
|
||||||
import { Entity } from "./entity";
|
import { Entity } from "./entity";
|
||||||
import { GameRoot } from "./root";
|
import { GameRoot } from "./root";
|
||||||
import { findNiceIntegerValue } from "../core/utils";
|
|
||||||
import { blueprintShape } from "./upgrades";
|
import { blueprintShape } from "./upgrades";
|
||||||
import { globalConfig } from "../core/config";
|
|
||||||
|
|
||||||
const logger = createLogger("blueprint");
|
const logger = createLogger("blueprint");
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
import { makeOffscreenBuffer } from "../../../core/buffer_utils";
|
import { makeOffscreenBuffer } from "../../../core/buffer_utils";
|
||||||
import { globalConfig } from "../../../core/config";
|
import { globalConfig } from "../../../core/config";
|
||||||
import { DrawParameters } from "../../../core/draw_parameters";
|
import { DrawParameters } from "../../../core/draw_parameters";
|
||||||
import { KEYMAPPINGS } from "../../key_action_mapper";
|
|
||||||
import { THEME } from "../../theme";
|
|
||||||
import { BaseHUDPart } from "../base_hud_part";
|
|
||||||
import { Loader } from "../../../core/loader";
|
import { Loader } from "../../../core/loader";
|
||||||
import { lerp } from "../../../core/utils";
|
import { lerp } from "../../../core/utils";
|
||||||
|
import { SOUNDS } from "../../../platform/sound";
|
||||||
|
import { KEYMAPPINGS } from "../../key_action_mapper";
|
||||||
import { enumHubGoalRewards } from "../../tutorial_goals";
|
import { enumHubGoalRewards } from "../../tutorial_goals";
|
||||||
|
import { BaseHUDPart } from "../base_hud_part";
|
||||||
|
|
||||||
|
const copy = require("clipboard-copy");
|
||||||
const wiresBackgroundDpi = 4;
|
const wiresBackgroundDpi = 4;
|
||||||
|
|
||||||
export class HUDWiresOverlay extends BaseHUDPart {
|
export class HUDWiresOverlay extends BaseHUDPart {
|
||||||
|
@ -16,6 +17,7 @@ export class HUDWiresOverlay extends BaseHUDPart {
|
||||||
initialize() {
|
initialize() {
|
||||||
// Probably not the best location, but the one which makes most sense
|
// Probably not the best location, but the one which makes most sense
|
||||||
this.root.keyMapper.getBinding(KEYMAPPINGS.ingame.switchLayers).add(this.switchLayers, this);
|
this.root.keyMapper.getBinding(KEYMAPPINGS.ingame.switchLayers).add(this.switchLayers, this);
|
||||||
|
this.root.keyMapper.getBinding(KEYMAPPINGS.placement.copyWireValue).add(this.copyWireValue, this);
|
||||||
|
|
||||||
this.generateTilePattern();
|
this.generateTilePattern();
|
||||||
|
|
||||||
|
@ -57,6 +59,46 @@ export class HUDWiresOverlay extends BaseHUDPart {
|
||||||
this.currentAlpha = lerp(this.currentAlpha, desiredAlpha, 0.12);
|
this.currentAlpha = lerp(this.currentAlpha, desiredAlpha, 0.12);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copies the wires value below the cursor
|
||||||
|
*/
|
||||||
|
copyWireValue() {
|
||||||
|
if (this.root.currentLayer !== "wires") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const mousePos = this.root.app.mousePosition;
|
||||||
|
if (!mousePos) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const tile = this.root.camera.screenToWorld(mousePos).toTileSpace();
|
||||||
|
const contents = this.root.map.getLayerContentXY(tile.x, tile.y, "wires");
|
||||||
|
if (!contents) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let value = null;
|
||||||
|
if (contents.components.Wire) {
|
||||||
|
const network = contents.components.Wire.linkedNetwork;
|
||||||
|
if (network && network.hasValue()) {
|
||||||
|
value = network.currentValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (contents.components.ConstantSignal) {
|
||||||
|
value = contents.components.ConstantSignal.signal;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value) {
|
||||||
|
copy(value.getAsCopyableKey());
|
||||||
|
this.root.soundProxy.playUi(SOUNDS.copy);
|
||||||
|
} else {
|
||||||
|
copy("");
|
||||||
|
this.root.soundProxy.playUiError();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param {DrawParameters} parameters
|
* @param {DrawParameters} parameters
|
||||||
|
|
|
@ -26,6 +26,13 @@ export class BooleanItem extends BaseItem {
|
||||||
return "boolean";
|
return "boolean";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
getAsCopyableKey() {
|
||||||
|
return this.value ? "1" : "0";
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {number} value
|
* @param {number} value
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -28,6 +28,13 @@ export class ColorItem extends BaseItem {
|
||||||
return "color";
|
return "color";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
getAsCopyableKey() {
|
||||||
|
return this.color;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {BaseItem} other
|
* @param {BaseItem} other
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -27,6 +27,13 @@ export class ShapeItem extends BaseItem {
|
||||||
return "shape";
|
return "shape";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
getAsCopyableKey() {
|
||||||
|
return this.definition.getHash();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {BaseItem} other
|
* @param {BaseItem} other
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -82,6 +82,8 @@ export const KEYMAPPINGS = {
|
||||||
cycleBuildingVariants: { keyCode: key("T") },
|
cycleBuildingVariants: { keyCode: key("T") },
|
||||||
cycleBuildings: { keyCode: 9 }, // TAB
|
cycleBuildings: { keyCode: 9 }, // TAB
|
||||||
switchDirectionLockSide: { keyCode: key("R") },
|
switchDirectionLockSide: { keyCode: key("R") },
|
||||||
|
|
||||||
|
copyWireValue: { keyCode: key("Z") },
|
||||||
},
|
},
|
||||||
|
|
||||||
massSelect: {
|
massSelect: {
|
||||||
|
|
|
@ -25,6 +25,7 @@ export const SOUNDS = {
|
||||||
destroyBuilding: "destroy_building",
|
destroyBuilding: "destroy_building",
|
||||||
placeBuilding: "place_building",
|
placeBuilding: "place_building",
|
||||||
placeBelt: "place_belt",
|
placeBelt: "place_belt",
|
||||||
|
copy: "copy",
|
||||||
};
|
};
|
||||||
|
|
||||||
export const MUSIC = {
|
export const MUSIC = {
|
||||||
|
|
|
@ -1070,7 +1070,8 @@ keybindings:
|
||||||
lockBeltDirection: Enable belt planner
|
lockBeltDirection: Enable belt planner
|
||||||
switchDirectionLockSide: >-
|
switchDirectionLockSide: >-
|
||||||
Planner: Switch side
|
Planner: Switch side
|
||||||
|
copyWireValue: >-
|
||||||
|
Wires: Copy value below cursor
|
||||||
massSelectStart: Hold and drag to start
|
massSelectStart: Hold and drag to start
|
||||||
massSelectSelectMultiple: Select multiple areas
|
massSelectSelectMultiple: Select multiple areas
|
||||||
massSelectCopy: Copy area
|
massSelectCopy: Copy area
|
||||||
|
|
Reference in New Issue