Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Source/EngineerReport/SystemHeatEngineerReport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,18 @@ 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.
Expand All @@ -38,6 +49,9 @@ private void AddTest()

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);
Expand Down
2 changes: 1 addition & 1 deletion Source/Modules/ModuleSystemHeatColorAnimator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ protected void Start()
{

targetRenderers = new List<Renderer>();
if (includedTransformList == "")
if (string.IsNullOrEmpty(includedTransformList))
{
foreach (Transform x in part.GetComponentsInChildren<Transform>())
{
Expand Down
4 changes: 4 additions & 0 deletions Source/SystemHeat.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
<PackageReference Include="KSPBuildTools" Version="1.1.1" />
</ItemGroup>

<ItemGroup Condition="'$(Configuration)' == 'Debug' Or '$(Configuration)' == 'Profiling'">
<AssemblyMetadata Include="HotReload" Value="true" />
</ItemGroup>

<ItemGroup>
<Compile Remove="Modules\ModuleSystemHeatMultiJettison.cs" />
<None Include="Modules\ModuleSystemHeatMultiJettison.cs" />
Expand Down
7 changes: 6 additions & 1 deletion Source/SystemHeatEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ protected void OnDestroy()
RemoveEditorCallbacks();
Instance = null;
}

private void OnHotReload(MonoBehaviour old)
{
if (HighLogic.LoadedSceneIsEditor && EditorLogic.fetch != null)
InitializeEditorConstruct(EditorLogic.fetch.ship, false);
}
protected void FixedUpdate()
{
if (simulator != null)
Expand All @@ -51,7 +57,6 @@ protected void FixedUpdate()
simulator.SimulationSpeed = SystemHeatUI.Instance.toolbarPanel.SimSituationVelocity;
}
simulator.SimulateEditor();

}
}
#region Editor
Expand Down
1 change: 0 additions & 1 deletion Source/SystemHeatGameSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ namespace SystemHeat

public class SystemHeatGameSettings_ReactorDamage : GameParameters.CustomParameterNode
{

[GameParameters.CustomParameterUI("AllowReactorDamage",
title = "#LOC_SystemHeat_Settings_AllowReactorDamage_Title",
toolTip = "#LOC_SystemHeat_Settings_AllowReactorDamage_Tooltip",
Expand Down
3 changes: 3 additions & 0 deletions Source/SystemHeatSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ public static Color GetLoopColor(int id)
{
return SystemHeatSettings.ColorData[Mathf.Clamp(id, 0, 9)];
}

/// <summary>
/// Load data from configuration
/// </summary>
Expand Down Expand Up @@ -216,5 +217,7 @@ public static CoolantType GetCoolantType(string name)
return new CoolantType();
}
}

static void OnHotLoad() => Load();
}
}
2 changes: 2 additions & 0 deletions Source/UI/Overlay/SystemHeatOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ protected void OnDestroy()
GameEvents.onEditorStarted.Remove(onEditorStart);
GameEvents.OnMapEntered.Remove(onEnterMapView);
GameEvents.OnMapExited.Remove(onExitMapView);
ClearPanels();
DestroyOverlay();
Instance = null;

}
Expand Down
2 changes: 2 additions & 0 deletions Source/UI/ReactorUI/ReactorToolbar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,9 @@ public void OnDestroy()
if (stockToolbarButton != null)
{
ApplicationLauncher.Instance.RemoveModApplication(stockToolbarButton);
stockToolbarButton = null;
}
DestroyToolbarPanel();
}

protected void OnToolbarButtonToggle()
Expand Down
28 changes: 27 additions & 1 deletion Source/UI/SystemHeatAssets.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using UnityEngine;


Expand All @@ -20,6 +22,7 @@ public class SystemHeatAssets : MonoBehaviour

internal static string ASSET_PATH = "GameData/SystemHeat/UI/systemheatui.dat";
internal static string SPRITE_ATLAS_NAME = "system-heat-sprites-1";

private void Awake()
{
Utils.Log("[SystemHeatAssets]: Loading Assets", LogType.UI);
Expand All @@ -42,5 +45,28 @@ private void Awake()
}
Utils.Log($"[SystemHeatAssets]: Loaded {Sprites.Count} sprites", LogType.UI);
}

// We can't load the asset bundle again - it is already loaded, and it would
// instantiate the old types. Instead, we use reflection to read them out of
// the old assembly. Hot-reloading will take care of replacing any widgets
// within.
private static void OnHotLoad(Assembly prev)
{
const BindingFlags Flags = BindingFlags.Public | BindingFlags.Static;

var old = prev.GetType(typeof(SystemHeatAssets).FullName);
OverlayPanelPrefab = GetPrefabProperty(old, nameof(OverlayPanelPrefab));
ToolbarPanelPrefab = GetPrefabProperty(old, nameof(ToolbarPanelPrefab));
ToolbarPanelLoopPrefab = GetPrefabProperty(old, nameof(ToolbarPanelLoopPrefab));
ReactorWidgetPrefab = GetPrefabProperty(old, nameof(ReactorWidgetPrefab));
ReactorToolbarPanelPrefab = GetPrefabProperty(old, nameof(ReactorToolbarPanelPrefab));
Sprites = (Dictionary<string, Sprite>)old.GetProperty(nameof(Sprites), Flags).GetValue(null);
}

private static GameObject GetPrefabProperty(Type old, string name)
{
const BindingFlags Flags = BindingFlags.Public | BindingFlags.Static;
return (GameObject)old.GetProperty(name, Flags).GetValue(null);
}
}
}
11 changes: 9 additions & 2 deletions Source/UI/SystemHeatUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,14 @@ public void Start()
{
if (ApplicationLauncher.Ready)
OnGUIAppLauncherReady();
}


// Explicitly destroy the toolbar panel because hot-reloading will destroy
// the old component but leave the panel game object orphaned.
private void OnHotReload(MonoBehaviour old)
{
DestroyToolbarPanel();
toolbarPanel = null;
}

protected void CreateToolbarPanel()
Expand Down Expand Up @@ -264,11 +270,12 @@ public void OnDestroy()
{
Utils.Log("[UI]: OnDestroy Fired", LogType.UI);
// Remove the stock toolbar button
GameEvents.onGUIApplicationLauncherReady.Remove(OnGUIAppLauncherReady);
if (stockToolbarButton != null)
{
ApplicationLauncher.Instance.RemoveModApplication(stockToolbarButton);
stockToolbarButton = null;
}
DestroyToolbarPanel();
GameEvents.onGUIApplicationLauncherReady.Remove(OnGUIAppLauncherReady);
GameEvents.onGUIApplicationLauncherDestroyed.Remove(OnGUIAppLauncherDestroyed);
GameEvents.onGUIApplicationLauncherUnreadifying.Remove(new EventData<GameScenes>.OnEvent(OnGUIAppLauncherUnreadifying));
Expand Down
Loading