44using Sandbox . ModAPI ;
55using System ;
66using System . IO ;
7+ using System . Windows . Controls ;
78using Torch ;
89using Torch . API ;
910using Torch . API . Managers ;
11+ using Torch . API . Plugins ;
1012using Torch . API . Session ;
1113using Torch . Session ;
1214
1315namespace StaticMarker
1416{
15- public class MarkerPlugin : TorchPluginBase
17+ public class MarkerPlugin : TorchPluginBase , IWpfPlugin
1618 {
17- const string ConfigMarkers = "StaticMarkerEntries.cfg" ;
19+ const string ConfigFile = "StaticMarkerEntries.cfg" ;
20+ const string ConfigMarkersFile = "StaticMarkerEntries.cfg" ;
1821
22+ private MarkerControl _control ;
1923 private TorchSessionManager _sessionManager ;
2024 private IMultiplayerManagerBase _multibase ;
25+ private Persistent < MarkerConfig > _config ;
2126 private MarkerEntriesConfig _entriesConfig ;
2227
2328 public static readonly Logger Log = LogManager . GetCurrentClassLogger ( ) ;
29+ public MarkerConfig Config => _config ? . Data ;
2430
2531 /// <inheritdoc />
26- public override void Init ( ITorchBase torch )
32+ public UserControl GetControl ( ) => _control ?? ( _control = new MarkerControl ( this ) ) ;
33+
34+ public void Save ( ) => _config . Save ( ) ;
35+
36+ /// <inheritdoc />
37+ public override void Init ( ITorchBase torch )
2738 {
2839 base . Init ( torch ) ;
2940
@@ -33,6 +44,19 @@ public override void Init(ITorchBase torch)
3344 else
3445 Log . Warn ( "No session manager loaded!" ) ;
3546
47+ var configFile = Path . Combine ( StoragePath , ConfigFile ) ;
48+ try
49+ {
50+ _config = Persistent < MarkerConfig > . Load ( configFile ) ;
51+ }
52+ catch ( Exception e )
53+ {
54+ Log . Warn ( e ) ;
55+ }
56+
57+ if ( _config ? . Data == null )
58+ _config = new Persistent < MarkerConfig > ( configFile , new MarkerConfig ( ) ) ;
59+
3660 LoadConfig ( ) ;
3761 }
3862
@@ -57,7 +81,7 @@ private void SessionChanged(ITorchSession session, TorchSessionState state)
5781 internal bool LoadConfig ( )
5882 {
5983 var success = false ;
60- var configFile = Path . Combine ( StoragePath , ConfigMarkers ) ;
84+ var configFile = Path . Combine ( StoragePath , ConfigMarkersFile ) ;
6185 try
6286 {
6387 _entriesConfig = Persistent < MarkerEntriesConfig > . Load ( configFile ) . Data ;
@@ -67,6 +91,10 @@ internal bool LoadConfig()
6791 {
6892 Log . Warn ( e ) ;
6993 }
94+
95+ if ( _config ? . Data == null )
96+ _entriesConfig = new Persistent < MarkerEntriesConfig > ( configFile , new MarkerEntriesConfig ( ) ) . Data ;
97+
7098 return success ;
7199 }
72100
@@ -80,7 +108,8 @@ private void _multibase_PlayerJoined(IPlayer obj)
80108 return ;
81109 }
82110
83- SendGPSEntries ( idendity ) ;
111+ if ( Config . SendMarkerOnJoin )
112+ SendGPSEntries ( idendity ) ;
84113 }
85114
86115 internal void SendGPSEntries ( long identityId )
0 commit comments