-
Notifications
You must be signed in to change notification settings - Fork 22
/
Globals.cs
119 lines (105 loc) · 4.45 KB
/
Globals.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
// TCAGlobals.cs
//
// Author:
// Allis Tauri <allista@gmail.com>
//
// Copyright (c) 2016 Allis Tauri
using System;
using System.IO;
using System.Reflection;
using System.Linq;
using System.Collections.Generic;
using AT_Utils;
namespace ThrottleControlledAvionics
{
class Globals : PluginGlobals<Globals>
{
public const string TCA_PART = "ThrottleControlledAvionics";
public const string INSTRUCTIONS = "INSTRUCTIONS.md";
public const string RADIATION_ICON = "ThrottleControlledAvionics/Icons/waypoint";
public const string CIRCLE_ICON = "ThrottleControlledAvionics/Icons/path-node";
public UIBundle AssetBundle = UIBundle.Create("ThrottleControlledAvionics/tca_ui.bundle");
[Persistent] public bool IntegrateIntoCareer = true;
[Persistent] public bool RoleSymmetryInFlight = true;
[Persistent] public bool UseStockAppLauncher = false;
[Persistent] public bool AutosaveBeforeLanding = true;
[Persistent] public float InputDeadZone = 0.01f; //1% of steering or translation control
[Persistent] public int MaxManualGroups = 10; //maximum number of manual control groups
[Persistent] public float KeyRepeatTime = 0.1f;
[Persistent] public float ClickDuration = 0.05f;
[Persistent] public float WaypointFadoutDist = 10000f;
[Persistent] public float CameraFadeinPower = 0.3f;
[Persistent] public float UnpackDistance = 5000f;
[Persistent] public float ActionListHeight = 110f;
[Persistent] public float MaxAAFilter = 1f;
[Persistent] public float ExhaustSafeDist = 1.1f;
[Persistent] public string PersistentRotationName = "PersistentRotation";
[Persistent] public float PersistentRotationThreshold = 5e-7f;
[Persistent] public float NoPersistentRotationThreshold = 5e-7f;
public MDSection Manual;
public static readonly SortedDictionary<string, Type> AllConfigs;
static Globals()
{
AllConfigs = new SortedDictionary<string, Type>();
foreach(var cmp in Assembly.GetExecutingAssembly().GetTypes()
.Where(t => t.IsSubclassOf(typeof(TCAComponent))))
{
foreach(var cfg in cmp.GetNestedTypes()
.Where(t => !t.IsAbstract && t.IsSubclassOf(typeof(TCAComponent.ComponentConfig))))
AllConfigs.Add(cmp.Name, cfg);
}
}
static FieldInfo get_INST(Type t) =>
t.GetField("INST", BindingFlags.Static|BindingFlags.FlattenHierarchy|BindingFlags.Public);
public override void Load(ConfigNode node)
{
base.Load(node);
foreach(var config in AllConfigs)
{
var config_node = node.GetNode(config.Key);
if(config_node != null)
{
var INSTf = get_INST(config.Value);
if(INSTf != null)
{
if(INSTf.GetValue(null) is TCAComponent.ComponentConfig INST)
INST.Load(config_node);
}
else
Utils.Log("WARNING: {} has no public static INST field", config.Value.FullName);
}
#if DEBUG
else
Utils.Log("WARNING: no configuration for {}", config.Key);
#endif
}
}
public override void Save(ConfigNode node)
{
base.Save(node);
foreach(var config in AllConfigs)
{
var INSTf = get_INST(config.Value);
if(INSTf != null)
{
var INST = INSTf.GetValue(null) as TCAComponent.ComponentConfig;
if(INST != null)
INST.Save(node.AddNode(config.Key));
}
}
}
public override void Init()
{
try
{
using(var file = new StreamReader(PluginFolder(INSTRUCTIONS)))
{
Manual = MD2Unity.Parse(file);
if(Manual.NoTitle) Manual.Title = "TCA Reference Manual";
}
}
catch(Exception ex) { Utils.Log("Error loading {} file:\n{}", PluginFolder(INSTRUCTIONS), ex); }
InputDeadZone *= InputDeadZone; //it is compared with the sqrMagnitude
}
}
}