Allow copying wire values

This commit is contained in:
tobspr 2020-09-28 14:45:53 +02:00
parent 7ed36daac0
commit d5f7a78386
10 changed files with 82 additions and 7 deletions

BIN
res_raw/sounds/sfx/copy.wav Normal file

Binary file not shown.

View File

@ -28,6 +28,15 @@ export class BaseItem extends BasicSerializableObject {
return "shape";
}
/**
* Returns a string id of the item
* @returns {string}
*/
getAsCopyableKey() {
abstract;
return "";
}
/**
* Returns if the item equals the other itme
* @param {BaseItem} other

View File

@ -1,12 +1,11 @@
import { globalConfig } from "../core/config";
import { DrawParameters } from "../core/draw_parameters";
import { Loader } from "../core/loader";
import { createLogger } from "../core/logging";
import { findNiceIntegerValue } from "../core/utils";
import { Vector } from "../core/vector";
import { Entity } from "./entity";
import { GameRoot } from "./root";
import { findNiceIntegerValue } from "../core/utils";
import { blueprintShape } from "./upgrades";
import { globalConfig } from "../core/config";
const logger = createLogger("blueprint");

View File

@ -1,13 +1,14 @@
import { makeOffscreenBuffer } from "../../../core/buffer_utils";
import { globalConfig } from "../../../core/config";
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 { lerp } from "../../../core/utils";
import { SOUNDS } from "../../../platform/sound";
import { KEYMAPPINGS } from "../../key_action_mapper";
import { enumHubGoalRewards } from "../../tutorial_goals";
import { BaseHUDPart } from "../base_hud_part";
const copy = require("clipboard-copy");
const wiresBackgroundDpi = 4;
export class HUDWiresOverlay extends BaseHUDPart {
@ -16,6 +17,7 @@ export class HUDWiresOverlay extends BaseHUDPart {
initialize() {
// 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.placement.copyWireValue).add(this.copyWireValue, this);
this.generateTilePattern();
@ -57,6 +59,46 @@ export class HUDWiresOverlay extends BaseHUDPart {
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

View File

@ -26,6 +26,13 @@ export class BooleanItem extends BaseItem {
return "boolean";
}
/**
* @returns {string}
*/
getAsCopyableKey() {
return this.value ? "1" : "0";
}
/**
* @param {number} value
*/

View File

@ -28,6 +28,13 @@ export class ColorItem extends BaseItem {
return "color";
}
/**
* @returns {string}
*/
getAsCopyableKey() {
return this.color;
}
/**
* @param {BaseItem} other
*/

View File

@ -27,6 +27,13 @@ export class ShapeItem extends BaseItem {
return "shape";
}
/**
* @returns {string}
*/
getAsCopyableKey() {
return this.definition.getHash();
}
/**
* @param {BaseItem} other
*/

View File

@ -82,6 +82,8 @@ export const KEYMAPPINGS = {
cycleBuildingVariants: { keyCode: key("T") },
cycleBuildings: { keyCode: 9 }, // TAB
switchDirectionLockSide: { keyCode: key("R") },
copyWireValue: { keyCode: key("Z") },
},
massSelect: {

View File

@ -25,6 +25,7 @@ export const SOUNDS = {
destroyBuilding: "destroy_building",
placeBuilding: "place_building",
placeBelt: "place_belt",
copy: "copy",
};
export const MUSIC = {

View File

@ -1070,7 +1070,8 @@ keybindings:
lockBeltDirection: Enable belt planner
switchDirectionLockSide: >-
Planner: Switch side
copyWireValue: >-
Wires: Copy value below cursor
massSelectStart: Hold and drag to start
massSelectSelectMultiple: Select multiple areas
massSelectCopy: Copy area