From 1fe7f64b233bdda4c50808cb4359472b3aaac49e Mon Sep 17 00:00:00 2001 From: Stone_Red <56473591+Stone-Red-Code@users.noreply.github.com> Date: Wed, 4 Oct 2023 23:32:52 +0200 Subject: [PATCH] Small code improvments --- .../Simulation/LogicGates/Interfaces/IColorable.cs | 2 +- .../Simulation/LogicGates/Switch.cs | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/StoneRed.LogicSimulator/Simulation/LogicGates/Interfaces/IColorable.cs b/StoneRed.LogicSimulator/Simulation/LogicGates/Interfaces/IColorable.cs index bd7a402..82a5d34 100644 --- a/StoneRed.LogicSimulator/Simulation/LogicGates/Interfaces/IColorable.cs +++ b/StoneRed.LogicSimulator/Simulation/LogicGates/Interfaces/IColorable.cs @@ -4,5 +4,5 @@ namespace StoneRed.LogicSimulator.Simulation.LogicGates.Interfaces; internal interface IColorable { - public Color Color { get; protected set; } + public Color Color { get; } } \ No newline at end of file diff --git a/StoneRed.LogicSimulator/Simulation/LogicGates/Switch.cs b/StoneRed.LogicSimulator/Simulation/LogicGates/Switch.cs index 47614c3..e84aa91 100644 --- a/StoneRed.LogicSimulator/Simulation/LogicGates/Switch.cs +++ b/StoneRed.LogicSimulator/Simulation/LogicGates/Switch.cs @@ -11,11 +11,10 @@ namespace StoneRed.LogicSimulator.Simulation.LogicGates; [LogicGateDescription("A switch is a toggleable switch that can be turned on and off.")] internal class Switch : LogicGate, IInteractable, IColorable { + private bool isPressed; public override int OutputCount { get; set; } = 1; public override int InputCount { get; set; } = 0; - - public bool IsPressed { get; set; } public Color Color { get; set; } = Color.Purple; 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)) { - IsPressed = !IsPressed; + isPressed = !isPressed; } - Color = IsPressed ? Color.Green : Color.Purple; - Info = IsPressed ? "ON" : "OFF"; + Color = isPressed ? Color.Green : Color.Purple; + Info = isPressed ? "ON" : "OFF"; } protected override void Execute() { - if (IsPressed) + if (isPressed) { SetOutputBit(1, 0); }