Skip to content

Commit 30a5d33

Browse files
committed
Fixed reload editor issue
1 parent 259cbdb commit 30a5d33

File tree

8 files changed

+42
-48
lines changed

8 files changed

+42
-48
lines changed
Binary file not shown.

Source/DynamicBatteryStorage/Data/VABVesselDataManager.cs

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -30,36 +30,29 @@ protected void Awake()
3030
{
3131
enabled = Settings.Enabled;
3232
Instance = this;
33-
}
34-
protected void Start()
35-
{
3633
SetupEditorCallbacks();
3734
}
38-
3935
#region Editor
4036
protected void SetupEditorCallbacks()
4137
{
42-
/// Add events for editor modifications
43-
if (HighLogic.LoadedSceneIsEditor)
44-
{
45-
GameEvents.onEditorShipModified.Add(new EventData<ShipConstruct>.OnEvent(onEditorVesselModified));
46-
GameEvents.onEditorRestart.Add(new EventVoid.OnEvent(onEditorVesselReset));
47-
GameEvents.onEditorStarted.Add(new EventVoid.OnEvent(onEditorVesselStart));
48-
GameEvents.onEditorPartDeleted.Add(new EventData<Part>.OnEvent(onEditorPartDeleted));
49-
GameEvents.onEditorPodDeleted.Add(new EventVoid.OnEvent(onEditorVesselReset));
50-
GameEvents.onEditorLoad.Add(new EventData<ShipConstruct, KSP.UI.Screens.CraftBrowserDialog.LoadType>.OnEvent(onEditorVesselLoad));
51-
GameEvents.onPartRemove.Add(new EventData<GameEvents.HostTargetAction<Part, Part>>.OnEvent(onEditorVesselPartRemoved));
52-
}
53-
else
54-
{
55-
GameEvents.onEditorShipModified.Remove(new EventData<ShipConstruct>.OnEvent(onEditorVesselModified));
56-
GameEvents.onEditorRestart.Remove(new EventVoid.OnEvent(onEditorVesselReset));
57-
GameEvents.onEditorStarted.Remove(new EventVoid.OnEvent(onEditorVesselStart));
58-
GameEvents.onEditorPodDeleted.Remove(new EventVoid.OnEvent(onEditorVesselReset));
59-
GameEvents.onEditorPartDeleted.Remove(new EventData<Part>.OnEvent(onEditorPartDeleted));
60-
GameEvents.onEditorLoad.Remove(new EventData<ShipConstruct, KSP.UI.Screens.CraftBrowserDialog.LoadType>.OnEvent(onEditorVesselLoad));
61-
GameEvents.onPartRemove.Remove(new EventData<GameEvents.HostTargetAction<Part, Part>>.OnEvent(onEditorVesselPartRemoved));
62-
}
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));
6356
}
6457

6558
protected void InitializeEditorConstruct(ShipConstruct ship, bool forceReset)
@@ -92,7 +85,7 @@ protected void RemovePart(Part p)
9285
#region Game Events
9386
public void onEditorPartDeleted(Part part)
9487
{
95-
Utils.Log("[VAB VesselDataManager][Editor]: Part Delete", Utils.LogType.VesselData);
88+
Utils.Log("[VAB VesselDataManager][Editor]: Part DELETED", Utils.LogType.VesselData);
9689
if (!HighLogic.LoadedSceneIsEditor) { return; }
9790

9891
InitializeEditorConstruct(EditorLogic.fetch.ship, false);
@@ -105,19 +98,25 @@ public void onEditorVesselReset()
10598
}
10699
public void onEditorVesselStart()
107100
{
108-
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);
109108
if (!HighLogic.LoadedSceneIsEditor) { return; }
110109
InitializeEditorConstruct(EditorLogic.fetch.ship, true);
111110
}
112111
public void onEditorVesselLoad(ShipConstruct ship, KSP.UI.Screens.CraftBrowserDialog.LoadType type)
113112
{
114-
Utils.Log("[RadioactivitySimulator][Editor]: Vessel LOAD", Utils.LogType.VesselData);
113+
Utils.Log("[VAB VesselDataManager][Editor]: Vessel LOAD", Utils.LogType.VesselData);
115114
if (!HighLogic.LoadedSceneIsEditor) { return; }
116115
InitializeEditorConstruct(ship, true);
117116
}
118117
public void onEditorVesselPartRemoved(GameEvents.HostTargetAction<Part, Part> p)
119118
{
120-
Utils.Log("[VAB VesselDataManager][Editor]: Vessel PART REMOVE", Utils.LogType.VesselData);
119+
Utils.Log("[VAB VesselDataManager][Editor]: Vessel PART REMOVED", Utils.LogType.VesselData);
121120
if (!HighLogic.LoadedSceneIsEditor) { return; }
122121

123122
if (electricalData == null)

Source/DynamicBatteryStorage/Handlers/PostKerbin/FissionGeneratorPowerHandler.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,9 @@ public class FissionGeneratorPowerHandler : ModuleDataHandler
55
public FissionGeneratorPowerHandler(HandlerModuleData moduleData) : base(moduleData)
66
{ }
77

8-
PartModule core;
9-
108
public override bool Initialize(PartModule pm)
119
{
1210
base.Initialize(pm);
13-
for (int i = 0; i < pm.part.Modules.Count; i++)
14-
{
15-
if (pm.part.Modules[i].moduleName == "FissionReactor")
16-
{
17-
core = pm.part.Modules[i];
18-
}
19-
}
2011
return true;
2112
}
2213

Source/DynamicBatteryStorage/Handlers/PostKerbin/ModuleCurvedSolarPanelPowerHandler.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
namespace DynamicBatteryStorage
22
{
3-
43
public class ModuleCurvedSolarPanelPowerHandler : ModuleDataHandler
54
{
65
public ModuleCurvedSolarPanelPowerHandler(HandlerModuleData moduleData) : base(moduleData)
@@ -9,8 +8,9 @@ public ModuleCurvedSolarPanelPowerHandler(HandlerModuleData moduleData) : base(m
98
public override bool Initialize(PartModule pm)
109
{
1110
base.Initialize(pm);
12-
/// If kopernicus is using the multistar settings, we need to show this in the editor but NOT in flight
13-
if (Settings.Kopernicus && Settings.KopernicusMultiStar || Settings.WeatherDrivenSolarPanel)
11+
/// In the case where Kopernicus is installed and using its >= v209 multistar logic, the solar panel management should only work in editor. In flight it is replaced with the Kop model
12+
/// In the case where WDSP is installed, the solar panel management should only work in editor. In flight it is replaced with the WDSP model
13+
if ((Settings.Kopernicus && Settings.KopernicusMultiStar) || Settings.WeatherDrivenSolarPanel)
1414
{
1515
return HighLogic.LoadedSceneIsEditor;
1616
}

Source/DynamicBatteryStorage/Handlers/Stock/ModuleDeployableSolarPanelPowerHandler.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ public override bool Initialize(PartModule pm)
2727
}
2828
}
2929
}
30-
/// If kopernicus is using the multistar settings, we need to show this in the editor but NOT in flight
31-
if (Settings.Kopernicus && Settings.KopernicusMultiStar || Settings.WeatherDrivenSolarPanel)
30+
/// In the case where Kopernicus is installed and using its >= v209 multistar logic, the solar panel management should only work in editor. In flight it is replaced with the Kop model
31+
/// In the case where WDSP is installed, the solar panel management should only work in editor. In flight it is replaced with the WDSP model
32+
if ((Settings.Kopernicus && Settings.KopernicusMultiStar) || Settings.WeatherDrivenSolarPanel)
3233
{
3334
return HighLogic.LoadedSceneIsEditor;
3435
}

Source/DynamicBatteryStorage/Handlers/WDSPPowerHandlers.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ protected override double GetValueEditor()
2929
}
3030
protected override double GetValueFlight()
3131
{
32-
double results = 0d;
33-
if (double.TryParse(pm.Fields.GetValue("currentOutput").ToString(), out results))
32+
if (double.TryParse(pm.Fields.GetValue("currentOutput").ToString(), out double results))
3433
{
3534
return results;
3635
}

Source/DynamicBatteryStorage/Settings.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@ private static void DetectMods()
161161
// Search for wdsp
162162
if (a.name.StartsWith("WeatherDrivenSolarPanel", StringComparison.Ordinal))
163163
{
164-
Settings.WeatherDrivenSolarPanel = true;
164+
WeatherDrivenSolarPanel = true;
165+
Utils.Log($"[Settings] Weather Dependent Solar Panel logic is Multi Star Logic is {WeatherDrivenSolarPanel}", Utils.LogType.Any);
165166
}
166167

167168
}

changelog.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
v2.3.4
22
------
33
- Stability updates: breaking the mod will now break it less
4-
- Performance updates: cut frame time cost of DBS on a 200 part vessel by 85%
5-
- Code cleanup to remove old thermal handling code now that nobody has missed it
4+
- Performance updates: cut frame time cost of DBS on a 200 part vessel by something like 75%
5+
- Fixed issues with edtor reverts and reloads failing to reset the UI until you made a change to the vessel
6+
- Code cleanup
7+
- Reworking of layout of handler code for ease of use
8+
- Remove old thermal handling code now that nobody has missed it
69

710
v2.3.3
811
------

0 commit comments

Comments
 (0)