]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
signal router (#20802)
authordeltanedas <39013340+deltanedas@users.noreply.github.com>
Tue, 14 Nov 2023 23:30:43 +0000 (23:30 +0000)
committerGitHub <noreply@github.com>
Tue, 14 Nov 2023 23:30:43 +0000 (16:30 -0700)
* add signal router sprite

* DisposalSignalRouter logic

* add disposal signal router

* add disposal signal router

* how did it work without this

* death

---------

Co-authored-by: deltanedas <@deltanedas:kde.org>
Content.Server/Disposal/Tube/Components/DisposalSignalRouterComponent.cs [new file with mode: 0644]
Content.Server/Disposal/Tube/Systems/DisposalSignalRouterSystem.cs [new file with mode: 0644]
Resources/Prototypes/Entities/Structures/Piping/Disposal/pipes.yml
Resources/Prototypes/Recipes/Construction/Graphs/utilities/disposal_pipes.yml
Resources/Prototypes/Recipes/Construction/utilities.yml
Resources/Textures/Structures/Piping/disposal.rsi/meta.json
Resources/Textures/Structures/Piping/disposal.rsi/signal-router-flipped-free.png [new file with mode: 0644]
Resources/Textures/Structures/Piping/disposal.rsi/signal-router-flipped.png [new file with mode: 0644]
Resources/Textures/Structures/Piping/disposal.rsi/signal-router-free.png [new file with mode: 0644]
Resources/Textures/Structures/Piping/disposal.rsi/signal-router.png [new file with mode: 0644]

diff --git a/Content.Server/Disposal/Tube/Components/DisposalSignalRouterComponent.cs b/Content.Server/Disposal/Tube/Components/DisposalSignalRouterComponent.cs
new file mode 100644 (file)
index 0000000..b4ef81d
--- /dev/null
@@ -0,0 +1,36 @@
+using Content.Server.Disposal.Tube.Systems;
+using Content.Shared.DeviceLinking;
+using Robust.Shared.Prototypes;
+
+namespace Content.Server.Disposal.Tube.Components;
+
+/// <summary>
+/// Requires <see cref="DisposalJunctionComponent"/> to function.
+/// </summary>
+[RegisterComponent, Access(typeof(DisposalSignalRouterSystem))]
+public sealed partial class DisposalSignalRouterComponent : Component
+{
+    /// <summary>
+    /// Whether to route items to the side or not.
+    /// </summary>
+    [DataField]
+    public bool Routing;
+
+    /// <summary>
+    /// Port that sets the router to send items to the side.
+    /// </summary>
+    [DataField]
+    public ProtoId<SinkPortPrototype> OnPort = "On";
+
+    /// <summary>
+    /// Port that sets the router to send items ahead.
+    /// </summary>
+    [DataField]
+    public ProtoId<SinkPortPrototype> OffPort = "Off";
+
+    /// <summary>
+    /// Port that toggles the router between sending items to the side and ahead.
+    /// </summary>
+    [DataField]
+    public ProtoId<SinkPortPrototype> TogglePort = "Toggle";
+}
diff --git a/Content.Server/Disposal/Tube/Systems/DisposalSignalRouterSystem.cs b/Content.Server/Disposal/Tube/Systems/DisposalSignalRouterSystem.cs
new file mode 100644 (file)
index 0000000..3a9fdbb
--- /dev/null
@@ -0,0 +1,52 @@
+using Content.Server.DeviceLinking.Events;
+using Content.Server.DeviceLinking.Systems;
+using Content.Server.Disposal.Tube;
+using Content.Server.Disposal.Tube.Components;
+
+namespace Content.Server.Disposal.Tube.Systems;
+
+/// <summary>
+/// Handles signals and the routing get next direction event.
+/// </summary>
+public sealed class DisposalSignalRouterSystem : EntitySystem
+{
+    [Dependency] private readonly DeviceLinkSystem _deviceLink = default!;
+
+    public override void Initialize()
+    {
+        base.Initialize();
+
+        SubscribeLocalEvent<DisposalSignalRouterComponent, ComponentInit>(OnInit);
+        SubscribeLocalEvent<DisposalSignalRouterComponent, SignalReceivedEvent>(OnSignalReceived);
+        SubscribeLocalEvent<DisposalSignalRouterComponent, GetDisposalsNextDirectionEvent>(OnGetNextDirection, after: new[] { typeof(DisposalTubeSystem) });
+    }
+
+    private void OnInit(EntityUid uid, DisposalSignalRouterComponent comp, ComponentInit args)
+    {
+        _deviceLink.EnsureSinkPorts(uid, comp.OnPort, comp.OffPort, comp.TogglePort);
+    }
+
+    private void OnSignalReceived(EntityUid uid, DisposalSignalRouterComponent comp, ref SignalReceivedEvent args)
+    {
+        // TogglePort flips it
+        // OnPort sets it to true
+        // OffPort sets it to false
+        comp.Routing = args.Port == comp.TogglePort
+            ? !comp.Routing
+            : args.Port == comp.OnPort;
+    }
+
+    private void OnGetNextDirection(EntityUid uid, DisposalSignalRouterComponent comp, ref GetDisposalsNextDirectionEvent args)
+    {
+        if (!comp.Routing)
+        {
+            args.Next = Transform(uid).LocalRotation.GetDir();
+            return;
+        }
+
+        // use the junction side direction when a tag matches
+        var ev = new GetDisposalsConnectableDirectionsEvent();
+        RaiseLocalEvent(uid, ref ev);
+        args.Next = ev.Connectable[1];
+    }
+}
index 9e3780a6dab09837e9a66d30990c2803ed5045fa..d4b7c1d3c96ecea69ab20879a69fee7deec6dc90 100644 (file)
   - type: Construction
     graph: DisposalPipe
     node: bend
+
+- type: entity
+  parent: DisposalJunction
+  id: DisposalSignalRouter
+  name: disposal signal router
+  description: A signal-controlled three-way router.
+  components:
+  - type: Sprite
+    drawdepth: ThickPipe
+    layers:
+    - map: [ "pipe" ]
+      state: signal-router-free
+  - type: DisposalTube
+    containerId: DisposalSignalRouter
+  - type: DisposalSignalRouter
+  - type: DeviceLinkSink
+    ports:
+    - On
+    - Off
+    - Toggle
+  - type: DeviceNetwork
+    deviceNetId: Wireless
+    receiveFrequencyId: BasicDevice
+  - type: WirelessNetworkConnection
+    range: 200
+  - type: ContainerContainer
+    containers:
+      DisposalSignalRouter: !type:Container
+  - type: GenericVisualizer
+    visuals:
+      enum.DisposalTubeVisuals.VisualState:
+        pipe:
+          Free: { state: signal-router-free }
+          Anchored: { state: signal-router }
+  - type: Flippable
+    mirrorEntity: DisposalSignalRouterFlipped
+  - type: Construction
+    graph: DisposalPipe
+    node: signal_router
+
+- type: entity
+  parent: DisposalSignalRouter
+  id: DisposalSignalRouterFlipped
+  suffix: flipped
+  components:
+  - type: Sprite
+    layers:
+    - map: [ "pipe" ]
+      state: signal-router-flipped-free
+  - type: DisposalJunction
+    degrees:
+    - 0
+    - 90
+    - 180
+  - type: GenericVisualizer
+    visuals:
+      enum.DisposalTubeVisuals.VisualState:
+        pipe:
+          Free: { state: signal-router-flipped-free }
+          Anchored: { state: signal-router-flipped }
index b626105532ffca4b69f98d57ad9a829c2d4fca52..1b3aa3105bfab85342ff64b1f47133782c9845bb 100644 (file)
       - material: Steel
         amount: 2
         doAfter: 1
+    # DisposalSignalRouter
+    - to: signal_router
+      steps:
+      - material: Steel
+        amount: 2
+        doAfter: 1
+      - material: Cable
+        amount: 1
+        doAfter: 1
+    - to: signal_router_flipped
+      steps:
+      - material: Steel
+        amount: 2
+        doAfter: 1
+      - material: Cable
+        amount: 1
+        doAfter: 1
   - node: broken
     entity: DisposalPipeBroken
     edges:
       - !type:DeleteEntity
       steps:
       - tool: Welding
-        doAfter: 1
\ No newline at end of file
+        doAfter: 1
+  # DisposalRouter
+  - node: signal_router
+    entity: DisposalSignalRouter
+    edges:
+    - to: start
+      completed:
+      - !type:SpawnPrototype
+        prototype: SheetSteel1
+        amount: 2
+      - !type:SpawnPrototype
+        prototype: CableApcStack1
+      - !type:DeleteEntity
+      steps:
+      - tool: Welding
+        doAfter: 1
+  - node: signal_router_flipped
+    entity: DisposalSignalRouterFlipped
+    edges:
+    - to: start
+      completed:
+      - !type:SpawnPrototype
+        prototype: SheetSteel1
+        amount: 2
+      - !type:SpawnPrototype
+        prototype: CableApcStack1
+      - !type:DeleteEntity
+      steps:
+      - tool: Welding
+        doAfter: 1
index d1dac1d1b057def64cea3d3b8123ccc84f9ae9c7..5bd28f9b5bc43ce00351f727ff8d760b172a76b2 100644 (file)
     state: conpipe-j2s
   mirror: DisposalRouter
 
+- type: construction
+  name: disposal signal router
+  description: A signal-controlled three-way router.
+  id: DisposalSignalRouter
+  graph: DisposalPipe
+  startNode: start
+  targetNode: signal_router
+  category: construction-category-utilities
+  placementMode: SnapgridCenter
+  canBuildInImpassable: false
+  icon:
+    sprite: Structures/Piping/disposal.rsi
+    state: signal-router-free
+  mirror: DisposalSignalRouterFlipped
+
+- type: construction
+  hide: true
+  name: disposal signal router
+  description: A signal-controlled three-way router.
+  id: DisposalSignalRouterFlipped
+  graph: DisposalPipe
+  startNode: start
+  targetNode: signal_router_flipped
+  category: construction-category-utilities
+  placementMode: SnapgridCenter
+  canBuildInImpassable: false
+  icon:
+    sprite: Structures/Piping/disposal.rsi
+    state: signal-router-flipped-free
+  mirror: DisposalSignalRouter
+
 - type: construction
   name: disposal junction
   description: A three-way junction. The arrow indicates where items exit.
index fd0ed2ac25deb5b3cef1fb8999fb5a3c6b3d4c80..87655b6b86c1e5935ab4941c9cb5b0516d3b9674 100644 (file)
@@ -5,7 +5,7 @@
         "y": 32
     },
     "license": "CC-BY-SA-3.0",
-    "copyright": "https://github.com/discordia-space/CEV-Eris/blob/bbe32606902c90f5290b57d905a3f31b84dc6d7d/icons/obj/pipes/disposal.dmi and modified by DrSmugleaf",
+    "copyright": "https://github.com/discordia-space/CEV-Eris/blob/bbe32606902c90f5290b57d905a3f31b84dc6d7d/icons/obj/pipes/disposal.dmi and modified by DrSmugleaf. Signal router sprites based on normal router modified by deltanedas (github).",
     "states": [
         {
             "name": "condisposal",
                     1.0
                 ]
             ]
+        },
+        {
+            "name": "signal-router",
+            "directions": 4,
+            "delays": [
+                [
+                    1.0
+                ],
+                [
+                    1.0
+                ],
+                [
+                    1.0
+                ],
+                [
+                    1.0
+                ]
+            ]
+        },
+        {
+            "name": "signal-router-free",
+            "directions": 4,
+            "delays": [
+                [
+                    1.0
+                ],
+                [
+                    1.0
+                ],
+                [
+                    1.0
+                ],
+                [
+                    1.0
+                ]
+            ]
+        },
+        {
+            "name": "signal-router-flipped",
+            "directions": 4,
+            "delays": [
+                [
+                    1.0
+                ],
+                [
+                    1.0
+                ],
+                [
+                    1.0
+                ],
+                [
+                    1.0
+                ]
+            ]
+        },
+        {
+            "name": "signal-router-flipped-free",
+            "directions": 4,
+            "delays": [
+                [
+                    1.0
+                ],
+                [
+                    1.0
+                ],
+                [
+                    1.0
+                ],
+                [
+                    1.0
+                ]
+            ]
         }
     ]
-}
\ No newline at end of file
+}
diff --git a/Resources/Textures/Structures/Piping/disposal.rsi/signal-router-flipped-free.png b/Resources/Textures/Structures/Piping/disposal.rsi/signal-router-flipped-free.png
new file mode 100644 (file)
index 0000000..c8f27f8
Binary files /dev/null and b/Resources/Textures/Structures/Piping/disposal.rsi/signal-router-flipped-free.png differ
diff --git a/Resources/Textures/Structures/Piping/disposal.rsi/signal-router-flipped.png b/Resources/Textures/Structures/Piping/disposal.rsi/signal-router-flipped.png
new file mode 100644 (file)
index 0000000..8ea007c
Binary files /dev/null and b/Resources/Textures/Structures/Piping/disposal.rsi/signal-router-flipped.png differ
diff --git a/Resources/Textures/Structures/Piping/disposal.rsi/signal-router-free.png b/Resources/Textures/Structures/Piping/disposal.rsi/signal-router-free.png
new file mode 100644 (file)
index 0000000..672aa56
Binary files /dev/null and b/Resources/Textures/Structures/Piping/disposal.rsi/signal-router-free.png differ
diff --git a/Resources/Textures/Structures/Piping/disposal.rsi/signal-router.png b/Resources/Textures/Structures/Piping/disposal.rsi/signal-router.png
new file mode 100644 (file)
index 0000000..2c9d4dd
Binary files /dev/null and b/Resources/Textures/Structures/Piping/disposal.rsi/signal-router.png differ