-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathModuleHealthEnvironmentSensor.cs
69 lines (57 loc) · 2.3 KB
/
ModuleHealthEnvironmentSensor.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
using KSP.Localization;
namespace KerbalHealth
{
class ModuleHealthEnvironmentSensor : PartModule
{
[KSPField]
public string type = "";
[KSPField(guiActive = true, guiActiveEditor = false)]
public float displayData;
public override void OnStart(StartState state)
{
if (Core.IsInEditor)
return;
Core.Log($"ModuleHealthEnvironmentSensor.OnStart({state}) for {part.name}");
switch (type.ToLowerInvariant())
{
case "radiation":
Fields["displayData"].guiName = "#KH_Radiation";
Fields["displayData"].guiUnits = "#KH_Module_perDay";
Fields["displayData"].guiFormat = "N0";
break;
case "magnetosphere":
Fields["displayData"].guiName = "#KH_Module_MagnetosphereShielding";
Fields["displayData"].guiUnits = "";
Fields["displayData"].guiFormat = "P0";
break;
default:
Fields["displayData"].guiActive = false;
break;
}
}
public void FixedUpdate()
{
if (Core.IsInEditor)
return;
if (!isActiveAndEnabled || !vessel.IsControllable || !KerbalHealthGeneralSettings.Instance.modEnabled || !KerbalHealthRadiationSettings.Instance.RadiationEnabled || KerbalHealthRadiationSettings.Instance.UseKerbalismRadiation)
{
Fields["displayData"].guiActive = false;
return;
}
else Fields["displayData"].guiActive = true;
switch (type.ToLowerInvariant())
{
case "radiation":
displayData = (float)KerbalHealthStatus.GetCosmicRadiation(vessel);
break;
case "magnetosphere":
displayData = 1 - (float)KerbalHealthStatus.GetMagnetosphereCoefficient(vessel);
break;
default:
Fields["displayData"].guiActive = false;
break;
}
}
public override string GetInfo() => Localizer.Format($"#KH_ModuleSensorInfo_{type.ToLowerInvariant()}");
}
}