-
Notifications
You must be signed in to change notification settings - Fork 2
/
GentlemanDriverPlugin.cs
84 lines (70 loc) · 3.78 KB
/
GentlemanDriverPlugin.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using GameReaderCommon;
using SimHub.Plugins;
using sjdawson.GentlemanDriverPlugin.Sections;
using System;
using System.Collections.Generic;
namespace sjdawson.GentlemanDriverPlugin
{
[PluginDescription("Additional properties, actions and events for use in various racing games.")]
[PluginAuthor("sjdawson")]
[PluginName("Gentleman Driver Plugin")]
public class GentlemanDriverPlugin: IPlugin, IDataPlugin, IWPFSettings
{
public GentlemanDriverPluginSettings Settings;
public PluginManager PluginManager { get; set; }
public List<IPluginSection> pluginSections = new List<IPluginSection>
{
new Laps(),
new Pits(),
new LaunchMode(),
new Session(),
new TyreCompound(),
new TyreTemps(),
new GameRunningDelayed(),
new WledControl(),
};
/// <summary>
/// Initialise the plugin preparing all settings, properties, events and triggers.
/// </summary>
/// <param name="pluginManager"></param>
public void Init(PluginManager pluginManager)
{
Settings = this.ReadCommonSettings("GentlemanDriverPluginSettings", () => new GentlemanDriverPluginSettings());
foreach (IPluginSection pluginSection in pluginSections)
pluginSection.Init(this);
}
/// <param name="pluginManager"></param>
/// <param name="data"></param>
public void DataUpdate(PluginManager pluginManager, ref GameData data)
{
foreach (IPluginSection pluginSection in pluginSections)
pluginSection.DataUpdate(ref data);
if (data.GameRunning)
if (data.OldData != null && data.NewData != null)
foreach (IPluginSection pluginSection in pluginSections)
pluginSection.GameRunningDataUpdate(ref data);
}
public void End(PluginManager pluginManager)
{
this.SaveCommonSettings("GentlemanDriverPluginSettings", Settings);
foreach (IPluginSection pluginSection in pluginSections)
pluginSection.End();
}
public System.Windows.Controls.Control GetWPFSettingsControl(PluginManager pluginManager) => new GentlemanDriverPluginSettingsControl(this);
/// <summary>
/// Calculate input as a percentage of the range min->max.
/// </summary>
/// <param name="input">The value to convert to a percentage</param>
/// <param name="min">The minumum value where input would be equivalent 0%</param>
/// <param name="max">The maximum value where input would be equivalent 100%</param>
/// <returns>Float between 0-1 to represent 0-100%</returns>
public float InputAsPercentageOfRange(float input, float min, float max) => input > min && input < max ? (input - min) / (max - min) : input > max ? 1 : 0;
public void AddProp(string PropertyName, dynamic defaultValue) => PluginManager.AddProperty(PropertyName, GetType(), defaultValue);
public void SetProp(string PropertyName, dynamic value) => PluginManager.SetPropertyValue(PropertyName, GetType(), value);
public dynamic GetProp(string PropertyName) => PluginManager.GetPropertyValue("DataCorePlugin.GameRawData."+PropertyName);
public dynamic GetNormalisedProp(string PropertyName) => PluginManager.GetPropertyValue("DataCorePlugin.GameData." + PropertyName);
public void AddEvent(string EventName) => PluginManager.AddEvent(EventName, GetType());
public void TriggerEvent(string EventName) => PluginManager.TriggerEvent(EventName, GetType());
public void AddAction(string ActionName, Action<PluginManager, string> ActionBody) => PluginManager.AddAction(ActionName, GetType(), ActionBody);
}
}