Skip to content

Commit

Permalink
Reset bindings for campaign configuration when returning to main menu
Browse files Browse the repository at this point in the history
  • Loading branch information
cheese3660 committed Nov 7, 2023
1 parent 0ee26fa commit 6338e33
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion SpaceWarp.Core/SpaceWarpPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
using HarmonyLib;
using I2.Loc;
using JetBrains.Annotations;
using KSP.Game;
using KSP.IO;
using KSP.Messages;
using KSP.ScriptInterop.impl.moonsharp;
using MoonSharp.Interpreter;
using MoonSharp.Interpreter.Interop;
Expand Down Expand Up @@ -40,7 +42,8 @@ public sealed class SpaceWarpPlugin : BaseSpaceWarpPlugin
internal ScriptEnvironment GlobalLuaState;

internal new static ManualLogSource Logger;



public SpaceWarpPlugin()
{
// Load the type forwarders
Expand Down Expand Up @@ -111,6 +114,20 @@ public override void OnInitialized()
{
ModuleManager.InitializeAllModules();
SetupLuaState();
Game.Messages.Subscribe(typeof(GameStateEnteredMessage), ResetToDefaults, false, true);
}

private void ResetToDefaults(MessageCenterMessage msg)
{
var stateChange = msg as GameStateEnteredMessage;
if (stateChange!.StateBeingEntered != GameState.MainMenu) return;
foreach (var plugin in PluginList.AllEnabledAndActivePlugins)
{
if (plugin.SaveConfigFile != null && plugin.SaveConfigFile.Sections.Count > 0)
{
plugin.SaveConfigFile.ResetToDefaults();
}
}
}

public override void OnPostInitialized()
Expand Down

0 comments on commit 6338e33

Please sign in to comment.