OSDN Git Service

Pre-PR5 Configurable Designators, Autostart, fix for Entity processing
[automap/automap.git] / Automap / AutomapMod.cs
index 3f34eb9..4fec56d 100644 (file)
@@ -7,6 +7,8 @@ namespace Automap
 {
     public class AutomapMod : ModSystem
     {
+               public const string _configFilename = @"automap.json";
+
         private ICoreAPI API { get; set; }
         private ICoreClientAPI ClientAPI { get; set; }
         private ILogger Logger { get; set; }
@@ -28,13 +30,15 @@ namespace Automap
                                this.ClientAPI = api as ICoreClientAPI;
                                this.Logger = Mod.Logger;
 
-
                                ClientAPI.Logger.VerboseDebug("Automap Present!");
-                               _localAutomap = new AutomapSystem(this.ClientAPI, this.Logger);
-                               _automapDialog = new AutomapGUIDialog(ClientAPI, _localAutomap);
+                               PrepareClientsideConfig( );
+                               _localAutomap = new AutomapSystem(this.ClientAPI, this.Logger,  this.CachedConfiguration);
+                               _automapDialog = new AutomapGUIDialog(ClientAPI, _localAutomap, this.CachedConfiguration);
 
                                ClientAPI.Input.RegisterHotKey(AutomapGUIDialog._automapControlPanelKey, "Automap control panel", GlKeys.M, HotkeyType.GUIOrOtherControls, shiftPressed: true);
                                ClientAPI.Input.SetHotKeyHandler(AutomapGUIDialog._automapControlPanelKey, ToggleAM_Dialog);
+
+                               ClientAPI.Event.LeaveWorld += PersistParameterChange;
                        }
 
             base.StartClientSide(api);
@@ -52,6 +56,41 @@ namespace Automap
 
                        return true;
                }
+
+               internal PersistedConfiguration CachedConfiguration {
+                       get
+                       {
+                       return ( PersistedConfiguration )ClientAPI.ObjectCache[_configFilename];
+                       }
+                       set
+                       {
+                       ClientAPI.ObjectCache.Add(_configFilename, value);
+                       }
+               }
+
+               private void PrepareClientsideConfig( )
+               {
+               PersistedConfiguration config = ClientAPI.LoadModConfig<PersistedConfiguration>(_configFilename);
+
+               if (config == null) {
+               //Regen default
+               Mod.Logger.Warning("Regenerating default config as it was missing / unparsable...");
+               ClientAPI.StoreModConfig<PersistedConfiguration>(new PersistedConfiguration(defaults: true ), _configFilename);
+               config = ClientAPI.LoadModConfig<PersistedConfiguration>(_configFilename);
+               }
+
+               this.CachedConfiguration = config;
+               }
+
+               internal void PersistParameterChange( )
+               {
+               //Store altered parameters
+
+               ClientAPI.StoreModConfig<PersistedConfiguration>(this.CachedConfiguration, _configFilename);
+               }
+
+
+
        }
 }