-using Vintagestory.API.Client;
-using Vintagestory.API.Common;
+using System.Collections.ObjectModel;
+using System.Linq;
+using Vintagestory.API.Client;
+using Vintagestory.API.Common;
namespace Automap
{
- public class AutomapMod : ModSystem
- {
- private ICoreAPI API { get; set; }
- private ICoreClientAPI ClientAPI { get; set; }
- private ILogger Logger { get; set; }
- private AutomapSystem _localAutomap;
- private AutomapGUIDialog _automapDialog;
+ 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; }
+ private AutomapSystem _localAutomap;
+ private AutomapGUIDialog _automapDialog;
- public override bool ShouldLoad(EnumAppSide forSide)
- {
- return forSide.IsClient();
- }
+
+ public override bool ShouldLoad(EnumAppSide forSide)
+ {
+ return forSide.IsClient();
+ }
public override void StartClientSide(ICoreClientAPI api)
{
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);
- }
+ base.StartClientSide(api);
+ }
public override double ExecuteOrder()
{
- return 0.2;
+ return 1.2;
}
private bool ToggleAM_Dialog(KeyCombination comb)
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);
+ }
+
+ #region External Interfaces
+ //Perhaps Other mods can make use of POI / EOI?
+
+ public ReadOnlyCollection<PointOfInterest> PointsOfInterest {
+ get
+ {
+ return _localAutomap.POIs.ToList().AsReadOnly();
+ }
+ }
+
+ public ReadOnlyCollection<EntityOfInterest> EntitiesOfInterest {
+ get
+ {
+ return _localAutomap.EOIs.ToList().AsReadOnly();
+ }
+ }
+
+ public CommandType Status
+ {
+ get { return _localAutomap.CurrentState; }
+ }
+
+ #endregion
+
+
}
}