1515using Unity . VisualScripting ;
1616using UnityEngine ;
1717using UnityEngine . AddressableAssets ;
18+ using UnityEngine . ResourceManagement . AsyncOperations ;
1819using UnityEngine . UIElements ;
1920using FlowAction = PatchManager . Core . Flow . FlowAction ;
2021
@@ -76,11 +77,14 @@ public override void Init()
7677 if ( ! isValid )
7778 {
7879 _wasCacheInvalidated = true ;
79- SpaceWarp . API . Loading . Loading . GeneralLoadingActions . Insert ( 0 ,
80+ SpaceWarp . API . Loading . Loading . GeneralLoadingActions . Insert ( 0 , ( ) => new FlowAction ( "Patch Manager: loading Patches from Addressables" ,
81+ LoadPatchesFromAddressables ) ) ;
82+ SpaceWarp . API . Loading . Loading . GeneralLoadingActions . Insert ( 0 , ( ) => new FlowAction ( "Patch Manager: Registering all patches" , RegisterAllPatches ) ) ;
83+ SpaceWarp . API . Loading . Loading . GeneralLoadingActions . Insert ( 2 ,
8084 ( ) => new FlowAction ( "Patch Manager: Creating New Assets" , PatchingManager . CreateNewAssets ) ) ;
81- SpaceWarp . API . Loading . Loading . GeneralLoadingActions . Insert ( 1 ,
85+ SpaceWarp . API . Loading . Loading . GeneralLoadingActions . Insert ( 3 ,
8286 ( ) => new FlowAction ( "Patch Manager: Rebuilding Cache" , PatchingManager . RebuildAllCache ) ) ;
83- SpaceWarp . API . Loading . Loading . GeneralLoadingActions . Insert ( 2 ,
87+ SpaceWarp . API . Loading . Loading . GeneralLoadingActions . Insert ( 4 ,
8488 ( ) => new FlowAction ( "Patch Manager: Registering Resource Locator" , RegisterResourceLocator ) ) ;
8589 }
8690 else
@@ -90,6 +94,24 @@ public override void Init()
9094 }
9195 }
9296
97+ private static void RegisterAllPatches ( Action resolve , Action < string > reject )
98+ {
99+ PatchingManager . RegisterPatches ( ) ;
100+ resolve ( ) ;
101+ }
102+
103+ private static void LoadPatchesFromAddressables ( Action resolve , Action < string > reject )
104+ {
105+ var handle = GameManager . Instance . Assets . LoadAssetsAsync < TextAsset > ( PATCH_LABEL , asset => { PatchingManager . ImportAssetPatch ( asset , REDUX_MOD_ID ) ; } ) ;
106+ handle . Completed += result =>
107+ {
108+ if ( result . Status == AsyncOperationStatus . Succeeded )
109+ resolve ( ) ;
110+ else
111+ reject ( "Failed to load patch assets!" ) ;
112+ } ;
113+ }
114+
93115 /// <inheritdoc />
94116 public override void PreLoad ( )
95117 {
@@ -123,16 +145,6 @@ public override void PreLoad()
123145 . Replace ( "\\ " , "-" )
124146 ) . ToHashSet ( ) ) ;
125147
126- var handle = GameManager . Instance . Assets . LoadAssetsAsync < TextAsset > ( PATCH_LABEL , asset =>
127- {
128- PatchingManager . ImportAssetPatch ( asset , REDUX_MOD_ID ) ;
129- } ) ;
130- handle . Completed += _ =>
131- {
132- Addressables . Release ( handle ) ;
133- } ;
134- handle . WaitForCompletion ( ) ;
135-
136148 foreach ( var modFolder in modFolders )
137149 {
138150 Logging . LogInfo ( $ "Loading patchers from { modFolder . Folder } ") ;
@@ -144,8 +156,6 @@ public override void PreLoad()
144156 {
145157 PatchingManager . ImportSinglePatch ( standalonePatch ) ;
146158 }
147-
148- PatchingManager . RegisterPatches ( ) ;
149159 }
150160
151161 /// <summary>
@@ -177,12 +187,13 @@ public override VisualElement GetDetails()
177187 if ( _wasCacheInvalidated )
178188 {
179189 text . text += $ "Total amount of patches: { PatchingManager . TotalPatchCount } \n ";
190+ text . text += $ "Total amount of errors: { PatchingManager . TotalErrorCount } \n ";
180191 }
181192 else
182193 {
183- text . text += "Total amount of patches: Unknown (loaded from cache)\n " ;
194+ text . text += $ "Total amount of patches: { CacheManager . Inventory . PatchCount } \n ";
195+ text . text += $ "Total amount of errors: { CacheManager . Inventory . ErrorCount } \n ";
184196 }
185- text . text += $ "Total amount of errors: { PatchingManager . TotalErrorCount } \n ";
186197
187198 text . text += "Patched labels:" ;
188199 foreach ( var label in PatchingManager . Universe . LoadedLabels )
0 commit comments