From 86d51432641d59f0fa4f88bf3ab5943b165a7880 Mon Sep 17 00:00:00 2001 From: TcePrepK <56453014+TcePrepK@users.noreply.github.com> Date: Fri, 25 Jun 2021 20:45:47 +0300 Subject: [PATCH] Copy from ejector --- src/js/game/hud/parts/wires_overlay.js | 45 ++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/src/js/game/hud/parts/wires_overlay.js b/src/js/game/hud/parts/wires_overlay.js index 328d6689..b68dd199 100644 --- a/src/js/game/hud/parts/wires_overlay.js +++ b/src/js/game/hud/parts/wires_overlay.js @@ -3,7 +3,9 @@ import { globalConfig } from "../../../core/config"; import { DrawParameters } from "../../../core/draw_parameters"; import { Loader } from "../../../core/loader"; import { lerp } from "../../../core/utils"; +import { enumDirectionToAngle, Vector } from "../../../core/vector"; import { SOUNDS } from "../../../platform/sound"; +import { enumPinSlotType } from "../../components/wired_pins"; import { KEYMAPPINGS } from "../../key_action_mapper"; import { enumHubGoalRewards } from "../../tutorial_goals"; import { BaseHUDPart } from "../base_hud_part"; @@ -96,10 +98,47 @@ export class HUDWiresOverlay extends BaseHUDPart { if (network && network.hasValue()) { value = network.currentValue; } - } + } else if (contents.components.Display) { + const pinsComp = contents.components.WiredPins; + const network = pinsComp.slots[0].linkedNetwork; - if (contents.components.ConstantSignal) { - value = contents.components.ConstantSignal.signal; + if (network && network.hasValue()) { + value = network.currentValue; + } + } + // else if (contents.components.ConstantSignal) { + // value = contents.components.ConstantSignal.signal; + // } + else if (contents.components.WiredPins) { + const pinComp = contents.components.WiredPins; + const staticComp = contents.components.StaticMapEntity; + + // Go over all slots and see if they are close to mouse or not + const pinSlots = pinComp.slots; + for (let i = 0; i < pinSlots.length; ++i) { + const slot = pinSlots[i]; + + // Check if the type matches + if (slot.type != enumPinSlotType.logicalEjector) { + continue; + } + + // Check if slot is close to mouse + const mouseTilePos = this.root.camera.screenToWorld(mousePos); + + // Dirty math that I don't like the look of + const slotPos = staticComp.localTileToWorld(slot.pos).toWorldSpaceCenterOfTile(); + const effectiveRotation = Math.radians( + staticComp.rotation + enumDirectionToAngle[slot.direction] + ); + const valueSpritePos = slotPos.add(new Vector(0, -9.1).rotated(effectiveRotation)); + const length = mouseTilePos.sub(valueSpritePos).length(); + + // If it is closer than 8 we can copy that value + if (length <= 8) { + value = slot.value; + } + } } if (value) {