55using System . Reflection ;
66using GoingMedievalModLauncher . Engine ;
77using GoingMedievalModLauncher . MonoScripts ;
8+ using GoingMedievalModLauncher . ui ;
89using I2 . Loc ;
910using Newtonsoft . Json ;
1011using NSEipix . Base ;
1112using NSEipix . ObjectMapper ;
1213using NSEipix . Repository ;
14+ using NSMedieval ;
1315using NSMedieval . Construction ;
1416using NSMedieval . Crops ;
1517using NSMedieval . Model ;
@@ -98,6 +100,9 @@ ContainerState State
98100 /// </summary>
99101 bool CodeOnly { get ; }
100102
103+ /// <summary>
104+ /// Indicates that the launcher should not search in the code directory
105+ /// </summary>
101106 bool NoCode { get ; }
102107
103108 void Init ( ) ;
@@ -165,14 +170,13 @@ public ContainerState State
165170 }
166171 }
167172
168- public bool NoCode { get ; }
169-
170173 /// <summary>
171174 /// The backing variable of the State property.
172175 /// </summary>
173176 private ContainerState _state ;
174177
175178 public bool CodeOnly { get ; }
179+ public bool NoCode { get ; }
176180
177181 private event Action < MonoBehaviour > OnDeinit ;
178182 private event Action OnInit ;
@@ -217,6 +221,7 @@ private PluginContainer(DirectoryInfo path, ManifestClass manifest)
217221
218222 if ( ! CodeOnly )
219223 {
224+ RegisterJsonRepositoryLoader < MapRepository , Map > ( ) ;
220225 RegisterJsonRepositoryLoader < MapSizeRepository , MapSize > ( ) ;
221226
222227 RegisterJsonRepositoryLoaderWithIdField < ResourceRepository , Resource > ( "resourceId" ) ;
@@ -240,7 +245,7 @@ private PluginContainer(DirectoryInfo path, ManifestClass manifest)
240245 assemblies . Add ( assembly ) ;
241246 }
242247
243- // Check if the assembly is valid (we don't want to load any dll within the mods-directory
248+ // Check if the assembly is valid (we don't want to load any dll within the mods-directory)
244249 Type pluginType = typeof ( IPlugin ) ;
245250 List < Type > validPlugins = new List < Type > ( ) ;
246251
@@ -250,7 +255,7 @@ private PluginContainer(DirectoryInfo path, ManifestClass manifest)
250255 {
251256 if ( assembly != null )
252257 {
253- Type [ ] types = new Type [ 0 ] ;
258+ Type [ ] types = Type . EmptyTypes ;
254259 try
255260 {
256261 types = assembly . GetTypes ( ) ;
@@ -287,12 +292,11 @@ private PluginContainer(DirectoryInfo path, ManifestClass manifest)
287292 }
288293 catch ( Exception e )
289294 {
290- Launcher . LOGGER . Info ( "Unable to get Plugin's type. Maybe the code is referencing an older launcher?" ) ;
291- Launcher . LOGGER . Info ( e . ToString ( ) ) ;
292-
295+ Launcher . LOGGER . Error ( e ,
296+ "Unable to get Plugin's type. Maybe the code is referencing an older launcher?" ) ;
293297 }
294298
295- //TODO: more erros ?
299+ //TODO: more errors ?
296300 if ( validPlugins . Count == 0 )
297301 {
298302 Launcher . LOGGER . Info ( "No valid plugin were found for this directory." ) ;
@@ -320,7 +324,7 @@ void I()
320324 }
321325 catch ( Exception e )
322326 {
323- Launcher . LOGGER . Info ( $ "Unable to initalize plugin { Name } : { e } ") ;
327+ Launcher . LOGGER . Error ( e , $ "Unable to initalize plugin { Name } ") ;
324328 }
325329 }
326330
@@ -329,11 +333,11 @@ void D(MonoBehaviour o)
329333 try
330334 {
331335 instance . disable ( o ) ;
332- // TODO: plugin.start (doorstepGameObject);
336+ // TODO: plugin.stop (doorstepGameObject);
333337 }
334338 catch ( Exception e )
335339 {
336- Launcher . LOGGER . Info ( $ "Unable to disbale plugin { Name } : { e } ") ;
340+ Launcher . LOGGER . Error ( e , $ "Unable to disbale plugin { Name } ") ;
337341 }
338342 }
339343
@@ -342,7 +346,7 @@ void D(MonoBehaviour o)
342346 }
343347 catch ( Exception e )
344348 {
345- Launcher . LOGGER . Info ( "An error happened instantiating a plugin!\n " + e ) ;
349+ Launcher . LOGGER . Error ( e , "An error happened instantiating a plugin!\n " ) ;
346350 }
347351 finally
348352 {
@@ -525,8 +529,9 @@ void Del(T repo)
525529 Launcher . LOGGER . Info ( $ "Added item { item . GetID ( ) } to repository { typeof ( T ) . Name } ") ;
526530 repo . Add ( item ) ;
527531 }
528-
529- repo . Reload ( ) ;
532+
533+ //DO NOT! RECURSION ALERT!
534+ //repo.Reload();
530535 }
531536
532537 }
@@ -711,7 +716,19 @@ public void Deinit(MonoBehaviour o)
711716
712717 }
713718
714- private ModLoaderPluginContainer ( ) { }
719+ private ModLoaderPluginContainer ( )
720+ {
721+ MainMenuPatch . OnMenuStartPost += ( ) =>
722+ {
723+ MainMenuPatch . AddMainMenuButton ( "ModsButton" , "Mods" , ( ) =>
724+ {
725+ if ( EngineLauncher . Instance . modManagerWindow == null ) return ;
726+
727+ EngineLauncher . Instance . modManagerWindow . shown = ! EngineLauncher . Instance . modManagerWindow . shown ;
728+
729+ } , 15 ) ;
730+ } ;
731+ }
715732
716733 }
717734
0 commit comments