1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2026-01-01 02:03:32 +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 LateralG { get; set; }
public float LongitudinalG { 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] [MoonSharpUserData]

View File

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

View File

@ -22,10 +22,15 @@
<!-- Header --> <!-- Header -->
<Label Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" FontSize="20" HorizontalAlignment="Left"> <Label Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" FontSize="20" HorizontalAlignment="Left">
<Label.Content> <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.Content>
</Label> </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 --> <!-- Enable -->
<StackPanel Grid.Row="1" Grid.Column="1" HorizontalAlignment="Right" Orientation="Horizontal"> <StackPanel Grid.Row="1" Grid.Column="1" HorizontalAlignment="Right" Orientation="Horizontal">
<Label Content="Enable module" HorizontalAlignment="Right" Margin="0,0,0,3" /> <Label Content="Enable module" HorizontalAlignment="Right" Margin="0,0,0,3" />

View File

@ -41,7 +41,7 @@ namespace Artemis.Modules.Games.RocketLeague
} }
Updater.GetPointers(); 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)."; 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 --> <!-- Header -->
<Label Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" FontSize="20" HorizontalAlignment="Left"> <Label Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" FontSize="20" HorizontalAlignment="Left">
<Label.Content> <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.Content>
</Label> </Label>

View File

@ -1,174 +1,174 @@
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.Linq; using System.Linq;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Windows.Documents; using System.Windows.Documents;
using Artemis.Modules.Abstract; using Artemis.Modules.Abstract;
using Artemis.Utilities; using Artemis.Utilities;
using DynamicExpresso; using DynamicExpresso;
using MahApps.Metro.Controls; using MahApps.Metro.Controls;
namespace Artemis.Profiles.Layers.Models namespace Artemis.Profiles.Layers.Models
{ {
public class LayerConditionModel public class LayerConditionModel
{ {
private readonly Interpreter _interpreter; private readonly Interpreter _interpreter;
private object _lastValue; private object _lastValue;
private Regex _rgx; private Regex _rgx;
public LayerConditionModel() public LayerConditionModel()
{ {
_interpreter = new Interpreter(); _interpreter = new Interpreter();
_rgx = new Regex("\\((.*?)\\)"); _rgx = new Regex("\\((.*?)\\)");
} }
public string Field { get; set; } public string Field { get; set; }
public string Value { get; set; } public string Value { get; set; }
public string Operator { get; set; } public string Operator { get; set; }
public string Type { get; set; } public string Type { get; set; }
public HotKey HotKey { get; set; } public HotKey HotKey { get; set; }
public bool ConditionMet(ModuleDataModel subject) public bool ConditionMet(ModuleDataModel subject)
{ {
lock (subject) lock (subject)
{ {
if (string.IsNullOrEmpty(Field) || string.IsNullOrEmpty(Type)) if (string.IsNullOrEmpty(Field) || string.IsNullOrEmpty(Type))
return false; return false;
// If the path points to a collection, look inside this collection // If the path points to a collection, look inside this collection
if (Field.Contains("(")) if (Field.Contains("("))
{ {
// Find the collection in the field path // Find the collection in the field path
var collectionField = _rgx.Match(Field).Groups[1].Value; var collectionField = _rgx.Match(Field).Groups[1].Value;
var collectionInspect = (IEnumerable) GeneralHelpers.GetPropertyValue(subject, collectionField); var collectionInspect = (IEnumerable) GeneralHelpers.GetPropertyValue(subject, collectionField);
var operatorParts = Operator.Split('|'); var operatorParts = Operator.Split('|');
var field = Field.Split(')').Last().Substring(1); var field = Field.Split(')').Last().Substring(1);
_lastValue = collectionInspect; _lastValue = collectionInspect;
if (operatorParts[0] == "any") if (operatorParts[0] == "any")
{ {
var anyMatch = false; var anyMatch = false;
foreach (var collectionValue in collectionInspect) foreach (var collectionValue in collectionInspect)
{ {
anyMatch = EvaluateOperator(collectionValue, field, operatorParts[1]); anyMatch = EvaluateOperator(collectionValue, field, operatorParts[1]);
if (anyMatch) if (anyMatch)
break; break;
} }
return anyMatch; return anyMatch;
} }
if (operatorParts[0] == "all") if (operatorParts[0] == "all")
{ {
var allMatch = true; var allMatch = true;
foreach (var collectionValue in collectionInspect) foreach (var collectionValue in collectionInspect)
{ {
allMatch = EvaluateOperator(collectionValue, field, operatorParts[1]); allMatch = EvaluateOperator(collectionValue, field, operatorParts[1]);
if (!allMatch) if (!allMatch)
break; break;
} }
return allMatch; return allMatch;
} }
if (operatorParts[0] == "none") if (operatorParts[0] == "none")
{ {
var noneMatch = true; var noneMatch = true;
foreach (var collectionValue in collectionInspect) foreach (var collectionValue in collectionInspect)
{ {
noneMatch = !EvaluateOperator(collectionValue, field, operatorParts[1]); noneMatch = !EvaluateOperator(collectionValue, field, operatorParts[1]);
if (!noneMatch) if (!noneMatch)
break; break;
} }
return noneMatch; return noneMatch;
} }
} }
var inspect = GeneralHelpers.GetPropertyValue(subject, Field); var inspect = GeneralHelpers.GetPropertyValue(subject, Field);
if (inspect == null) if (inspect == null)
{ {
_lastValue = null; _lastValue = null;
return false; return false;
} }
bool returnValue; bool returnValue;
if (Operator == "changed" || Operator == "decreased" || Operator == "increased") if (Operator == "changed" || Operator == "decreased" || Operator == "increased")
returnValue = EvaluateEventOperator(subject, inspect); returnValue = EvaluateEventOperator(subject, inspect);
else else
returnValue = EvaluateOperator(subject, Field); returnValue = EvaluateOperator(subject, Field);
_lastValue = inspect; _lastValue = inspect;
return returnValue; return returnValue;
} }
} }
private bool EvaluateEventOperator(ModuleDataModel subject, object inspect) private bool EvaluateEventOperator(ModuleDataModel subject, object inspect)
{ {
// DynamicExpresso doesn't want a null so when it was previously null (should only happen first iteration) // 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 // return false since that would be the only possible outcome
if (_lastValue == null) if (_lastValue == null)
return false; return false;
// Assign the right parameter // Assign the right parameter
var rightParam = new Parameter("value", _lastValue); var rightParam = new Parameter("value", _lastValue);
// Come up with the proper operator // Come up with the proper operator
var changeOperator = ""; var changeOperator = "";
if (Operator == "changed") if (Operator == "changed")
changeOperator = "!="; changeOperator = "!=";
else if (Operator == "decreased") else if (Operator == "decreased")
changeOperator = "<"; changeOperator = "<";
else if (Operator == "increased") else if (Operator == "increased")
changeOperator = ">"; changeOperator = ">";
// Evaluate the result and store it // Evaluate the result and store it
var returnValue = _interpreter.Eval<bool>($"subject.{Field} {changeOperator} value", new Parameter("subject", subject.GetType(), subject), rightParam); var returnValue = _interpreter.Eval<bool>($"subject.{Field} {changeOperator} value", new Parameter("subject", subject.GetType(), subject), rightParam);
// Set the last value to the new value // Set the last value to the new value
_lastValue = inspect; _lastValue = inspect;
// Return the evaluated result // Return the evaluated result
return returnValue; return returnValue;
} }
private bool EvaluateOperator(object subject, string field, string operatorOverwrite = null) private bool EvaluateOperator(object subject, string field, string operatorOverwrite = null)
{ {
// Since _lastValue won't be used, rely on Value to not be null // Since _lastValue won't be used, rely on Value to not be null
if (string.IsNullOrEmpty(Value)) if (string.IsNullOrEmpty(Value))
return false; return false;
if (Type == "String") if (Type == "String")
{ {
var stringExpressionText = operatorOverwrite == null var stringExpressionText = operatorOverwrite == null
? $"subject.{field}.ToLower(){Operator}(value)" ? $"subject.{field}.ToLower(){Operator}(value)"
: $"subject.{field}.ToLower(){operatorOverwrite}(value)"; : $"subject.{field}.ToLower(){operatorOverwrite}(value)";
return _interpreter.Eval<bool>(stringExpressionText, new Parameter("subject", subject.GetType(), subject), new Parameter("value", Value.ToLower())); return _interpreter.Eval<bool>(stringExpressionText, new Parameter("subject", subject.GetType(), subject), new Parameter("value", Value.ToLower()));
} }
Parameter rightParam = null; Parameter rightParam = null;
switch (Type) switch (Type)
{ {
case "Enum": case "Enum":
var enumType = GeneralHelpers.GetPropertyValue(subject, field).GetType(); var enumType = GeneralHelpers.GetPropertyValue(subject, field).GetType();
rightParam = new Parameter("value", Enum.Parse(enumType, Value)); rightParam = new Parameter("value", Enum.Parse(enumType, Value));
break; break;
case "Boolean": case "Boolean":
rightParam = new Parameter("value", bool.Parse(Value)); rightParam = new Parameter("value", bool.Parse(Value));
break; break;
case "Int32": case "Int32":
rightParam = new Parameter("value", int.Parse(Value)); rightParam = new Parameter("value", int.Parse(Value));
break; break;
case "Single": case "Single":
// Parse commas as decimals // Parse commas as decimals
rightParam = new Parameter("value", float.Parse(Value.Replace(",", "."), rightParam = new Parameter("value", float.Parse(Value.Replace(",", "."),
CultureInfo.InvariantCulture)); CultureInfo.InvariantCulture));
break; break;
} }
var expressionText = operatorOverwrite == null var expressionText = operatorOverwrite == null
? $"subject.{field} {Operator} value" ? $"subject.{field} {Operator} value"
: $"subject.{field} {operatorOverwrite} value"; : $"subject.{field} {operatorOverwrite} value";
return _interpreter.Eval<bool>(expressionText, new Parameter("subject", subject.GetType(), subject), rightParam); 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) if (!Enabled)
return false; return false;
_fadeTweener?.Update(40); FadeTweener?.Update(40);
var conditionsMet = LayerCondition.ConditionsMet(this, dataModel); var conditionsMet = LayerCondition.ConditionsMet(this, dataModel);
if (conditionsMet && !_conditionsMetLastFrame) if (conditionsMet && !_conditionsMetLastFrame)
OnLayerConditionsMet(); OnLayerConditionsMet();
@ -61,7 +61,7 @@ namespace Artemis.Profiles.Layers.Models
OnLayerConditionsUnmet(); OnLayerConditionsUnmet();
_conditionsMetLastFrame = conditionsMet; _conditionsMetLastFrame = conditionsMet;
return _fadeTweener != null && _fadeTweener.Running || conditionsMet; return FadeTweener != null && FadeTweener.Running || conditionsMet;
} }
/// <summary> /// <summary>
@ -74,7 +74,7 @@ namespace Artemis.Profiles.Layers.Models
{ {
if (LayerType == null) if (LayerType == null)
return; return;
LayerType.Update(this, dataModel, preview); LayerType.Update(this, dataModel, preview);
LayerAnimation?.Update(this, updateAnimations); LayerAnimation?.Update(this, updateAnimations);
@ -114,12 +114,37 @@ namespace Artemis.Profiles.Layers.Models
if (Brush == null || !preview && !RenderAllowed) if (Brush == null || !preview && !RenderAllowed)
return; return;
// If fading in/out, push transparency on the entire context ApplyHierarchyOpacity(c);
if (_fadeTweener != null && _fadeTweener.Running)
c.PushOpacity(_fadeTweener.Value);
LayerType.Draw(this, 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(); c.Pop();
var current = this;
while (current.Parent != null)
{
current = current.Parent;
if (current.FadeTweener != null && current.FadeTweener.Running)
c.Pop();
}
} }
/// <summary> /// <summary>
@ -128,7 +153,7 @@ namespace Artemis.Profiles.Layers.Models
public void SetupProperties() public void SetupProperties()
{ {
LayerType.SetupProperties(this); LayerType.SetupProperties(this);
// If the type is an event, set it up // If the type is an event, set it up
if (IsEvent && EventProperties == null) if (IsEvent && EventProperties == null)
EventProperties = new KeyboardEventPropertiesModel EventProperties = new KeyboardEventPropertiesModel
@ -330,11 +355,11 @@ namespace Artemis.Profiles.Layers.Models
{ {
if (FadeInTime <= 0) if (FadeInTime <= 0)
return; return;
if (_fadeTweener != null && _fadeTweener.Running) if (FadeTweener != null && FadeTweener.Running)
_fadeTweener = new Tweener<float>(_fadeTweener.Value, 1, FadeInTime, Ease.Quint.Out, TweenModel.LerpFuncFloat); FadeTweener = new Tweener<float>(FadeTweener.Value, 1, FadeInTime, Ease.Quint.Out, TweenModel.LerpFuncFloat);
else else
_fadeTweener = new Tweener<float>(0, 1, FadeInTime, Ease.Quint.Out, TweenModel.LerpFuncFloat); FadeTweener = new Tweener<float>(0, 1, FadeInTime, Ease.Quint.Out, TweenModel.LerpFuncFloat);
_fadeTweener.Start(); FadeTweener.Start();
} }
private void OnLayerConditionsUnmet(object sender, EventArgs eventArgs) private void OnLayerConditionsUnmet(object sender, EventArgs eventArgs)
@ -342,11 +367,11 @@ namespace Artemis.Profiles.Layers.Models
if (FadeOutTime <= 0) if (FadeOutTime <= 0)
return; return;
if (_fadeTweener != null && _fadeTweener.Running) if (FadeTweener != null && FadeTweener.Running)
_fadeTweener = new Tweener<float>(_fadeTweener.Value, 0, FadeOutTime, Ease.Quint.In, TweenModel.LerpFuncFloat); FadeTweener = new Tweener<float>(FadeTweener.Value, 0, FadeOutTime, Ease.Quint.In, TweenModel.LerpFuncFloat);
else else
_fadeTweener = new Tweener<float>(1, 0, FadeOutTime, Ease.Quint.In, TweenModel.LerpFuncFloat); FadeTweener = new Tweener<float>(1, 0, FadeOutTime, Ease.Quint.In, TweenModel.LerpFuncFloat);
_fadeTweener.Start(); FadeTweener.Start();
} }
#region Properties #region Properties
@ -390,7 +415,9 @@ namespace Artemis.Profiles.Layers.Models
[JsonIgnore] private Brush _brush; [JsonIgnore] private Brush _brush;
[JsonIgnore] private bool _conditionsMetLastFrame; [JsonIgnore] private bool _conditionsMetLastFrame;
[JsonIgnore] private Tweener<float> _fadeTweener;
[JsonIgnore]
public Tweener<float> FadeTweener { get; set; }
[JsonIgnore] [JsonIgnore]
public double X { get; set; } public double X { get; set; }
@ -440,7 +467,7 @@ namespace Artemis.Profiles.Layers.Models
[JsonIgnore] [JsonIgnore]
public DateTime LastRender { get; set; } public DateTime LastRender { get; set; }
#endregion #endregion
#endregion #endregion