Small code improvments

This commit is contained in:
Stone_Red
2023-10-04 23:32:52 +02:00
parent 9a944f30b6
commit 1fe7f64b23
2 changed files with 6 additions and 7 deletions
@@ -4,5 +4,5 @@ namespace StoneRed.LogicSimulator.Simulation.LogicGates.Interfaces;
internal interface IColorable internal interface IColorable
{ {
public Color Color { get; protected set; } public Color Color { get; }
} }
@@ -11,11 +11,10 @@ namespace StoneRed.LogicSimulator.Simulation.LogicGates;
[LogicGateDescription("A switch is a toggleable switch that can be turned on and off.")] [LogicGateDescription("A switch is a toggleable switch that can be turned on and off.")]
internal class Switch : LogicGate, IInteractable, IColorable internal class Switch : LogicGate, IInteractable, IColorable
{ {
private bool isPressed;
public override int OutputCount { get; set; } = 1; public override int OutputCount { get; set; } = 1;
public override int InputCount { get; set; } = 0; public override int InputCount { get; set; } = 0;
public bool IsPressed { get; set; }
public Color Color { get; set; } = Color.Purple; public Color Color { get; set; } = Color.Purple;
public string Info { get; set; } = "OFF"; public string Info { get; set; } = "OFF";
@@ -23,16 +22,16 @@ internal class Switch : LogicGate, IInteractable, IColorable
{ {
if (mouseState.IsButtonDown(MouseButton.Left) && !previousMouseState.IsButtonDown(MouseButton.Left)) if (mouseState.IsButtonDown(MouseButton.Left) && !previousMouseState.IsButtonDown(MouseButton.Left))
{ {
IsPressed = !IsPressed; isPressed = !isPressed;
} }
Color = IsPressed ? Color.Green : Color.Purple; Color = isPressed ? Color.Green : Color.Purple;
Info = IsPressed ? "ON" : "OFF"; Info = isPressed ? "ON" : "OFF";
} }
protected override void Execute() protected override void Execute()
{ {
if (IsPressed) if (isPressed)
{ {
SetOutputBit(1, 0); SetOutputBit(1, 0);
} }