1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Cleaned up F1 2017 module

Cleaned up WoW module
Fixed Rocket League module crash
Added fade support to entire folders
This commit is contained in:
SpoinkyNL 2017-11-12 11:22:58 +01:00
parent 53b88be937
commit 06eaf42590
7 changed files with 225 additions and 204 deletions

View File

@ -196,11 +196,6 @@ namespace Artemis.Modules.Games.FormulaOne2017
public float LateralG { get; set; }
public float LongitudinalG { get; set; }
public float WheelSpeedFrontLeft { get; set; }
public float WheelSpeedFrontRight { get; set; }
public float WheelSpeedRearLeft { get; set; }
public float WheelSpeedRearRight { get; set; }
}
[MoonSharpUserData]

View File

@ -13,7 +13,6 @@ namespace Artemis.Modules.Games.FormulaOne2017
{
private bool _mustListen;
private UdpClient _udpClient;
private UdpClient _udpListener;
private DateTime _lastUpdate;
private int _revAtZeroFrames;
@ -105,11 +104,6 @@ namespace Artemis.Modules.Games.FormulaOne2017
dataModel.Car.Details.LateralG = msg.m_gforce_lat;
dataModel.Car.Details.LongitudinalG = msg.m_gforce_lon;
// dataModel.Car.Details.WheelSpeedFrontLeft = msg.m_wheel_speed_fl;
// dataModel.Car.Details.WheelSpeedFrontRight = msg.m_wheel_speed_fr;
// dataModel.Car.Details.WheelSpeedRearLeft = msg.m_wheel_speed_bl;
// dataModel.Car.Details.WheelSpeedRearRight = msg.m_wheel_speed_br;
dataModel.Session.SessionType = (SessionType) msg.m_sessionType;
// It's unknown in time trial but lets overwrite that to race
if (dataModel.Session.SessionType == SessionType.Unknown && dataModel.Car.SpeedMph > 0)

View File

@ -22,10 +22,15 @@
<!-- Header -->
<Label Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" FontSize="20" HorizontalAlignment="Left">
<Label.Content>
<AccessText TextWrapping="Wrap" Text="By default shows RPM on the F-keys, gear on the other keys and track flags on the numpad." />
<AccessText TextWrapping="Wrap" Text="There is currently no default profile available for F1 2017." />
</Label.Content>
</Label>
<!-- Sub header -->
<TextBlock Grid.Row="1" Grid.Column="0" VerticalAlignment="Bottom" TextWrapping="Wrap" HorizontalAlignment="Left" FontFamily="Segoe UI Semibold" TextAlignment="Justify" Margin="5,0,0,10">
The F1 2017 module requires UDP Telemetry to be enabled in the ingame settings menu.
</TextBlock>
<!-- Enable -->
<StackPanel Grid.Row="1" Grid.Column="1" HorizontalAlignment="Right" Orientation="Horizontal">
<Label Content="Enable module" HorizontalAlignment="Right" Margin="0,0,0,3" />

View File

@ -41,7 +41,7 @@ namespace Artemis.Modules.Games.RocketLeague
}
Updater.GetPointers();
var version = SettingsProvider.Load<OffsetSettings>().RocketLeague.GameVersion;
var version = SettingsProvider.Load<OffsetSettings>().RocketLeague?.GameVersion;
VersionText = $"Requires patch {version}. When a new patch is released Artemis downloads new pointers for the latest version (unless disabled in settings).";
}
}

View File

@ -16,7 +16,7 @@
<!-- Header -->
<Label Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" FontSize="20" HorizontalAlignment="Left">
<Label.Content>
<AccessText TextWrapping="Wrap" Text="Fight the Legion in style with reactive lighting." />
<AccessText TextWrapping="Wrap" Text="There is currently no default profile available for World of Warcraft." />
</Label.Content>
</Label>

View File

@ -1,174 +1,174 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text.RegularExpressions;
using System.Windows.Documents;
using Artemis.Modules.Abstract;
using Artemis.Utilities;
using DynamicExpresso;
using MahApps.Metro.Controls;
namespace Artemis.Profiles.Layers.Models
{
public class LayerConditionModel
{
private readonly Interpreter _interpreter;
private object _lastValue;
private Regex _rgx;
public LayerConditionModel()
{
_interpreter = new Interpreter();
_rgx = new Regex("\\((.*?)\\)");
}
public string Field { get; set; }
public string Value { get; set; }
public string Operator { get; set; }
public string Type { get; set; }
public HotKey HotKey { get; set; }
public bool ConditionMet(ModuleDataModel subject)
{
lock (subject)
{
if (string.IsNullOrEmpty(Field) || string.IsNullOrEmpty(Type))
return false;
// If the path points to a collection, look inside this collection
if (Field.Contains("("))
{
// Find the collection in the field path
var collectionField = _rgx.Match(Field).Groups[1].Value;
var collectionInspect = (IEnumerable) GeneralHelpers.GetPropertyValue(subject, collectionField);
var operatorParts = Operator.Split('|');
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text.RegularExpressions;
using System.Windows.Documents;
using Artemis.Modules.Abstract;
using Artemis.Utilities;
using DynamicExpresso;
using MahApps.Metro.Controls;
namespace Artemis.Profiles.Layers.Models
{
public class LayerConditionModel
{
private readonly Interpreter _interpreter;
private object _lastValue;
private Regex _rgx;
public LayerConditionModel()
{
_interpreter = new Interpreter();
_rgx = new Regex("\\((.*?)\\)");
}
public string Field { get; set; }
public string Value { get; set; }
public string Operator { get; set; }
public string Type { get; set; }
public HotKey HotKey { get; set; }
public bool ConditionMet(ModuleDataModel subject)
{
lock (subject)
{
if (string.IsNullOrEmpty(Field) || string.IsNullOrEmpty(Type))
return false;
// If the path points to a collection, look inside this collection
if (Field.Contains("("))
{
// Find the collection in the field path
var collectionField = _rgx.Match(Field).Groups[1].Value;
var collectionInspect = (IEnumerable) GeneralHelpers.GetPropertyValue(subject, collectionField);
var operatorParts = Operator.Split('|');
var field = Field.Split(')').Last().Substring(1);
_lastValue = collectionInspect;
if (operatorParts[0] == "any")
{
var anyMatch = false;
foreach (var collectionValue in collectionInspect)
{
anyMatch = EvaluateOperator(collectionValue, field, operatorParts[1]);
if (anyMatch)
break;
}
return anyMatch;
}
if (operatorParts[0] == "all")
{
var allMatch = true;
foreach (var collectionValue in collectionInspect)
{
allMatch = EvaluateOperator(collectionValue, field, operatorParts[1]);
if (!allMatch)
break;
}
return allMatch;
}
if (operatorParts[0] == "none")
{
var noneMatch = true;
foreach (var collectionValue in collectionInspect)
{
noneMatch = !EvaluateOperator(collectionValue, field, operatorParts[1]);
if (!noneMatch)
break;
}
return noneMatch;
}
}
var inspect = GeneralHelpers.GetPropertyValue(subject, Field);
if (inspect == null)
{
_lastValue = null;
return false;
}
bool returnValue;
if (Operator == "changed" || Operator == "decreased" || Operator == "increased")
returnValue = EvaluateEventOperator(subject, inspect);
else
returnValue = EvaluateOperator(subject, Field);
_lastValue = inspect;
return returnValue;
}
}
private bool EvaluateEventOperator(ModuleDataModel subject, object inspect)
{
// DynamicExpresso doesn't want a null so when it was previously null (should only happen first iteration)
// return false since that would be the only possible outcome
if (_lastValue == null)
return false;
// Assign the right parameter
var rightParam = new Parameter("value", _lastValue);
// Come up with the proper operator
var changeOperator = "";
if (Operator == "changed")
changeOperator = "!=";
else if (Operator == "decreased")
changeOperator = "<";
else if (Operator == "increased")
changeOperator = ">";
// Evaluate the result and store it
var returnValue = _interpreter.Eval<bool>($"subject.{Field} {changeOperator} value", new Parameter("subject", subject.GetType(), subject), rightParam);
// Set the last value to the new value
_lastValue = inspect;
// Return the evaluated result
return returnValue;
}
private bool EvaluateOperator(object subject, string field, string operatorOverwrite = null)
{
// Since _lastValue won't be used, rely on Value to not be null
if (string.IsNullOrEmpty(Value))
return false;
if (Type == "String")
{
var stringExpressionText = operatorOverwrite == null
? $"subject.{field}.ToLower(){Operator}(value)"
: $"subject.{field}.ToLower(){operatorOverwrite}(value)";
return _interpreter.Eval<bool>(stringExpressionText, new Parameter("subject", subject.GetType(), subject), new Parameter("value", Value.ToLower()));
}
Parameter rightParam = null;
switch (Type)
{
case "Enum":
var enumType = GeneralHelpers.GetPropertyValue(subject, field).GetType();
rightParam = new Parameter("value", Enum.Parse(enumType, Value));
break;
case "Boolean":
rightParam = new Parameter("value", bool.Parse(Value));
break;
case "Int32":
rightParam = new Parameter("value", int.Parse(Value));
break;
case "Single":
// Parse commas as decimals
rightParam = new Parameter("value", float.Parse(Value.Replace(",", "."),
CultureInfo.InvariantCulture));
break;
}
var expressionText = operatorOverwrite == null
? $"subject.{field} {Operator} value"
: $"subject.{field} {operatorOverwrite} value";
return _interpreter.Eval<bool>(expressionText, new Parameter("subject", subject.GetType(), subject), rightParam);
}
}
}
_lastValue = collectionInspect;
if (operatorParts[0] == "any")
{
var anyMatch = false;
foreach (var collectionValue in collectionInspect)
{
anyMatch = EvaluateOperator(collectionValue, field, operatorParts[1]);
if (anyMatch)
break;
}
return anyMatch;
}
if (operatorParts[0] == "all")
{
var allMatch = true;
foreach (var collectionValue in collectionInspect)
{
allMatch = EvaluateOperator(collectionValue, field, operatorParts[1]);
if (!allMatch)
break;
}
return allMatch;
}
if (operatorParts[0] == "none")
{
var noneMatch = true;
foreach (var collectionValue in collectionInspect)
{
noneMatch = !EvaluateOperator(collectionValue, field, operatorParts[1]);
if (!noneMatch)
break;
}
return noneMatch;
}
}
var inspect = GeneralHelpers.GetPropertyValue(subject, Field);
if (inspect == null)
{
_lastValue = null;
return false;
}
bool returnValue;
if (Operator == "changed" || Operator == "decreased" || Operator == "increased")
returnValue = EvaluateEventOperator(subject, inspect);
else
returnValue = EvaluateOperator(subject, Field);
_lastValue = inspect;
return returnValue;
}
}
private bool EvaluateEventOperator(ModuleDataModel subject, object inspect)
{
// DynamicExpresso doesn't want a null so when it was previously null (should only happen first iteration)
// return false since that would be the only possible outcome
if (_lastValue == null)
return false;
// Assign the right parameter
var rightParam = new Parameter("value", _lastValue);
// Come up with the proper operator
var changeOperator = "";
if (Operator == "changed")
changeOperator = "!=";
else if (Operator == "decreased")
changeOperator = "<";
else if (Operator == "increased")
changeOperator = ">";
// Evaluate the result and store it
var returnValue = _interpreter.Eval<bool>($"subject.{Field} {changeOperator} value", new Parameter("subject", subject.GetType(), subject), rightParam);
// Set the last value to the new value
_lastValue = inspect;
// Return the evaluated result
return returnValue;
}
private bool EvaluateOperator(object subject, string field, string operatorOverwrite = null)
{
// Since _lastValue won't be used, rely on Value to not be null
if (string.IsNullOrEmpty(Value))
return false;
if (Type == "String")
{
var stringExpressionText = operatorOverwrite == null
? $"subject.{field}.ToLower(){Operator}(value)"
: $"subject.{field}.ToLower(){operatorOverwrite}(value)";
return _interpreter.Eval<bool>(stringExpressionText, new Parameter("subject", subject.GetType(), subject), new Parameter("value", Value.ToLower()));
}
Parameter rightParam = null;
switch (Type)
{
case "Enum":
var enumType = GeneralHelpers.GetPropertyValue(subject, field).GetType();
rightParam = new Parameter("value", Enum.Parse(enumType, Value));
break;
case "Boolean":
rightParam = new Parameter("value", bool.Parse(Value));
break;
case "Int32":
rightParam = new Parameter("value", int.Parse(Value));
break;
case "Single":
// Parse commas as decimals
rightParam = new Parameter("value", float.Parse(Value.Replace(",", "."),
CultureInfo.InvariantCulture));
break;
}
var expressionText = operatorOverwrite == null
? $"subject.{field} {Operator} value"
: $"subject.{field} {operatorOverwrite} value";
return _interpreter.Eval<bool>(expressionText, new Parameter("subject", subject.GetType(), subject), rightParam);
}
}
}

View File

@ -53,7 +53,7 @@ namespace Artemis.Profiles.Layers.Models
if (!Enabled)
return false;
_fadeTweener?.Update(40);
FadeTweener?.Update(40);
var conditionsMet = LayerCondition.ConditionsMet(this, dataModel);
if (conditionsMet && !_conditionsMetLastFrame)
OnLayerConditionsMet();
@ -61,7 +61,7 @@ namespace Artemis.Profiles.Layers.Models
OnLayerConditionsUnmet();
_conditionsMetLastFrame = conditionsMet;
return _fadeTweener != null && _fadeTweener.Running || conditionsMet;
return FadeTweener != null && FadeTweener.Running || conditionsMet;
}
/// <summary>
@ -74,7 +74,7 @@ namespace Artemis.Profiles.Layers.Models
{
if (LayerType == null)
return;
LayerType.Update(this, dataModel, preview);
LayerAnimation?.Update(this, updateAnimations);
@ -114,12 +114,37 @@ namespace Artemis.Profiles.Layers.Models
if (Brush == null || !preview && !RenderAllowed)
return;
// If fading in/out, push transparency on the entire context
if (_fadeTweener != null && _fadeTweener.Running)
c.PushOpacity(_fadeTweener.Value);
ApplyHierarchyOpacity(c);
LayerType.Draw(this, c);
if (_fadeTweener != null && _fadeTweener.Running)
PopHierarchyOpacity(c);
}
private void ApplyHierarchyOpacity(DrawingContext c)
{
if (FadeTweener != null && FadeTweener.Running)
c.PushOpacity(FadeTweener.Value);
var current = this;
while (current.Parent != null)
{
current = current.Parent;
if (current.FadeTweener != null && current.FadeTweener.Running)
c.PushOpacity(current.FadeTweener.Value);
}
}
private void PopHierarchyOpacity(DrawingContext c)
{
if (FadeTweener != null && FadeTweener.Running)
c.Pop();
var current = this;
while (current.Parent != null)
{
current = current.Parent;
if (current.FadeTweener != null && current.FadeTweener.Running)
c.Pop();
}
}
/// <summary>
@ -128,7 +153,7 @@ namespace Artemis.Profiles.Layers.Models
public void SetupProperties()
{
LayerType.SetupProperties(this);
// If the type is an event, set it up
if (IsEvent && EventProperties == null)
EventProperties = new KeyboardEventPropertiesModel
@ -330,11 +355,11 @@ namespace Artemis.Profiles.Layers.Models
{
if (FadeInTime <= 0)
return;
if (_fadeTweener != null && _fadeTweener.Running)
_fadeTweener = new Tweener<float>(_fadeTweener.Value, 1, FadeInTime, Ease.Quint.Out, TweenModel.LerpFuncFloat);
if (FadeTweener != null && FadeTweener.Running)
FadeTweener = new Tweener<float>(FadeTweener.Value, 1, FadeInTime, Ease.Quint.Out, TweenModel.LerpFuncFloat);
else
_fadeTweener = new Tweener<float>(0, 1, FadeInTime, Ease.Quint.Out, TweenModel.LerpFuncFloat);
_fadeTweener.Start();
FadeTweener = new Tweener<float>(0, 1, FadeInTime, Ease.Quint.Out, TweenModel.LerpFuncFloat);
FadeTweener.Start();
}
private void OnLayerConditionsUnmet(object sender, EventArgs eventArgs)
@ -342,11 +367,11 @@ namespace Artemis.Profiles.Layers.Models
if (FadeOutTime <= 0)
return;
if (_fadeTweener != null && _fadeTweener.Running)
_fadeTweener = new Tweener<float>(_fadeTweener.Value, 0, FadeOutTime, Ease.Quint.In, TweenModel.LerpFuncFloat);
if (FadeTweener != null && FadeTweener.Running)
FadeTweener = new Tweener<float>(FadeTweener.Value, 0, FadeOutTime, Ease.Quint.In, TweenModel.LerpFuncFloat);
else
_fadeTweener = new Tweener<float>(1, 0, FadeOutTime, Ease.Quint.In, TweenModel.LerpFuncFloat);
_fadeTweener.Start();
FadeTweener = new Tweener<float>(1, 0, FadeOutTime, Ease.Quint.In, TweenModel.LerpFuncFloat);
FadeTweener.Start();
}
#region Properties
@ -390,7 +415,9 @@ namespace Artemis.Profiles.Layers.Models
[JsonIgnore] private Brush _brush;
[JsonIgnore] private bool _conditionsMetLastFrame;
[JsonIgnore] private Tweener<float> _fadeTweener;
[JsonIgnore]
public Tweener<float> FadeTweener { get; set; }
[JsonIgnore]
public double X { get; set; }
@ -440,7 +467,7 @@ namespace Artemis.Profiles.Layers.Models
[JsonIgnore]
public DateTime LastRender { get; set; }
#endregion
#endregion