@@ -33,121 +33,7 @@ private static void GameLogicData_Parse(GameLogicData __instance, ref JObject ro
3333 {
3434 if ( ! fullyInitialized )
3535 {
36- Load ( rootObject ) ;
37- foreach ( JToken jtoken in rootObject . SelectTokens ( "$.*.*" ) . ToArray ( ) )
38- {
39- JObject ? token = jtoken . TryCast < JObject > ( ) ;
40- if ( token != null )
41- {
42- string dataType = Util . GetJTokenName ( token , 2 ) ;
43- if ( Loader . typeMappings . TryGetValue ( dataType , out Loader . TypeMapping ? typeMapping ) )
44- {
45- if ( token [ "idx" ] != null && ( int ) token [ "idx" ] == - 1 && typeMapping . shouldCreateCache )
46- {
47- Type targetType = typeMapping . type ;
48- string id = Util . GetJTokenName ( token ) ;
49- token [ "idx" ] = Registry . autoidx ;
50- MethodInfo ? methodInfo = typeof ( EnumCache < > ) . MakeGenericType ( targetType ) . GetMethod ( "AddMapping" ) ;
51- if ( methodInfo != null )
52- {
53- methodInfo . Invoke ( null , new object [ ] { id , Registry . autoidx } ) ;
54- methodInfo . Invoke ( null , new object [ ] { id , Registry . autoidx } ) ;
55-
56- if ( Loader . typeHandlers . TryGetValue ( targetType , out var handler ) )
57- {
58- handler ( token , true ) ;
59- }
60- Plugin . logger . LogInfo ( "Created mapping for " + targetType . ToString ( ) + " with id " + id + " and index " + Registry . autoidx ) ;
61- Registry . autoidx ++ ;
62- }
63- }
64- }
65- }
66- }
67- foreach ( JToken jtoken in rootObject . SelectTokens ( "$.*.*" ) . ToArray ( ) )
68- {
69- JObject ? token = jtoken . TryCast < JObject > ( ) ;
70- if ( token != null )
71- {
72- string dataType = Util . GetJTokenName ( token , 2 ) ;
73- if ( Loader . typeMappings . TryGetValue ( dataType , out Loader . TypeMapping ? typeMapping ) )
74- {
75- if ( Loader . typeHandlers . TryGetValue ( typeMapping . type , out var handler ) )
76- {
77- handler ( token , false ) ;
78- }
79- }
80- }
81- }
82- foreach ( System . Collections . Generic . KeyValuePair < int , string > item in Registry . prefabNames )
83- {
84- UnitData . Type unitPrefabType = UnitData . Type . Scout ;
85- string prefabId = item . Value ;
86- if ( Enum . TryParse ( prefabId , out UnitData . Type parsedType ) )
87- {
88- unitPrefabType = parsedType ;
89- PrefabManager . units . TryAdd ( item . Key , PrefabManager . units [ ( int ) unitPrefabType ] ) ;
90- }
91- else
92- {
93- KeyValuePair < Visual . PrefabInfo , Unit > prefabInfo = Registry . unitPrefabs . FirstOrDefault ( kv => kv . Key . name == prefabId ) ;
94- if ( ! EqualityComparer < Visual . PrefabInfo > . Default . Equals ( prefabInfo . Key , default ) )
95- {
96- PrefabManager . units . TryAdd ( item . Key , prefabInfo . Value ) ;
97- }
98- else
99- {
100- PrefabManager . units . TryAdd ( item . Key , PrefabManager . units [ ( int ) unitPrefabType ] ) ;
101- }
102- }
103- }
104- foreach ( Visual . SkinInfo skin in Registry . skinInfo )
105- {
106- if ( skin . skinData != null )
107- __instance . skinData [ ( SkinType ) skin . idx ] = skin . skinData ;
108- }
109- foreach ( KeyValuePair < string , string > entry in embarkNames )
110- {
111- try
112- {
113- UnitData . Type unit = EnumCache < UnitData . Type > . GetType ( entry . Key ) ;
114- UnitData . Type newUnit = EnumCache < UnitData . Type > . GetType ( entry . Value ) ;
115- embarkOverrides [ unit ] = newUnit ;
116- Plugin . logger . LogInfo ( $ "Embark unit type for { entry . Key } is now { entry . Value } ") ;
117- }
118- catch
119- {
120- Plugin . logger . LogError ( $ "Embark unit type for { entry . Key } is not valid: { entry . Value } ") ;
121- }
122- }
123- foreach ( KeyValuePair < string , string > entry in attractsResourceNames )
124- {
125- try
126- {
127- ImprovementData . Type improvement = EnumCache < ImprovementData . Type > . GetType ( entry . Key ) ;
128- ResourceData . Type resource = EnumCache < ResourceData . Type > . GetType ( entry . Value ) ;
129- attractsResourceOverrides [ improvement ] = resource ;
130- Plugin . logger . LogInfo ( $ "Improvement { entry . Key } now attracts { entry . Value } ") ;
131- }
132- catch
133- {
134- Plugin . logger . LogError ( $ "Improvement { entry . Key } resource type is not valid: { entry . Value } ") ;
135- }
136- }
137- foreach ( KeyValuePair < string , string > entry in attractsTerrainNames )
138- {
139- try
140- {
141- ImprovementData . Type improvement = EnumCache < ImprovementData . Type > . GetType ( entry . Key ) ;
142- Polytopia . Data . TerrainData . Type terrain = EnumCache < Polytopia . Data . TerrainData . Type > . GetType ( entry . Value ) ;
143- attractsTerrainOverrides [ improvement ] = terrain ;
144- Plugin . logger . LogInfo ( $ "Improvement { entry . Key } now attracts on { entry . Value } ") ;
145- }
146- catch
147- {
148- Plugin . logger . LogError ( $ "Improvement { entry . Key } terrain type is not valid: { entry . Value } ") ;
149- }
150- }
36+ Load ( __instance , rootObject ) ;
15137 fullyInitialized = true ;
15238 }
15339 }
@@ -408,7 +294,7 @@ internal static void Init()
408294 stopwatch . Stop ( ) ;
409295 }
410296
411- internal static void Load ( JObject gameLogicdata )
297+ internal static void Load ( GameLogicData gameLogicData , JObject json )
412298 {
413299 stopwatch . Start ( ) ;
414300 Loc . BuildAndLoadLocalization (
@@ -432,7 +318,7 @@ internal static void Load(JObject gameLogicdata)
432318 {
433319 Loader . LoadGameLogicDataPatch (
434320 mod ,
435- gameLogicdata ,
321+ json ,
436322 JObject . Parse ( new StreamReader ( new MemoryStream ( file . bytes ) ) . ReadToEnd ( ) )
437323 ) ;
438324 continue ;
@@ -465,6 +351,7 @@ internal static void Load(JObject gameLogicdata)
465351 {
466352 TechItem . techTierFirebaseId . Add ( $ "tech_research_{ i } ") ;
467353 }
354+ Loader . ProcessGameLogicData ( gameLogicData , json ) ;
468355 stopwatch . Stop ( ) ;
469356 Plugin . logger . LogInfo ( $ "Loaded all mods in { stopwatch . ElapsedMilliseconds } ms") ;
470357 }
0 commit comments