mirror of
https://github.com/Stone-Red-Code/StoneRed.LogicSimulator.git
synced 2026-09-07 07:55:58 +02:00
Initial commit
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
|
||||
using MonoGame.Extended.Input;
|
||||
|
||||
using StoneRed.LogicSimulator.Simulation.LogicGates.Interfaces;
|
||||
|
||||
namespace StoneRed.LogicSimulator.Simulation.LogicGates;
|
||||
|
||||
internal class Switch : LogicGate, IInteractable, IColorable
|
||||
{
|
||||
public override int OutputCount => 1;
|
||||
|
||||
public override int InputCount => 0;
|
||||
|
||||
public bool IsPressed { get; set; }
|
||||
public Color Color { get; set; } = Color.Purple;
|
||||
public string Info { get; set; } = "OFF";
|
||||
|
||||
public Switch()
|
||||
{
|
||||
Metadata.Name = "Switch";
|
||||
}
|
||||
|
||||
public void OnInteraction(MouseStateExtended mouseState, MouseStateExtended previousMouseState, KeyboardStateExtended keyboardStateExtended)
|
||||
{
|
||||
if (mouseState.IsButtonDown(MouseButton.Left) && !previousMouseState.IsButtonDown(MouseButton.Left))
|
||||
{
|
||||
IsPressed = !IsPressed;
|
||||
}
|
||||
|
||||
Color = IsPressed ? Color.Green : Color.Purple;
|
||||
Info = IsPressed ? "ON" : "OFF";
|
||||
}
|
||||
|
||||
protected override void Execute()
|
||||
{
|
||||
if (IsPressed)
|
||||
{
|
||||
SetOutputBit(1, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetOutputBit(0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user