@@ -15,8 +15,6 @@ public class EditorVesselDataManager : MonoBehaviour
1515
1616 public static EditorVesselDataManager Instance { get ; private set ; }
1717 public VesselElectricalData ElectricalData { get { return electricalData ; } }
18- public VesselThermalData HeatData { get { return heatData ; } }
19-
2018 public bool Ready { get { return dataReady ; } }
2119
2220 #endregion
@@ -26,43 +24,35 @@ public class EditorVesselDataManager : MonoBehaviour
2624 bool dataReady = false ;
2725
2826 VesselElectricalData electricalData ;
29- VesselThermalData heatData ;
3027 #endregion
3128
3229 protected void Awake ( )
3330 {
3431 enabled = Settings . Enabled ;
3532 Instance = this ;
36- }
37- protected void Start ( )
38- {
3933 SetupEditorCallbacks ( ) ;
4034 }
41-
4235 #region Editor
4336 protected void SetupEditorCallbacks ( )
4437 {
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 ) ) ;
6656 }
6757
6858 protected void InitializeEditorConstruct ( ShipConstruct ship , bool forceReset )
@@ -75,39 +65,27 @@ protected void InitializeEditorConstruct(ShipConstruct ship, bool forceReset)
7565 else
7666 electricalData . RefreshData ( false , ship . Parts ) ;
7767
78- if ( heatData == null || forceReset )
79- heatData = new VesselThermalData ( ship . Parts ) ;
80- else
81- heatData . RefreshData ( false , ship . Parts ) ;
82-
83-
8468 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-
8769 dataReady = true ;
8870 }
8971 else
9072 {
9173 Utils . Log ( String . Format ( "Ship is null" ) , Utils . LogType . VesselData ) ;
9274 electricalData = new VesselElectricalData ( new List < Part > ( ) ) ;
93- heatData = new VesselThermalData ( new List < Part > ( ) ) ;
9475 }
9576 }
9677
9778 protected void RemovePart ( Part p )
9879 {
99-
10080 electricalData . RemoveHandlersForPart ( p ) ;
101- heatData . RemoveHandlersForPart ( p ) ;
102-
10381 }
10482 #endregion
10583
10684
10785 #region Game Events
10886 public void onEditorPartDeleted ( Part part )
10987 {
110- Utils . Log ( "[VAB VesselDataManager][Editor]: Part Delete " , Utils . LogType . VesselData ) ;
88+ Utils . Log ( "[VAB VesselDataManager][Editor]: Part DELETED " , Utils . LogType . VesselData ) ;
11189 if ( ! HighLogic . LoadedSceneIsEditor ) { return ; }
11290
11391 InitializeEditorConstruct ( EditorLogic . fetch . ship , false ) ;
@@ -120,22 +98,28 @@ public void onEditorVesselReset()
12098 }
12199 public void onEditorVesselStart ( )
122100 {
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 ) ;
124108 if ( ! HighLogic . LoadedSceneIsEditor ) { return ; }
125109 InitializeEditorConstruct ( EditorLogic . fetch . ship , true ) ;
126110 }
127111 public void onEditorVesselLoad ( ShipConstruct ship , KSP . UI . Screens . CraftBrowserDialog . LoadType type )
128112 {
129- Utils . Log ( "[RadioactivitySimulator ][Editor]: Vessel LOAD" , Utils . LogType . VesselData ) ;
113+ Utils . Log ( "[VAB VesselDataManager ][Editor]: Vessel LOAD" , Utils . LogType . VesselData ) ;
130114 if ( ! HighLogic . LoadedSceneIsEditor ) { return ; }
131115 InitializeEditorConstruct ( ship , true ) ;
132116 }
133117 public void onEditorVesselPartRemoved ( GameEvents . HostTargetAction < Part , Part > p )
134118 {
135- Utils . Log ( "[VAB VesselDataManager][Editor]: Vessel PART REMOVE " , Utils . LogType . VesselData ) ;
119+ Utils . Log ( "[VAB VesselDataManager][Editor]: Vessel PART REMOVED " , Utils . LogType . VesselData ) ;
136120 if ( ! HighLogic . LoadedSceneIsEditor ) { return ; }
137121
138- if ( electricalData == null || heatData == null )
122+ if ( electricalData == null )
139123 InitializeEditorConstruct ( EditorLogic . fetch . ship , false ) ;
140124 else
141125 RemovePart ( p . target ) ;
0 commit comments