1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2025-06-07 01:54:10 +00:00

Copy from ejector

This commit is contained in:
TcePrepK 2021-06-25 20:45:47 +03:00
parent dba91fa50c
commit 86d5143264

View File

@ -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) {