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 1/7] 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) { From 9ef712c99d1461e1923b2ad32d84981b11545aff Mon Sep 17 00:00:00 2001 From: TcePrepK <56453014+TcePrepK@users.noreply.github.com> Date: Fri, 25 Jun 2021 21:22:22 +0300 Subject: [PATCH 2/7] Removed display check because it doesn't work anyways --- src/js/game/hud/parts/wires_overlay.js | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/js/game/hud/parts/wires_overlay.js b/src/js/game/hud/parts/wires_overlay.js index b68dd199..3a2ed110 100644 --- a/src/js/game/hud/parts/wires_overlay.js +++ b/src/js/game/hud/parts/wires_overlay.js @@ -95,13 +95,6 @@ export class HUDWiresOverlay extends BaseHUDPart { let value = null; if (contents.components.Wire) { const network = contents.components.Wire.linkedNetwork; - if (network && network.hasValue()) { - value = network.currentValue; - } - } else if (contents.components.Display) { - const pinsComp = contents.components.WiredPins; - const network = pinsComp.slots[0].linkedNetwork; - if (network && network.hasValue()) { value = network.currentValue; } @@ -131,6 +124,7 @@ export class HUDWiresOverlay extends BaseHUDPart { const effectiveRotation = Math.radians( staticComp.rotation + enumDirectionToAngle[slot.direction] ); + // -9.1 comes from systems > wired_pins.js > line 207 const valueSpritePos = slotPos.add(new Vector(0, -9.1).rotated(effectiveRotation)); const length = mouseTilePos.sub(valueSpritePos).length(); From d2bf33dcc7d7db034cc95bcfd974aa568eb16a24 Mon Sep 17 00:00:00 2001 From: EmeraldBlock Date: Mon, 28 Jun 2021 13:28:55 -0500 Subject: [PATCH 3/7] undo removal of constant signal check --- src/js/game/hud/parts/wires_overlay.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/js/game/hud/parts/wires_overlay.js b/src/js/game/hud/parts/wires_overlay.js index 3a2ed110..de245e9e 100644 --- a/src/js/game/hud/parts/wires_overlay.js +++ b/src/js/game/hud/parts/wires_overlay.js @@ -98,11 +98,9 @@ export class HUDWiresOverlay extends BaseHUDPart { if (network && network.hasValue()) { value = network.currentValue; } - } - // else if (contents.components.ConstantSignal) { - // value = contents.components.ConstantSignal.signal; - // } - else if (contents.components.WiredPins) { + } 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; From 0deb08901b610a901b745e607572cfc29070d6a0 Mon Sep 17 00:00:00 2001 From: EmeraldBlock Date: Mon, 28 Jun 2021 13:39:55 -0500 Subject: [PATCH 4/7] move unchanging value out of loop --- src/js/game/hud/parts/wires_overlay.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/js/game/hud/parts/wires_overlay.js b/src/js/game/hud/parts/wires_overlay.js index de245e9e..3ed48ec7 100644 --- a/src/js/game/hud/parts/wires_overlay.js +++ b/src/js/game/hud/parts/wires_overlay.js @@ -104,6 +104,8 @@ export class HUDWiresOverlay extends BaseHUDPart { const pinComp = contents.components.WiredPins; const staticComp = contents.components.StaticMapEntity; + const mouseTilePos = this.root.camera.screenToWorld(mousePos); + // 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) { @@ -115,8 +117,6 @@ export class HUDWiresOverlay extends BaseHUDPart { } // 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( From 93ecc7779252ceaa82603c30308d2632888e5d22 Mon Sep 17 00:00:00 2001 From: EmeraldBlock Date: Mon, 28 Jun 2021 14:01:26 -0500 Subject: [PATCH 5/7] use 90 degree rotation --- src/js/game/hud/parts/wires_overlay.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/js/game/hud/parts/wires_overlay.js b/src/js/game/hud/parts/wires_overlay.js index 3ed48ec7..f493826f 100644 --- a/src/js/game/hud/parts/wires_overlay.js +++ b/src/js/game/hud/parts/wires_overlay.js @@ -119,11 +119,11 @@ export class HUDWiresOverlay extends BaseHUDPart { // Check if slot is close to mouse // 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 effectiveRotation = (staticComp.rotation + enumDirectionToAngle[slot.direction]) % 360; // -9.1 comes from systems > wired_pins.js > line 207 - const valueSpritePos = slotPos.add(new Vector(0, -9.1).rotated(effectiveRotation)); + const valueSpritePos = slotPos.add( + new Vector(0, -9.1).rotateInplaceFastMultipleOf90(effectiveRotation) + ); const length = mouseTilePos.sub(valueSpritePos).length(); // If it is closer than 8 we can copy that value From 0bac871eba09c43c79964288be2c14d693068c2e Mon Sep 17 00:00:00 2001 From: EmeraldBlock Date: Mon, 28 Jun 2021 16:57:58 -0500 Subject: [PATCH 6/7] use closest output as item --- src/js/game/hud/parts/wires_overlay.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/js/game/hud/parts/wires_overlay.js b/src/js/game/hud/parts/wires_overlay.js index f493826f..256abf19 100644 --- a/src/js/game/hud/parts/wires_overlay.js +++ b/src/js/game/hud/parts/wires_overlay.js @@ -108,6 +108,7 @@ export class HUDWiresOverlay extends BaseHUDPart { // Go over all slots and see if they are close to mouse or not const pinSlots = pinComp.slots; + let minLength = Infinity; for (let i = 0; i < pinSlots.length; ++i) { const slot = pinSlots[i]; @@ -127,7 +128,8 @@ export class HUDWiresOverlay extends BaseHUDPart { const length = mouseTilePos.sub(valueSpritePos).length(); // If it is closer than 8 we can copy that value - if (length <= 8) { + if (length < minLength) { + minLength = length; value = slot.value; } } From c557c2570b1436ce3fc35c9509ebd1b97c3e14f2 Mon Sep 17 00:00:00 2001 From: TcePrepK <56453014+TcePrepK@users.noreply.github.com> Date: Thu, 1 Jul 2021 23:15:30 +0300 Subject: [PATCH 7/7] Fixed comment --- src/js/game/hud/parts/wires_overlay.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/js/game/hud/parts/wires_overlay.js b/src/js/game/hud/parts/wires_overlay.js index 256abf19..15a7154f 100644 --- a/src/js/game/hud/parts/wires_overlay.js +++ b/src/js/game/hud/parts/wires_overlay.js @@ -127,7 +127,7 @@ export class HUDWiresOverlay extends BaseHUDPart { ); const length = mouseTilePos.sub(valueSpritePos).length(); - // If it is closer than 8 we can copy that value + // If it is closer than current minimum length we can copy that value if (length < minLength) { minLength = length; value = slot.value;