Skip to content

Commit

Permalink
Merge pull request #2009 from Wibble199/feature/evaluatable-debug
Browse files Browse the repository at this point in the history
Evaluatable debug
  • Loading branch information
diogotr7 committed May 17, 2020
2 parents d9ed030 + f5fcc84 commit 5a1befd
Show file tree
Hide file tree
Showing 35 changed files with 339 additions and 347 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private void setVolumeOverlay()
_MaxVariablePath = "100"
},

}, new Settings.Overrides.Logic.Builder.OverrideLogicBuilder().SetDynamicBoolean("_Enabled", new BooleanOr(new List<IEvaluatable<bool>> { new BooleanKeyDownWithTimer(Keys.VolumeUp, 3), new BooleanKeyDownWithTimer(Keys.VolumeDown, 3) }))));
}, new Settings.Overrides.Logic.Builder.OverrideLogicBuilder().SetDynamicBoolean("_Enabled", new BooleanOr(new List<Evaluatable<bool>> { new BooleanKeyDownWithTimer(Keys.VolumeUp, 3), new BooleanKeyDownWithTimer(Keys.VolumeDown, 3) }))));
}

public override void Reset()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,19 @@ public override void Reset()
};
}

public static OverrideLogicBuilder InGameAnd(IEvaluatable<bool> eval)
public static OverrideLogicBuilder InGameAnd(Evaluatable<bool> eval)
{
return new OverrideLogicBuilder().SetDynamicBoolean("_Enabled",
new BooleanAnd(
new IEvaluatable<bool>[] {
new Evaluatable<bool>[] {
new BooleanGSIBoolean("Match/InGame"),
eval
}
)
);
}

public static OverrideLogicBuilder EnabledWhen(IEvaluatable<bool> condition)
public static OverrideLogicBuilder EnabledWhen(Evaluatable<bool> condition)
{
return new OverrideLogicBuilder().SetDynamicBoolean("_Enabled", condition);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,21 +206,21 @@ public override void Reset()
},
new OverrideLogicBuilder()
.SetLookupTable("_PrimaryColor", new OverrideLookupTableBuilder<Color>()
.AddEntry(Color.FromArgb(125,42,123), new BooleanAnd(new IEvaluatable<bool>[] {
.AddEntry(Color.FromArgb(125,42,123), new BooleanAnd(new Evaluatable<bool>[] {
new BooleanGSINumeric("World/DimensionID", 1),
new BooleanGSIBoolean("Player/InGame")
}))//The End
.AddEntry(Color.FromArgb(255,183,0), new BooleanAnd(new IEvaluatable<bool>[] {
.AddEntry(Color.FromArgb(255,183,0), new BooleanAnd(new Evaluatable<bool>[] {
new BooleanGSINumeric("World/DimensionID", -1),
new BooleanGSIBoolean("Player/InGame")
}))//The Nether
)
.SetLookupTable("_SecondaryColor", new OverrideLookupTableBuilder<Color>()
.AddEntry(Color.FromArgb(49,0,59), new BooleanAnd(new IEvaluatable<bool>[] {
.AddEntry(Color.FromArgb(49,0,59), new BooleanAnd(new Evaluatable<bool>[] {
new BooleanGSINumeric("World/DimensionID", 1),
new BooleanGSIBoolean("Player/InGame")
}))//The End
.AddEntry(Color.FromArgb(87,83,0), new BooleanAnd(new IEvaluatable<bool>[] {
.AddEntry(Color.FromArgb(87,83,0), new BooleanAnd(new Evaluatable<bool>[] {
new BooleanGSINumeric("World/DimensionID", -1),
new BooleanGSIBoolean("Player/InGame")
}))//The Nether
Expand All @@ -235,21 +235,21 @@ public override void Reset()
},
new OverrideLogicBuilder()
.SetLookupTable("_PrimaryColor", new OverrideLookupTableBuilder<Color>()
.AddEntry(Color.FromArgb(209,232,80), new BooleanAnd(new IEvaluatable<bool>[] {
.AddEntry(Color.FromArgb(209,232,80), new BooleanAnd(new Evaluatable<bool>[] {
new BooleanGSINumeric("World/DimensionID", 1),
new BooleanGSIBoolean("Player/InGame")
}))//The End
.AddEntry(Color.FromArgb(184,26,0), new BooleanAnd(new IEvaluatable<bool>[] {
.AddEntry(Color.FromArgb(184,26,0), new BooleanAnd(new Evaluatable<bool>[] {
new BooleanGSINumeric("World/DimensionID", -1),
new BooleanGSIBoolean("Player/InGame")
}))//The Nether
)
.SetLookupTable("_SecondaryColor", new OverrideLookupTableBuilder<Color>()
.AddEntry(Color.FromArgb(107,102,49),new BooleanAnd(new IEvaluatable<bool>[] {
.AddEntry(Color.FromArgb(107,102,49),new BooleanAnd(new Evaluatable<bool>[] {
new BooleanGSINumeric("World/DimensionID", 1),
new BooleanGSIBoolean("Player/InGame")
}))//The End
.AddEntry(Color.FromArgb(59,8,0), new BooleanAnd(new IEvaluatable<bool>[] {
.AddEntry(Color.FromArgb(59,8,0), new BooleanAnd(new Evaluatable<bool>[] {
new BooleanGSINumeric("World/DimensionID", -1),
new BooleanGSIBoolean("Player/InGame")
}))//The Nether
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public override void Reset()
}
},
new OverrideLogicBuilder()
.SetDynamicDouble("_Value", new IfElseNumeric( new BooleanAnd( new List<IEvaluatable<bool>>{//if match is tied 0 - 0
.SetDynamicDouble("_Value", new IfElseNumeric( new BooleanAnd( new List<Evaluatable<bool>>{//if match is tied 0 - 0
new BooleanMathsComparison(new NumberGSINumeric("YourTeam/Goals"), new NumberConstant(0)),
new BooleanMathsComparison(new NumberGSINumeric("OpponentTeam/Goals"), new NumberConstant(0))
}
Expand All @@ -87,7 +87,7 @@ public override void Reset()
new NumberGSINumeric("YourTeam/Goals")//otherwise set to our goals
)
)
.SetDynamicDouble("_MaxValue", new IfElseNumeric( new BooleanAnd( new List<IEvaluatable<bool>>{//if match is tied 0 - 0
.SetDynamicDouble("_MaxValue", new IfElseNumeric( new BooleanAnd( new List<Evaluatable<bool>>{//if match is tied 0 - 0
new BooleanMathsComparison(new NumberGSINumeric("YourTeam/Goals"), new NumberConstant(0)),
new BooleanMathsComparison(new NumberGSINumeric("OpponentTeam/Goals"), new NumberConstant(0))
}
Expand Down
2 changes: 1 addition & 1 deletion Project-Aurora/Project-Aurora/Project-Aurora.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@
<Compile Include="Settings\Overrides\Logic\Control_SublogicHolder.xaml.cs">
<DependentUpon>Control_SublogicHolder.xaml</DependentUpon>
</Compile>
<Compile Include="Settings\Overrides\Logic\IEvaluatable.cs" />
<Compile Include="Settings\Overrides\Logic\Evaluatable.cs" />
<Compile Include="Settings\Overrides\Logic\OverrideLogicBuilder.cs" />
<Compile Include="Settings\Overrides\Logic\OverrideLookupTable.cs" />
<Compile Include="Settings\Overrides\LogicOverridableAttribute.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ private void CheckTriggers(IGameState gamestate) {
} else if (IsTriggerNumericValueBased(Properties.TriggerMode) || IsTriggerEvaluatableNumericValueBased(Properties.TriggerMode)) {
// Evaluate the evaluatable or the game state path and retrieve the double
double resolvedTriggerValue = IsTriggerEvaluatableNumericValueBased(Properties.TriggerMode)
? ((IEvaluatable<double>)Properties.EvaluatableTrigger)?.Evaluate(gamestate) ?? 0 // Evaluatable may be null, so we need to account for that
? ((Evaluatable<double>)Properties.EvaluatableTrigger)?.Evaluate(gamestate) ?? 0 // Evaluatable may be null, so we need to account for that
: gamestate.GetNumber(Properties.TriggerPath);

// Check to see if a gamestate value change should trigger the animation
Expand All @@ -242,7 +242,7 @@ private void CheckTriggers(IGameState gamestate) {
} else {
// Evaluatable the boolean, either as an evaluatable or a game state variable.
bool resolvedTriggerValue = IsTriggerEvaluatableBooleanValueBased(Properties.TriggerMode)
? ((IEvaluatable<bool>)Properties.EvaluatableTrigger)?.Evaluate(gamestate) ?? false // Evaluatable may be null, so we need to account for that
? ((Evaluatable<bool>)Properties.EvaluatableTrigger)?.Evaluate(gamestate) ?? false // Evaluatable may be null, so we need to account for that
: gamestate.GetBool(Properties.TriggerPath);

switch (Properties.TriggerMode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ private void triggerMode_SelectionChanged(object sender, SelectionChangedEventAr
UpdateUI();

// If the evaluatable is not the correct type or it is null, then create the default Evaluatable for it
if (AnimationLayerHandler.IsTriggerEvaluatableNumericValueBased(selectedItem) && !typeof(IEvaluatable<double>).IsAssignableFrom(Context.Properties._EvaluatableTrigger?.GetType()))
if (AnimationLayerHandler.IsTriggerEvaluatableNumericValueBased(selectedItem) && !typeof(Evaluatable<double>).IsAssignableFrom(Context.Properties._EvaluatableTrigger?.GetType()))
Context.Properties._EvaluatableTrigger = EvaluatableDefaults.Get<double>();
else if (AnimationLayerHandler.IsTriggerEvaluatableBooleanValueBased(selectedItem) && !typeof(IEvaluatable<bool>).IsAssignableFrom(Context.Properties._EvaluatableTrigger?.GetType()))
else if (AnimationLayerHandler.IsTriggerEvaluatableBooleanValueBased(selectedItem) && !typeof(Evaluatable<bool>).IsAssignableFrom(Context.Properties._EvaluatableTrigger?.GetType()))
Context.Properties._EvaluatableTrigger = EvaluatableDefaults.Get<bool>();

// Update the evaluatable control
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Aurora.Settings"
xmlns:conditions="clr-namespace:Aurora.Settings.Overrides.Logic"
xmlns:controls="clr-namespace:Aurora.Controls"
xmlns:overrides="clr-namespace:Aurora.Settings.Overrides"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:l="clr-namespace:Aurora.Settings.Overrides.Logic"
xmlns:o="clr-namespace:Aurora.Settings.Overrides"
xmlns:utils="clr-namespace:Aurora.Utils"
mc:Ignorable="d"
d:DesignHeight="520" d:DesignWidth="920">
<UserControl.Resources>
<overrides:PrettyTypeNameConverter x:Key="PrettyTypeNameConv" />
<overrides:TypeToIconConverter x:Key="TypeToIconConv" />
<overrides:HasValueToBoolConverter x:Key="HasValToBoolConv" />
<o:PrettyTypeNameConverter x:Key="PrettyTypeNameConv" />
<o:TypeToIconConverter x:Key="TypeToIconConv" />
<o:HasValueToBoolConverter x:Key="HasValToBoolConv" />
</UserControl.Resources>

<Grid>
Expand Down Expand Up @@ -54,5 +52,7 @@
<Button Margin="0,9,10,0" Grid.ColumnSpan="999" HorizontalAlignment="Right" VerticalAlignment="Top" Click="HelpButton_Click">
<Image Source="/Aurora;component/Resources/Question_Help.png" Width="23" Height="23" Margin="2"/>
</Button>

<CheckBox IsChecked="{Binding (l:EvaluatablePresenterAddons.ShowDebugInfo), RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type o:Control_OverridesEditor}}, Mode=TwoWay}" Content="Debug values" Margin="0,13,90,0" Grid.ColumnSpan="999" HorizontalAlignment="Right" VerticalAlignment="Top" />
</Grid>
</UserControl>
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Aurora.Settings.Overrides.Logic {
/// Condition that accesses a specific game state variable (of boolean type) and returns the state.
/// </summary>
[Evaluatable("Boolean State Variable", category: EvaluatableCategory.State)]
public class BooleanGSIBoolean : IEvaluatable<bool> {
public class BooleanGSIBoolean : Evaluatable<bool> {

/// <summary>Creates an empty boolean state variable lookup.</summary>
public BooleanGSIBoolean() { }
Expand All @@ -24,14 +24,12 @@ public BooleanGSIBoolean() { }
/// so that the application be updated if required.</summary>
[Newtonsoft.Json.JsonIgnore]
private Control_ConditionGSIBoolean control;
public Visual GetControl() => control ?? (control = new Control_ConditionGSIBoolean(this));
public override Visual GetControl() => control ?? (control = new Control_ConditionGSIBoolean(this));

/// <summary>Fetches the given boolean value from the game state and returns it.</summary>
public bool Evaluate(IGameState gameState) => gameState.GetBool(VariablePath);
object IEvaluatable.Evaluate(IGameState gameState) => Evaluate(gameState);
protected override bool Execute(IGameState gameState) => gameState.GetBool(VariablePath);

public IEvaluatable<bool> Clone() => new BooleanGSIBoolean { VariablePath = VariablePath };
IEvaluatable IEvaluatable.Clone() => Clone();
public override Evaluatable<bool> Clone() => new BooleanGSIBoolean { VariablePath = VariablePath };
}


Expand All @@ -40,7 +38,7 @@ public BooleanGSIBoolean() { }
/// Condition that accesses some specified game state variables (of numeric type) and returns a comparison between them.
/// </summary>
[Evaluatable("Numeric State Variable", category: EvaluatableCategory.State)]
public class BooleanGSINumeric : IEvaluatable<bool> {
public class BooleanGSINumeric : Evaluatable<bool> {

/// <summary>Creates a blank numeric game state lookup evaluatable.</summary>
public BooleanGSINumeric() { }
Expand All @@ -61,10 +59,10 @@ public BooleanGSINumeric() { }
// Control assigned to this condition
[Newtonsoft.Json.JsonIgnore]
private Control_ConditionGSINumeric control;
public Visual GetControl() => control ?? (control = new Control_ConditionGSINumeric(this));
public override Visual GetControl() => control ?? (control = new Control_ConditionGSINumeric(this));

/// <summary>Parses the numbers, compares the result, and returns the result.</summary>
public bool Evaluate(IGameState gameState) {
protected override bool Execute(IGameState gameState) {
// Parse the operands (either as numbers or paths)
double op1 = gameState.GetNumber(Operand1Path);
double op2 = gameState.GetNumber(Operand2Path);
Expand All @@ -80,10 +78,8 @@ public bool Evaluate(IGameState gameState) {
default: return false;
}
}
object IEvaluatable.Evaluate(IGameState gameState) => Evaluate(gameState);

public IEvaluatable<bool> Clone() => new BooleanGSINumeric { Operand1Path = Operand1Path, Operand2Path = Operand2Path, Operator = Operator };
IEvaluatable IEvaluatable.Clone() => Clone();

public override Evaluatable<bool> Clone() => new BooleanGSINumeric { Operand1Path = Operand1Path, Operand2Path = Operand2Path, Operator = Operator };
}


Expand All @@ -92,7 +88,7 @@ public bool Evaluate(IGameState gameState) {
/// Condition that accesses a specified game state variable (of any enum type) and returns a comparison between it and a static enum of the same type.
/// </summary>
[Evaluatable("Enum State Variable", category: EvaluatableCategory.State)]
public class BooleanGSIEnum : IEvaluatable<bool> {
public class BooleanGSIEnum : Evaluatable<bool> {

/// <summary>Creates a blank enum game state lookup evaluatable.</summary>
public BooleanGSIEnum() { }
Expand All @@ -109,16 +105,14 @@ public BooleanGSIEnum() { }

// Control
private Control_BooleanGSIEnum control;
public Visual GetControl() => control ?? (control = new Control_BooleanGSIEnum(this));
public override Visual GetControl() => control ?? (control = new Control_BooleanGSIEnum(this));

/// <summary>Parses the numbers, compares the result, and returns the result.</summary>
public bool Evaluate(IGameState gameState) {
protected override bool Execute(IGameState gameState) {
var @enum = gameState.GetEnum(StatePath);
return @enum != null && @enum.Equals(EnumValue);
}
object IEvaluatable.Evaluate(IGameState gameState) => Evaluate(gameState);

public IEvaluatable<bool> Clone() => new BooleanGSIEnum { StatePath = StatePath, EnumValue = EnumValue };
IEvaluatable IEvaluatable.Clone() => Clone();

public override Evaluatable<bool> Clone() => new BooleanGSIEnum { StatePath = StatePath, EnumValue = EnumValue };
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,25 @@ namespace Aurora.Settings.Overrides.Logic.Boolean {
/// When 'Set' is true, the gate will start outputting true until 'Reset' becomes true.
/// </summary>
[Evaluatable("Flip-flop", category: EvaluatableCategory.Logic)]
public class Boolean_Latch : IEvaluatable<bool> {
public class Boolean_Latch : Evaluatable<bool> {

private bool state = false;

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

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

public bool Evaluate(IGameState gameState) {
protected override bool Execute(IGameState gameState) {
if (Reset.Evaluate(gameState))
state = false;
if (Set.Evaluate(gameState))
state = true;
return state;
}
object IEvaluatable.Evaluate(IGameState gameState) => Evaluate(gameState);

public Visual GetControl() => new StackPanel()

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 = "Set" })
Expand All @@ -42,7 +41,6 @@ public bool Evaluate(IGameState gameState) {
.WithChild(new Control_EvaluatablePresenter { EvalType = typeof(bool) }
.WithBinding(Control_EvaluatablePresenter.ExpressionProperty, new Binding(nameof(Reset)) { Source = this, Mode = BindingMode.TwoWay })));

public IEvaluatable<bool> Clone() => new Boolean_Latch(Set.Clone(), Reset.Clone());
IEvaluatable IEvaluatable.Clone() => Clone();
public override Evaluatable<bool> Clone() => new Boolean_Latch(Set.Clone(), Reset.Clone());
}
}
Loading

0 comments on commit 5a1befd

Please sign in to comment.