forked from KSPModStewards/SystemHeat
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSystemHeatEngineerReport.cs
More file actions
75 lines (61 loc) · 1.98 KB
/
Copy pathSystemHeatEngineerReport.cs
File metadata and controls
75 lines (61 loc) · 1.98 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
using KSP.UI.Screens;
using System.Collections;
using UnityEngine;
namespace SystemHeat
{
[KSPAddon(KSPAddon.Startup.EditorAny, false)]
public class SystemHeatEngineerReport : MonoBehaviour
{
private LoopTemperatureTest tempTest;
private LoopFluxTest fluxTest;
void Awake()
{
GameEvents.onGUIEngineersReportReady.Add(ReportReady);
GameEvents.onGUIEngineersReportDestroy.Add(ReportDestroyed);
}
public void OnDestroy()
{
GameEvents.onGUIEngineersReportReady.Remove(ReportReady);
GameEvents.onGUIEngineersReportDestroy.Remove(ReportDestroyed);
RemoveTest();
}
// onGUIEngineersReportReady only fires once per editor session, so on a hot
// reload we need to re-add the tests manually here.
private void OnHotReload(MonoBehaviour old)
{
if (EngineersReport.Instance != null)
AddTest();
}
private void AddTest()
{
//Wait for DeltaV simulation to be instantiated and to finish.
//Register our test in the Report
tempTest = new LoopTemperatureTest();
fluxTest = new LoopFluxTest();
EngineersReport.Instance.AddTest(tempTest);
EngineersReport.Instance.AddTest(fluxTest);
EngineersReport.Instance.ShouldTest(tempTest);
EngineersReport.Instance.ShouldTest(fluxTest);
}
private void RemoveTest()
{
// EngineersReport may already be torn down on scene exit; tests are tied
// to its lifetime and don't need to be removed in that case.
if (EngineersReport.Instance == null) return;
//Only if it was actually added, deregister it.
if (tempTest != null) EngineersReport.Instance.RemoveTest(tempTest);
if (fluxTest != null) EngineersReport.Instance.RemoveTest(fluxTest);
}
private void ReportDestroyed()
{
RemoveTest();
}
private void ReportReady()
{
Utils.Log("[SystemHeatEngineerReport] Report Ready Fired", LogType.Simulator);
RemoveTest();
AddTest();
}
}
}