forked from andreasdahl1987/DahlDesignProperties
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDataPlugin.cs
132 lines (111 loc) · 4.78 KB
/
DataPlugin.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
using DahlDesign.Plugin.Categories;
using GameReaderCommon;
using SimHub.Plugins;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Windows.Media;
namespace DahlDesign.Plugin
{
[PluginDescription("Dahl Design Properties")]
[PluginAuthor("Andreas Dahl")]
[PluginName("DahlDesign")]
public class DahlDesign : IPlugin, IDataPlugin, IWPFSettingsV2
{
public DataPluginSettings Settings;
/// <summary>Instance of the current plugin manager</summary>
public PluginManager PluginManager { get; set; }
public iRacing.Data iRacing;
public Categories.Dashboard Dashboard;
public Categories.DDC DDC;
public Rotary Rotary;
public SmoothGear SmoothGear;
public Acceleration Acceleration;
public int counter = 0;
public ImageSource PictureIcon => this.ToIcon(Properties.Resources.Dahl_icon);
public string LeftMenuTitle => "Dahl Design";
public DahlGameData dahlGameData = new DahlGameData();
public List<SectionBase> Sections = new List<SectionBase>();
private bool sectionsAreDirty = true;
/// <summary>
/// Called once after plugins startup
/// Plugins are rebuilt at game change
/// </summary>
/// <param name="pluginManager"></param>
public void Init(PluginManager pluginManager)
{
SimHub.Logging.Current.Info("Starting plugin");
// Load settings
Settings = this.ReadCommonSettings<DataPluginSettings>("GeneralSettings", () => new DataPluginSettings());
Dashboard = new Categories.Dashboard(this);
DDC = new Categories.DDC(this);
Rotary = new Rotary(this);
iRacing = new iRacing.Data(this);
SmoothGear = new SmoothGear(this);
InitSections();
}
private void InitSections()
{
if (sectionsAreDirty == false) { return; }
Sections.Clear();
iRacing.Initialize();
Sections.Add(Dashboard);
Sections.Add(DDC);
Sections.Add(Rotary);
Sections.Add(iRacing);
Sections.Add(new Tires(this));
Sections.Add(new iRacingSpotter(this));
Sections.Add(SmoothGear);
Sections.Add(new Acceleration(this));
sectionsAreDirty = false;
}
public void DataUpdate(PluginManager pluginManager, ref GameData data)
{
//FRAME COUNTER FOR CPU SAVING
//Counters used: 1,2,3,4,5,6,7,8,9,10,11,14,15,17,20,22,24,25,27,30,33,35,36,38,39,40,43,45,47,50,51,52,53,54,55,59
counter++;
//Resetting counter
if (counter > 59)
{
counter = 0;
}
if (data.GameRunning && data.NewData != null)
{
dahlGameData.GameData = data;
dahlGameData.GameName = data.GameName;
dahlGameData.SetGameData();
foreach (SectionBase section in Sections)
{
section.DataUpdate();
}
sectionsAreDirty= true;
} else
{
InitSections();
}
}
public void End(PluginManager pluginManager)
{
// Save settings
this.SaveCommonSettings("GeneralSettings", Settings);
}
/// <summary>
/// Returns the settings control, return null if no settings control is required
/// </summary>
/// <param name="pluginManager"></param>
/// <returns></returns>
public System.Windows.Controls.Control GetWPFSettingsControl(PluginManager pluginManager)
{
return new SettingsControl(this) { DataContext = Settings }; ;
}
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(PropertyName);
public bool HasProp(string PropertyName) => PluginManager.GetAllPropertiesNames().Contains(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);
public void TriggerAction(string ActionName) => PluginManager.TriggerAction(ActionName);
}
}