forked from antonpup/Aurora
-
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add /variables POST endpoint, and GSI functions to get them
- Loading branch information
Aytackydln
committed
Dec 24, 2024
1 parent
e993a32
commit fef5829
Showing
6 changed files
with
223 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace AuroraRgb.Nodes; | ||
|
||
public class AuroraVariables | ||
{ | ||
public static readonly AuroraVariables Instance = new(); | ||
|
||
public Dictionary<string, bool> Booleans { get; } = new(8); | ||
public Dictionary<string, double> Numbers { get; } = new(8); | ||
public Dictionary<string, string> Strings { get; } = new(8); | ||
} |
47 changes: 47 additions & 0 deletions
47
Project-Aurora/Project-Aurora/Settings/Overrides/Logic/Boolean/Boolean_Variable.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using System.Collections.Generic; | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
using System.Windows.Data; | ||
using System.Windows.Media; | ||
using AuroraRgb.Nodes; | ||
using AuroraRgb.Profiles; | ||
using AuroraRgb.Utils; | ||
|
||
namespace AuroraRgb.Settings.Overrides.Logic.Boolean; | ||
|
||
[Evaluatable("Boolean Global Variable", category: EvaluatableCategory.Global)] | ||
public class Boolean_Variable : Evaluatable<bool> | ||
{ | ||
public Evaluatable<bool> DefaultValue { get; set; } = new BooleanConstant(); | ||
public Evaluatable<string> VariableName { get; set; } = new StringConstant(); | ||
|
||
public Boolean_Variable() { } | ||
|
||
public Boolean_Variable(Evaluatable<string> variableName, Evaluatable<bool> defaultValue) { | ||
VariableName = variableName; | ||
DefaultValue = defaultValue; | ||
} | ||
|
||
protected override bool Execute(IGameState gameState) | ||
{ | ||
var key = VariableName.Evaluate(gameState); | ||
var defaultValue = DefaultValue.Evaluate(gameState); | ||
return AuroraVariables.Instance.Booleans.GetValueOrDefault(key, defaultValue); | ||
} | ||
|
||
public override Visual GetControl() | ||
{ | ||
return new StackPanel { Orientation = Orientation.Horizontal } | ||
.WithChild(new TextBlock { Text = "Name", FontWeight = FontWeights.Bold, Margin = new Thickness(2, 0, 6, 0), VerticalAlignment = VerticalAlignment.Center }) | ||
.WithChild(new Control_EvaluatablePresenter { EvalType = typeof(string) } | ||
.WithBinding(Control_EvaluatablePresenter.ExpressionProperty, new Binding(nameof(VariableName)) { Source = this, Mode = BindingMode.TwoWay })) | ||
.WithChild(new TextBlock { Text = "Default Value", FontWeight = FontWeights.Bold, Margin = new Thickness(2, 0, 6, 0), VerticalAlignment = VerticalAlignment.Center }) | ||
.WithChild(new Control_EvaluatablePresenter { EvalType = typeof(bool) } | ||
.WithBinding(Control_EvaluatablePresenter.ExpressionProperty, new Binding(nameof(DefaultValue)) { Source = this, Mode = BindingMode.TwoWay })); | ||
} | ||
|
||
public override Evaluatable<bool> Clone() | ||
{ | ||
return new Boolean_Variable(VariableName, DefaultValue); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
Project-Aurora/Project-Aurora/Settings/Overrides/Logic/Number/Number_Variable.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using System.Collections.Generic; | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
using System.Windows.Data; | ||
using System.Windows.Media; | ||
using AuroraRgb.Nodes; | ||
using AuroraRgb.Profiles; | ||
using AuroraRgb.Utils; | ||
|
||
namespace AuroraRgb.Settings.Overrides.Logic.Number; | ||
|
||
[Evaluatable("Number Global Variable", category: EvaluatableCategory.Global)] | ||
public class Number_Variable : Evaluatable<double> | ||
{ | ||
public Evaluatable<double> DefaultValue { get; set; } = new NumberConstant(); | ||
public Evaluatable<string> VariableName { get; set; } = new StringConstant(); | ||
|
||
public Number_Variable() { } | ||
|
||
public Number_Variable(Evaluatable<string> variableName, Evaluatable<double> defaultValue) { | ||
VariableName = variableName; | ||
DefaultValue = defaultValue; | ||
} | ||
|
||
protected override double Execute(IGameState gameState) | ||
{ | ||
var key = VariableName.Evaluate(gameState); | ||
var defaultValue = DefaultValue.Evaluate(gameState); | ||
return AuroraVariables.Instance.Numbers.GetValueOrDefault(key, defaultValue); | ||
} | ||
|
||
public override Visual GetControl() | ||
{ | ||
return new StackPanel { Orientation = Orientation.Horizontal } | ||
.WithChild(new TextBlock { Text = "Name", FontWeight = FontWeights.Bold, Margin = new Thickness(2, 0, 6, 0), VerticalAlignment = VerticalAlignment.Center }) | ||
.WithChild(new Control_EvaluatablePresenter { EvalType = typeof(string) } | ||
.WithBinding(Control_EvaluatablePresenter.ExpressionProperty, new Binding(nameof(VariableName)) { Source = this, Mode = BindingMode.TwoWay })) | ||
.WithChild(new TextBlock { Text = "Default Value", FontWeight = FontWeights.Bold, Margin = new Thickness(2, 0, 6, 0), VerticalAlignment = VerticalAlignment.Center }) | ||
.WithChild(new Control_EvaluatablePresenter { EvalType = typeof(double) } | ||
.WithBinding(Control_EvaluatablePresenter.ExpressionProperty, new Binding(nameof(DefaultValue)) { Source = this, Mode = BindingMode.TwoWay })); | ||
} | ||
|
||
public override Evaluatable<double> Clone() | ||
{ | ||
return new Number_Variable(VariableName, DefaultValue); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
Project-Aurora/Project-Aurora/Settings/Overrides/Logic/String/String_Variable.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System.Collections.Generic; | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
using System.Windows.Data; | ||
using System.Windows.Media; | ||
using AuroraRgb.Nodes; | ||
using AuroraRgb.Profiles; | ||
using AuroraRgb.Utils; | ||
|
||
namespace AuroraRgb.Settings.Overrides.Logic; | ||
|
||
[Evaluatable("String Global Variable", category: EvaluatableCategory.Global)] | ||
public class String_Variable : Evaluatable<string> | ||
{ | ||
public Evaluatable<string> DefaultValue { get; set; } = new StringConstant(); | ||
public Evaluatable<string> VariableName { get; set; } = new StringConstant(); | ||
|
||
public String_Variable() { } | ||
|
||
public String_Variable(Evaluatable<string> variableName, Evaluatable<string> defaultValue) | ||
{ | ||
VariableName = variableName; | ||
DefaultValue = defaultValue; | ||
} | ||
|
||
protected override string Execute(IGameState gameState) | ||
{ | ||
var key = VariableName.Evaluate(gameState); | ||
var defaultValue = DefaultValue.Evaluate(gameState); | ||
return AuroraVariables.Instance.Strings.GetValueOrDefault(key, defaultValue); | ||
} | ||
|
||
public override Visual GetControl() | ||
{ | ||
return new StackPanel { Orientation = Orientation.Horizontal } | ||
.WithChild(new TextBlock { Text = "Name", FontWeight = FontWeights.Bold, Margin = new Thickness(2, 0, 6, 0), VerticalAlignment = VerticalAlignment.Center }) | ||
.WithChild(new Control_EvaluatablePresenter { EvalType = typeof(string) } | ||
.WithBinding(Control_EvaluatablePresenter.ExpressionProperty, new Binding(nameof(VariableName)) { Source = this, Mode = BindingMode.TwoWay })) | ||
.WithChild(new TextBlock { Text = "Default Value", FontWeight = FontWeights.Bold, Margin = new Thickness(2, 0, 6, 0), VerticalAlignment = VerticalAlignment.Center }) | ||
.WithChild(new Control_EvaluatablePresenter { EvalType = typeof(string) } | ||
.WithBinding(Control_EvaluatablePresenter.ExpressionProperty, new Binding(nameof(DefaultValue)) { Source = this, Mode = BindingMode.TwoWay })); | ||
} | ||
|
||
public override Evaluatable<string> Clone() | ||
{ | ||
return new String_Variable(VariableName, DefaultValue); | ||
} | ||
} |