-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathApp.Settings.cs
More file actions
181 lines (135 loc) · 5.18 KB
/
Copy pathApp.Settings.cs
File metadata and controls
181 lines (135 loc) · 5.18 KB
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
using System.IO;
using System.Windows;
using static MarvinsAIRA.Settings;
namespace MarvinsAIRA
{
public partial class App : Application
{
private Settings _settings = new();
private bool _settings_pauseSerialization = false;
private float _settings_serializationTimer = 0;
public Settings Settings
{
get => _settings;
}
private void InitializeSettings()
{
WriteLine( "InitializeSettings called.", true );
var filePath = Path.Combine( DocumentsFolder, "Settings.xml" );
if ( File.Exists( filePath ) )
{
_settings_pauseSerialization = true;
var settings = (Settings?) Serializer.Load( filePath, typeof( Settings ) );
if ( settings != null )
{
// START TEMPORARY CODE - GET RID OF THIS AFTER ABOUT A MONTH
if ( ( _settings.USEffectStyle == 2 ) && _settings.USEffectStyleInvert )
{
_settings.USEffectStyleConstantForce = false;
_settings.USEffectStyleConstantForceInverted = true;
_settings.USEffectStyle = 3;
}
_settings.USEffectStyleInvert = false;
if ( ( _settings.OSEffectStyle == 2 ) && _settings.OSEffectStyleInvert )
{
_settings.OSEffectStyleConstantForce = false;
_settings.OSEffectStyleConstantForceInverted = true;
_settings.OSEffectStyle = 3;
}
_settings.USEffectStyleInvert = false;
// END TEMPORARY CODE - GET RID OF THIS AFTER ABOUT A MONTH
_settings = settings;
}
_settings_pauseSerialization = false;
}
var mainWindow = MarvinsAIRA.MainWindow.Instance;
if ( mainWindow != null )
{
mainWindow.DataContext = _settings;
mainWindow.FixRangeSliders();
}
}
public void UpdateSettings( float deltaTime )
{
if ( _settings_serializationTimer > 0 )
{
_settings_serializationTimer -= deltaTime;
if ( _settings_serializationTimer <= 0 )
{
_settings_serializationTimer = 0;
// update per wheel/car/track/track configuration force feedback settings
var forceFeedbackSettingsFound = false;
foreach ( var forceFeedbackSettings in Settings.ForceFeedbackSettingsList )
{
if ( ( forceFeedbackSettings.WheelName == _ffb_wheelSaveName ) && ( forceFeedbackSettings.CarName == _car_carSaveName ) && ( forceFeedbackSettings.TrackName == _track_trackSaveName ) && ( forceFeedbackSettings.TrackConfigName == _track_trackConfigSaveName ) )
{
forceFeedbackSettings.OverallScale = Settings.OverallScale;
forceFeedbackSettings.DetailScale = Settings.DetailScale;
forceFeedbackSettingsFound = true;
break;
}
}
if ( !forceFeedbackSettingsFound )
{
var forceFeedbackSettings = new ForceFeedbackSettings
{
WheelName = _ffb_wheelSaveName,
CarName = _car_carSaveName,
TrackName = _track_trackSaveName,
TrackConfigName = _track_trackConfigSaveName,
OverallScale = Settings.OverallScale,
DetailScale = Settings.DetailScale,
};
Settings.ForceFeedbackSettingsList.Add( forceFeedbackSettings );
}
// update per-car steering effects settings
var steeringEffectsSettingsFound = false;
foreach ( var steeringEffectsSettings in Settings.SteeringEffectsSettingsList )
{
if ( steeringEffectsSettings.CarName == _car_currentCarScreenName )
{
steeringEffectsSettings.SteeringEffectsEnabled = Settings.SteeringEffectsEnabled;
steeringEffectsSettings.USStartYawRateFactorLeft = Settings.USStartYawRateFactorLeft;
steeringEffectsSettings.USEndYawRateFactorLeft = Settings.USEndYawRateFactorLeft;
steeringEffectsSettings.USStartYawRateFactorRight = Settings.USStartYawRateFactorRight;
steeringEffectsSettings.USEndYawRateFactorRight = Settings.USEndYawRateFactorRight;
steeringEffectsSettings.OSStartYVelocity = Settings.OSStartYVelocity;
steeringEffectsSettings.OSEndYVelocity = Settings.OSEndYVelocity;
steeringEffectsSettings.OSSoftness = Settings.OSSoftness;
steeringEffectsSettingsFound = true;
break;
}
}
if ( !steeringEffectsSettingsFound )
{
var steeringEffectsSettings = new SteeringEffectsSettings
{
CarName = _car_currentCarScreenName,
SteeringEffectsEnabled = Settings.SteeringEffectsEnabled,
USStartYawRateFactorLeft = Settings.USStartYawRateFactorLeft,
USEndYawRateFactorLeft = Settings.USEndYawRateFactorLeft,
USStartYawRateFactorRight = Settings.USStartYawRateFactorRight,
USEndYawRateFactorRight = Settings.USEndYawRateFactorRight,
OSStartYVelocity = Settings.OSStartYVelocity,
OSEndYVelocity = Settings.OSEndYVelocity,
OSSoftness = Settings.OSSoftness,
};
Settings.SteeringEffectsSettingsList.Add( steeringEffectsSettings );
}
// save the configuration file
var filePath = Path.Combine( DocumentsFolder, "Settings.xml" );
Serializer.Save( filePath, _settings );
WriteLine( $"Settings.xml file updated [{_ffb_wheelSaveName}, {_car_carSaveName}, {_track_trackSaveName}, {_track_trackConfigSaveName}, {_wetdry_conditionSaveName}]" );
}
}
}
public void QueueForSerialization()
{
if ( !_settings_pauseSerialization )
{
_settings_serializationTimer = 1;
}
}
}
}