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

Combine T and SR flip flop #2237

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
using Aurora.Profiles;
using Aurora.Utils;
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;

namespace Aurora.Settings.Overrides.Logic.Boolean {

namespace Aurora.Settings.Overrides.Logic.Boolean
{
#region Obsolete
/// <summary>
/// A simple memory gate that can be used for storing a boolean state.
/// While the given input is true, the state of the flip-flop is toggled.
/// </summary>
[Evaluatable("Flip-flop (Toggle)", category: EvaluatableCategory.Logic)]
[Obsolete("This Evaluatable is obsolete. Use Boolean_FlipFlop instead.", false)]
public class Boolean_FlipFlopT : Evaluatable<bool> {

private bool state = false;
Expand Down Expand Up @@ -42,7 +44,7 @@ protected override bool Execute(IGameState gameState) {
/// A simple memory gate that can be used for storing a boolean state.
/// When 'Set' is true, the gate will start outputting true until 'Reset' becomes true.
/// </summary>
[Evaluatable("Flip-flop (Set-Reset)", category: EvaluatableCategory.Logic)]
[Obsolete("This Evaluatable is obsolete. Use Boolean_FlipFlop instead.", false)]
public class Boolean_FlipFlopSR : Evaluatable<bool> {

private bool state = false;
Expand Down Expand Up @@ -74,4 +76,52 @@ protected override bool Execute(IGameState gameState) {

public override Evaluatable<bool> Clone() => new Boolean_FlipFlopSR(Set.Clone(), Reset.Clone());
}
}
#endregion

/// <summary>
/// A simple memory gate that can be used for storing a boolean state and also Toggle it.
/// When 'Set' is true, the gate will start outputting true until 'Reset' becomes true.
/// You can also Toggle it with the toggle input.
/// </summary>
[Evaluatable("Flip-flop", category: EvaluatableCategory.Logic)]
public class Boolean_FlipFlop : Evaluatable<bool>
{

private bool state = false;

public Evaluatable<bool> Toggle { get; set; }
public Evaluatable<bool> Set { get; set; }
public Evaluatable<bool> Reset { get; set; }

public Boolean_FlipFlop() : this(EvaluatableDefaults.Get<bool>(), EvaluatableDefaults.Get<bool>(), EvaluatableDefaults.Get<bool>()) { }
public Boolean_FlipFlop(Evaluatable<bool> toggle, Evaluatable<bool> set, Evaluatable<bool> reset) { Toggle = toggle; Set = set; Reset = reset; }

protected override bool Execute(IGameState gameState)
{
if (Toggle.Evaluate(gameState))
state = !state;
if (Reset.Evaluate(gameState))
state = false;
if (Set.Evaluate(gameState))
state = true;
return state;
}

public override Visual GetControl() => new StackPanel()
.WithChild(new TextBlock { Text = "Flip-Flop", FontWeight = FontWeights.Bold })
.WithChild(new StackPanel { Orientation = Orientation.Horizontal, Margin = new Thickness(0, 4, 0, 4) }
.WithChild(new Label { Content = "Toggle" })
.WithChild(new Control_EvaluatablePresenter { EvalType = typeof(bool) }
.WithBinding(Control_EvaluatablePresenter.ExpressionProperty, new Binding(nameof(Toggle)) { Source = this, Mode = BindingMode.TwoWay })))
.WithChild(new StackPanel { Orientation = Orientation.Horizontal }
.WithChild(new Label { Content = "Set" })
.WithChild(new Control_EvaluatablePresenter { EvalType = typeof(bool) }
.WithBinding(Control_EvaluatablePresenter.ExpressionProperty, new Binding(nameof(Set)) { Source = this, Mode = BindingMode.TwoWay })))
.WithChild(new StackPanel { Orientation = Orientation.Horizontal }
.WithChild(new Label { Content = "Reset" })
.WithChild(new Control_EvaluatablePresenter { EvalType = typeof(bool) }
.WithBinding(Control_EvaluatablePresenter.ExpressionProperty, new Binding(nameof(Reset)) { Source = this, Mode = BindingMode.TwoWay })));

public override Evaluatable<bool> Clone() => new Boolean_FlipFlop(Toggle.Clone(), Set.Clone(), Reset.Clone());
}
}