Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Sprite changes to Logic Gates to show the input/output state #33277

Merged
merged 8 commits into from
Dec 6, 2024
9 changes: 9 additions & 0 deletions Content.Server/DeviceLinking/Components/LogicGateComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ public sealed partial class LogicGateComponent : Component
[DataField]
public LogicGate Gate = LogicGate.Or;

[DataField]
public LogicGateState InputA = LogicGateState.Low;

[DataField]
public LogicGateState InputB = LogicGateState.Low;

[DataField]
public LogicGateState Output = LogicGateState.Low;

/// <summary>
/// Tool quality to use for cycling logic gate operations.
/// Cannot be pulsing since linking uses that.
Expand Down
14 changes: 14 additions & 0 deletions Content.Server/DeviceLinking/Systems/LogicGateSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,12 @@ private void OnSignalReceived(EntityUid uid, LogicGateComponent comp, ref Signal
if (args.Port == comp.InputPortA)
{
comp.StateA = state;
_appearance.SetData(uid, LogicGateVisuals.InputA, SignalToLogicState(state));
}
else if (args.Port == comp.InputPortB)
{
comp.StateB = state;
_appearance.SetData(uid, LogicGateVisuals.InputB, SignalToLogicState(state));
}

UpdateOutput(uid, comp);
Expand Down Expand Up @@ -143,6 +145,8 @@ private void UpdateOutput(EntityUid uid, LogicGateComponent comp)
break;
}

_appearance.SetData(uid, LogicGateVisuals.Output, output ? LogicGateState.High : LogicGateState.Low);

// only send a payload if it actually changed
if (output != comp.LastOutput)
{
Expand All @@ -151,4 +155,14 @@ private void UpdateOutput(EntityUid uid, LogicGateComponent comp)
_deviceLink.SendSignal(uid, comp.OutputPort, output);
}
}

private static LogicGateState SignalToLogicState(SignalState state)
{
return state switch
{
SignalState.High => LogicGateState.High,
SignalState.Low => LogicGateState.Low,
_ => LogicGateState.Momentary,
};
}
}
18 changes: 16 additions & 2 deletions Content.Shared/DeviceLinking/SharedLogicGate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ public enum LogicGate : byte
[Serializable, NetSerializable]
public enum LogicGateVisuals : byte
{
Gate
Gate,
InputA,
InputB,
Output
}

/// <summary>
Expand All @@ -32,5 +35,16 @@ public enum LogicGateVisuals : byte
[Serializable, NetSerializable]
public enum LogicGateLayers : byte
{
Gate
Gate,
InputA,
InputB,
Output
}

[Serializable, NetSerializable]
public enum LogicGateState : byte
{
Low,
High,
Momentary
}
18 changes: 18 additions & 0 deletions Resources/Prototypes/Entities/Structures/gates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@
layers:
- state: base
- state: logic
- state: empty
map: [ "enum.LogicGateLayers.InputA" ]
- state: empty
map: [ "enum.LogicGateLayers.InputB" ]
- state: empty
map: [ "enum.LogicGateLayers.Output" ]
- state: or
map: [ "enum.LogicGateLayers.Gate" ]
- type: LogicGate
Expand Down Expand Up @@ -63,6 +69,18 @@
Nor: { state: nor }
Nand: { state: nand }
Xnor: { state: xnor }
enum.LogicGateVisuals.InputA:
enum.LogicGateLayers.InputA:
High: { state: logic_a }
Low: { state: empty }
enum.LogicGateVisuals.InputB:
enum.LogicGateLayers.InputB:
High: { state: logic_b }
Low: { state: empty }
enum.LogicGateVisuals.Output:
enum.LogicGateLayers.Output:
High: { state: logic_o }
Low: { state: empty }

- type: entity
parent: LogicGateOr
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Resources/Textures/Objects/Devices/gates.rsi/logic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions Resources/Textures/Objects/Devices/gates.rsi/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@
{
"name": "logic"
},
{
"name": "logic_o"
},
{
"name": "logic_b"
},
{
"name": "logic_a"
},
{
"name": "empty"
},
{
"name": "or"
},
Expand Down
Loading