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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

0tito
Copy link

@0tito 0tito commented Nov 12, 2024

About the PR

Gates now show the state of their inputs and outputs on the sprite

Why / Balance

Its easier to use them if you can see the states

Media

2024-11-12.10-41-36.mp4

Requirements

Changelog

@github-actions github-actions bot added the Changes: Sprites Changes: Might require knowledge of spriting or visual design. label Nov 12, 2024
Copy link
Contributor

github-actions bot commented Nov 12, 2024

RSI Diff Bot; head commit 16a2e13 merging into 8776c71
This PR makes changes to 1 or more RSIs. Here is a summary of all changes:

Resources/Textures/Objects/Devices/gates.rsi

State Old New Status
logic Modified
empty Added
logic_a Added
logic_b Added
logic_o Added

Edit: diff updated after 16a2e13

@deltanedas
Copy link
Contributor

use separate layers for a/b/output and none of the evil stuff is needed

@0tito
Copy link
Author

0tito commented Nov 14, 2024

Is this better? im not exactly the best coder :godo:

@SlamBamActionman SlamBamActionman added the S: Untriaged Status: Indicates an item has not been triaged and doesn't have appropriate labels. label Nov 14, 2024
@SaphireLattice SaphireLattice added P3: Standard Priority: Default priority for repository items. T: New Feature Type: New feature or content, or extending existing content D3: Low Difficulty: Some codebase knowledge required. S: Needs Review Status: Requires additional reviews before being fully accepted A: Art Area: Art with no implications for other areas. T: Visual Change Type: Deals with changes to art, sprites or other visuals in the game. and removed S: Untriaged Status: Indicates an item has not been triaged and doesn't have appropriate labels. labels Nov 15, 2024
Copy link
Contributor

@Aeshus Aeshus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!

There's some small code style issues, and a bug where the code accidentally sets InputA instead of InputB.

Other than that, I like the change and the rest of the visualizer/layering stuff looks good (I don't have personal experience with any of it).

Also, I'm not a maintainer, so this is just a peer review. I may have made some mistakes in my review, or have missed things, so take this review with a grain of salt.

Comment on lines 72 to 73


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent spacing -- there should only be one line between fields.

Suggested change

@@ -18,6 +18,19 @@ public sealed partial class LogicGateComponent : Component
[DataField]
public LogicGate Gate = LogicGate.Or;


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent spacing -- there should only be one line between fields.

Suggested change

[DataField]
public LogicGateState Output = LogicGateState.Low;


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent spacing -- there should only be one line between fields.

Suggested change

Comment on lines 128 to 153
{
case LogicGate.Or:
output = a || b;
_appearance.SetData(uid, LogicGateVisuals.Output, output ? LogicGateState.High : LogicGateState.Low);
break;
case LogicGate.And:
output = a && b;
_appearance.SetData(uid, LogicGateVisuals.Output, output ? LogicGateState.High : LogicGateState.Low);
break;
case LogicGate.Xor:
output = a != b;
_appearance.SetData(uid, LogicGateVisuals.Output, output ? LogicGateState.High : LogicGateState.Low);
break;
case LogicGate.Nor:
output = !(a || b);
_appearance.SetData(uid, LogicGateVisuals.Output, output ? LogicGateState.High : LogicGateState.Low);
break;
case LogicGate.Nand:
output = !(a && b);
_appearance.SetData(uid, LogicGateVisuals.Output, output ? LogicGateState.High : LogicGateState.Low);
break;
case LogicGate.Xnor:
output = a == b;
_appearance.SetData(uid, LogicGateVisuals.Output, output ? LogicGateState.High : LogicGateState.Low);
break;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can extract down the _appearance.SetData call below the switch, as it's the same for every code path.

Also, there's a missing default case.

Suggested change
{
case LogicGate.Or:
output = a || b;
_appearance.SetData(uid, LogicGateVisuals.Output, output ? LogicGateState.High : LogicGateState.Low);
break;
case LogicGate.And:
output = a && b;
_appearance.SetData(uid, LogicGateVisuals.Output, output ? LogicGateState.High : LogicGateState.Low);
break;
case LogicGate.Xor:
output = a != b;
_appearance.SetData(uid, LogicGateVisuals.Output, output ? LogicGateState.High : LogicGateState.Low);
break;
case LogicGate.Nor:
output = !(a || b);
_appearance.SetData(uid, LogicGateVisuals.Output, output ? LogicGateState.High : LogicGateState.Low);
break;
case LogicGate.Nand:
output = !(a && b);
_appearance.SetData(uid, LogicGateVisuals.Output, output ? LogicGateState.High : LogicGateState.Low);
break;
case LogicGate.Xnor:
output = a == b;
_appearance.SetData(uid, LogicGateVisuals.Output, output ? LogicGateState.High : LogicGateState.Low);
break;
}
{
case LogicGate.Or:
output = a || b;
break;
case LogicGate.And:
output = a && b;
break;
case LogicGate.Xor:
output = a != b;
break;
case LogicGate.Nor:
output = !(a || b);
break;
case LogicGate.Nand:
output = !(a && b);
break;
case LogicGate.Xnor:
output = a == b;
break;
default:
throw new ArgumentOutOfRangeException();
}
_appearance.SetData(uid, LogicGateVisuals.Output, output ? LogicGateState.High : LogicGateState.Low);

If you're adventurous, you can also just refactor the switch statement into a switch expression

@@ -3,6 +3,7 @@
using Content.Shared.DeviceLinking;
using Content.Shared.Examine;
using Content.Shared.Interaction;
using Content.Shared.Lathe;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused import?

Suggested change
using Content.Shared.Lathe;

}
else if (args.Port == comp.InputPortB)
{
comp.StateB = state;
_appearance.SetData(uid, LogicGateVisuals.InputA, UpdateState(state));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be modifying InputB instead of InputA?

Suggested change
_appearance.SetData(uid, LogicGateVisuals.InputA, UpdateState(state));
_appearance.SetData(uid, LogicGateVisuals.InputB, UpdateState(state));

Comment on lines 164 to 178
LogicGateState UpdateState(SignalState state)
{
switch (state)
{
case SignalState.High:
return LogicGateState.High;
break;
case SignalState.Low:
return LogicGateState.Low;
break;
default:
return LogicGateState.Momentary;
break;

}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're missing an access modifier on the function.

Also, you can make it more succinct by using a switch expression.

Finally, it makes sense to rename the function to SignalToLogicState, as the previous name kind-of implies some kind of side effect ("UpdateState"), when really all it does is map all of the SignalStates to their correct LogicGateState.

Suggested change
LogicGateState UpdateState(SignalState state)
{
switch (state)
{
case SignalState.High:
return LogicGateState.High;
break;
case SignalState.Low:
return LogicGateState.Low;
break;
default:
return LogicGateState.Momentary;
break;
}
private static LogicGateState SignalToLogicState(SignalState state)
{
return state switch
{
SignalState.High => LogicGateState.High,
SignalState.Low => LogicGateState.Low,
_ => LogicGateState.Momentary,
};

@@ -63,6 +69,18 @@
Nor: { state: nor }
Nand: { state: nand }
Xnor: { state: xnor }
enum.LogicGateVisuals.InputA:
enum.LogicGateLayers.InputA:
High: {state: logic_a }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing a space.

Suggested change
High: {state: logic_a }
High: { state: logic_a }

@@ -36,6 +36,12 @@
layers:
- state: base
- state: logic
- state: empty
map: ["enum.LogicGateLayers.InputA"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing spacing.

Suggested change
map: ["enum.LogicGateLayers.InputA"]
map: [ "enum.LogicGateLayers.InputA" ]

@github-actions github-actions bot added the size/M Denotes a PR that changes 30-99 lines. label Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A: Art Area: Art with no implications for other areas. Changes: Sprites Changes: Might require knowledge of spriting or visual design. D3: Low Difficulty: Some codebase knowledge required. P3: Standard Priority: Default priority for repository items. S: Needs Review Status: Requires additional reviews before being fully accepted size/M Denotes a PR that changes 30-99 lines. T: New Feature Type: New feature or content, or extending existing content T: Visual Change Type: Deals with changes to art, sprites or other visuals in the game.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants