-
Notifications
You must be signed in to change notification settings - Fork 96
/
SCANconfigLoader.cs
149 lines (115 loc) · 5.07 KB
/
SCANconfigLoader.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#region license
/*
* [Scientific Committee on Advanced Navigation]
* S.C.A.N. Satellite
*
* SCANconfigLoader - Load the config file settings at startup
*
* Copyright (c)2014 David Grandy <david.grandy@gmail.com>;
* Copyright (c)2014 technogeeky <technogeeky@gmail.com>;
* Copyright (c)2014 (Your Name Here) <your email here>; see LICENSE.txt for licensing details.
*/
#endregion
using System.Linq;
using SCANsat.SCAN_Data;
using palette = SCANsat.SCAN_UI.UI_Framework.SCANcolorUtil;
namespace SCANsat
{
public static class SCANconfigLoader
{
private static bool globalResource = false;
private static bool initialized = false;
private const string configFile = "SCANsat/Resources/SCANcolors";
private const string configNodeName = "SCAN_Color_Config";
private const string paletteFile = "SCANsat/Resources/SCANpalettes";
private const string paletteNodeName = "SCAN_Palette_Config";
private static SCAN_Color_Config SCANnode;
private static SCAN_Palette_Config SCANpalettes;
public static SCAN_Color_Config SCANNode
{
get { return SCANnode; }
}
public static SCAN_Palette_Config SCANPalettes
{
get { return SCANpalettes; }
}
public static bool GlobalResource
{
get { return globalResource; }
}
public static bool Initialized
{
get { return initialized; }
}
internal static void configLoader()
{
SCANpalettes = new SCAN_Palette_Config(paletteFile, paletteNodeName);
SCANnode = new SCAN_Color_Config(configFile, configNodeName);
SCANcontroller.checkLoadedTerrainNodes();
loadResources();
}
private static void loadResources()
{
foreach (var rs in ResourceCache.Instance.GlobalResources)
{
if ((HarvestTypes)rs.ResourceType != HarvestTypes.Planetary)
continue;
SCANresourceGlobal currentGlobal = SCANcontroller.getResourceNode(rs.ResourceName);
PartResourceDefinition pr = PartResourceLibrary.Instance.GetDefinition(rs.ResourceName);
if (currentGlobal == null)
{
SCANcontroller.addToResourceData(rs.ResourceName, new SCANresourceGlobal(rs.ResourceName, pr == null ? rs.ResourceName : pr.displayName, 20, rs.Distribution.MinAbundance, rs.Distribution.MaxAbundance, palette.magenta, palette.cb_orange));//, t));
currentGlobal = SCANcontroller.getResourceNode(rs.ResourceName, true);
}
currentGlobal.DisplayName = pr == null ? rs.ResourceName : pr.displayName;
if (rs.Distribution.MinAbundance > currentGlobal.DefaultMinValue)
currentGlobal.DefaultMinValue = rs.Distribution.MinAbundance;
if (rs.Distribution.MaxAbundance > currentGlobal.DefaultMaxValue)
currentGlobal.DefaultMaxValue = rs.Distribution.MaxAbundance;
foreach (CelestialBody body in FlightGlobals.Bodies)
{
SCANresourceBody newBody = currentGlobal.getBodyConfig(body.bodyName, false);
if (newBody == null)
currentGlobal.addToBodyConfigs(body.bodyName, new SCANresourceBody(rs.ResourceName, body, currentGlobal.DefaultMinValue, currentGlobal.DefaultMaxValue), false);
}
SCANcontroller.addToLoadedResourceNames(rs.ResourceName);
}
foreach (var rsBody in ResourceCache.Instance.PlanetaryResources)
{
if ((HarvestTypes)rsBody.ResourceType != HarvestTypes.Planetary)
continue;
SCANresourceGlobal currentGlobal = SCANcontroller.getResourceNode(rsBody.ResourceName);
if (currentGlobal == null)
{
PartResourceDefinition pr = PartResourceLibrary.Instance.GetDefinition(rsBody.ResourceName);
SCANcontroller.addToResourceData(rsBody.ResourceName, new SCANresourceGlobal(rsBody.ResourceName, pr == null ? rsBody.ResourceName : pr.displayName, 20, 0, 0.001f, palette.magenta, palette.cb_orange));//, t));
currentGlobal = SCANcontroller.getResourceNode(rsBody.ResourceName, true);
foreach (CelestialBody body in FlightGlobals.Bodies)
{
SCANresourceBody newBody = currentGlobal.getBodyConfig(body.bodyName, false);
if (newBody == null)
currentGlobal.addToBodyConfigs(body.bodyName, new SCANresourceBody(rsBody.ResourceName, body, 0, 0.001f), false);
}
SCANcontroller.addToLoadedResourceNames(rsBody.ResourceName);
}
SCANresourceBody currentBody = currentGlobal.getBodyConfig(rsBody.PlanetName, false);
if (currentBody == null)
{
CelestialBody body = FlightGlobals.Bodies.FirstOrDefault(a => a.bodyName == rsBody.PlanetName);
if (body == null)
continue;
currentGlobal.addToBodyConfigs(rsBody.PlanetName, new SCANresourceBody(rsBody.ResourceName, body, rsBody.Distribution.MinAbundance, rsBody.Distribution.MaxAbundance), false);
currentBody = currentGlobal.getBodyConfig(rsBody.PlanetName, false);
}
if (rsBody.Distribution.MinAbundance > currentBody.DefaultMinValue)
currentBody.DefaultMinValue = rsBody.Distribution.MinAbundance;
if (rsBody.Distribution.MaxAbundance > currentBody.DefaultMaxValue)
currentBody.DefaultMaxValue = rsBody.Distribution.MaxAbundance;
}
if (SCANcontroller.MasterResourceCount == 0)
globalResource = false;
else
globalResource = true;
}
}
}