@@ -15,8 +15,6 @@ public class EditorVesselDataManager : MonoBehaviour
15
15
16
16
public static EditorVesselDataManager Instance { get ; private set ; }
17
17
public VesselElectricalData ElectricalData { get { return electricalData ; } }
18
- public VesselThermalData HeatData { get { return heatData ; } }
19
-
20
18
public bool Ready { get { return dataReady ; } }
21
19
22
20
#endregion
@@ -26,43 +24,35 @@ public class EditorVesselDataManager : MonoBehaviour
26
24
bool dataReady = false ;
27
25
28
26
VesselElectricalData electricalData ;
29
- VesselThermalData heatData ;
30
27
#endregion
31
28
32
29
protected void Awake ( )
33
30
{
34
31
enabled = Settings . Enabled ;
35
32
Instance = this ;
36
- }
37
- protected void Start ( )
38
- {
39
33
SetupEditorCallbacks ( ) ;
40
34
}
41
-
42
35
#region Editor
43
36
protected void SetupEditorCallbacks ( )
44
37
{
45
- /// Add events for editor modifications
46
- if ( HighLogic . LoadedSceneIsEditor )
47
- {
48
- GameEvents . onEditorShipModified . Add ( new EventData < ShipConstruct > . OnEvent ( onEditorVesselModified ) ) ;
49
- GameEvents . onEditorRestart . Add ( new EventVoid . OnEvent ( onEditorVesselReset ) ) ;
50
- GameEvents . onEditorStarted . Add ( new EventVoid . OnEvent ( onEditorVesselStart ) ) ;
51
- GameEvents . onEditorPartDeleted . Add ( new EventData < Part > . OnEvent ( onEditorPartDeleted ) ) ;
52
- GameEvents . onEditorPodDeleted . Add ( new EventVoid . OnEvent ( onEditorVesselReset ) ) ;
53
- GameEvents . onEditorLoad . Add ( new EventData < ShipConstruct , KSP . UI . Screens . CraftBrowserDialog . LoadType > . OnEvent ( onEditorVesselLoad ) ) ;
54
- GameEvents . onPartRemove . Add ( new EventData < GameEvents . HostTargetAction < Part , Part > > . OnEvent ( onEditorVesselPartRemoved ) ) ;
55
- }
56
- else
57
- {
58
- GameEvents . onEditorShipModified . Remove ( new EventData < ShipConstruct > . OnEvent ( onEditorVesselModified ) ) ;
59
- GameEvents . onEditorRestart . Remove ( new EventVoid . OnEvent ( onEditorVesselReset ) ) ;
60
- GameEvents . onEditorStarted . Remove ( new EventVoid . OnEvent ( onEditorVesselStart ) ) ;
61
- GameEvents . onEditorPodDeleted . Remove ( new EventVoid . OnEvent ( onEditorVesselReset ) ) ;
62
- GameEvents . onEditorPartDeleted . Remove ( new EventData < Part > . OnEvent ( onEditorPartDeleted ) ) ;
63
- GameEvents . onEditorLoad . Remove ( new EventData < ShipConstruct , KSP . UI . Screens . CraftBrowserDialog . LoadType > . OnEvent ( onEditorVesselLoad ) ) ;
64
- GameEvents . onPartRemove . Remove ( new EventData < GameEvents . HostTargetAction < Part , Part > > . OnEvent ( onEditorVesselPartRemoved ) ) ;
65
- }
38
+ GameEvents . onEditorShipModified . Add ( new EventData < ShipConstruct > . OnEvent ( onEditorVesselModified ) ) ;
39
+ GameEvents . onEditorRestart . Add ( new EventVoid . OnEvent ( onEditorVesselReset ) ) ;
40
+ GameEvents . onEditorStarted . Add ( new EventVoid . OnEvent ( onEditorVesselStart ) ) ;
41
+ GameEvents . onEditorPartDeleted . Add ( new EventData < Part > . OnEvent ( onEditorPartDeleted ) ) ;
42
+ GameEvents . onEditorPodDeleted . Add ( new EventVoid . OnEvent ( onEditorVesselReset ) ) ;
43
+ GameEvents . onEditorLoad . Add ( new EventData < ShipConstruct , KSP . UI . Screens . CraftBrowserDialog . LoadType > . OnEvent ( onEditorVesselLoad ) ) ;
44
+ GameEvents . onPartRemove . Add ( new EventData < GameEvents . HostTargetAction < Part , Part > > . OnEvent ( onEditorVesselPartRemoved ) ) ;
45
+ }
46
+
47
+ void OnDestroy ( )
48
+ {
49
+ GameEvents . onEditorShipModified . Remove ( new EventData < ShipConstruct > . OnEvent ( onEditorVesselModified ) ) ;
50
+ GameEvents . onEditorRestart . Remove ( new EventVoid . OnEvent ( onEditorVesselReset ) ) ;
51
+ GameEvents . onEditorStarted . Remove ( new EventVoid . OnEvent ( onEditorVesselStart ) ) ;
52
+ GameEvents . onEditorPodDeleted . Remove ( new EventVoid . OnEvent ( onEditorVesselReset ) ) ;
53
+ GameEvents . onEditorPartDeleted . Remove ( new EventData < Part > . OnEvent ( onEditorPartDeleted ) ) ;
54
+ GameEvents . onEditorLoad . Remove ( new EventData < ShipConstruct , KSP . UI . Screens . CraftBrowserDialog . LoadType > . OnEvent ( onEditorVesselLoad ) ) ;
55
+ GameEvents . onPartRemove . Remove ( new EventData < GameEvents . HostTargetAction < Part , Part > > . OnEvent ( onEditorVesselPartRemoved ) ) ;
66
56
}
67
57
68
58
protected void InitializeEditorConstruct ( ShipConstruct ship , bool forceReset )
@@ -75,39 +65,27 @@ protected void InitializeEditorConstruct(ShipConstruct ship, bool forceReset)
75
65
else
76
66
electricalData . RefreshData ( false , ship . Parts ) ;
77
67
78
- if ( heatData == null || forceReset )
79
- heatData = new VesselThermalData ( ship . Parts ) ;
80
- else
81
- heatData . RefreshData ( false , ship . Parts ) ;
82
-
83
-
84
68
Utils . Log ( String . Format ( "Dumping electrical database: \n {0}" , electricalData . ToString ( ) ) , Utils . LogType . VesselData ) ;
85
- Utils . Log ( String . Format ( "Dumping thermal database: \n {0}" , heatData . ToString ( ) ) , Utils . LogType . VesselData ) ;
86
-
87
69
dataReady = true ;
88
70
}
89
71
else
90
72
{
91
73
Utils . Log ( String . Format ( "Ship is null" ) , Utils . LogType . VesselData ) ;
92
74
electricalData = new VesselElectricalData ( new List < Part > ( ) ) ;
93
- heatData = new VesselThermalData ( new List < Part > ( ) ) ;
94
75
}
95
76
}
96
77
97
78
protected void RemovePart ( Part p )
98
79
{
99
-
100
80
electricalData . RemoveHandlersForPart ( p ) ;
101
- heatData . RemoveHandlersForPart ( p ) ;
102
-
103
81
}
104
82
#endregion
105
83
106
84
107
85
#region Game Events
108
86
public void onEditorPartDeleted ( Part part )
109
87
{
110
- Utils . Log ( "[VAB VesselDataManager][Editor]: Part Delete " , Utils . LogType . VesselData ) ;
88
+ Utils . Log ( "[VAB VesselDataManager][Editor]: Part DELETED " , Utils . LogType . VesselData ) ;
111
89
if ( ! HighLogic . LoadedSceneIsEditor ) { return ; }
112
90
113
91
InitializeEditorConstruct ( EditorLogic . fetch . ship , false ) ;
@@ -120,22 +98,28 @@ public void onEditorVesselReset()
120
98
}
121
99
public void onEditorVesselStart ( )
122
100
{
123
- Utils . Log ( "[VAB VesselDataManager]: Vessel START" , Utils . LogType . VesselData ) ;
101
+ Utils . Log ( "[VAB VesselDataManager][Editor]: Vessel START" , Utils . LogType . VesselData ) ;
102
+ if ( ! HighLogic . LoadedSceneIsEditor ) { return ; }
103
+ InitializeEditorConstruct ( EditorLogic . fetch . ship , true ) ;
104
+ }
105
+ public void onEditorVesselRestore ( )
106
+ {
107
+ Utils . Log ( "[VAB VesselDataManager]: Vessel RESTORE" , Utils . LogType . VesselData ) ;
124
108
if ( ! HighLogic . LoadedSceneIsEditor ) { return ; }
125
109
InitializeEditorConstruct ( EditorLogic . fetch . ship , true ) ;
126
110
}
127
111
public void onEditorVesselLoad ( ShipConstruct ship , KSP . UI . Screens . CraftBrowserDialog . LoadType type )
128
112
{
129
- Utils . Log ( "[RadioactivitySimulator ][Editor]: Vessel LOAD" , Utils . LogType . VesselData ) ;
113
+ Utils . Log ( "[VAB VesselDataManager ][Editor]: Vessel LOAD" , Utils . LogType . VesselData ) ;
130
114
if ( ! HighLogic . LoadedSceneIsEditor ) { return ; }
131
115
InitializeEditorConstruct ( ship , true ) ;
132
116
}
133
117
public void onEditorVesselPartRemoved ( GameEvents . HostTargetAction < Part , Part > p )
134
118
{
135
- Utils . Log ( "[VAB VesselDataManager][Editor]: Vessel PART REMOVE " , Utils . LogType . VesselData ) ;
119
+ Utils . Log ( "[VAB VesselDataManager][Editor]: Vessel PART REMOVED " , Utils . LogType . VesselData ) ;
136
120
if ( ! HighLogic . LoadedSceneIsEditor ) { return ; }
137
121
138
- if ( electricalData == null || heatData == null )
122
+ if ( electricalData == null )
139
123
InitializeEditorConstruct ( EditorLogic . fetch . ship , false ) ;
140
124
else
141
125
RemovePart ( p . target ) ;
0 commit comments