Skip to content

Commit 40a23c6

Browse files
committed
Load assets from addressables at the correct place, cache the total patch count and error count
1 parent 34ee6ac commit 40a23c6

File tree

4 files changed

+46
-17
lines changed

4 files changed

+46
-17
lines changed

Runtime/Core/Assets/PatchingManager.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,11 @@ bool killLoadingBarTips
350350
}
351351

352352
InjectPatchManagerTips = !killLoadingBarTips;
353+
if (killLoadingBarTips)
354+
{
355+
CacheManager.SetTotalPatchCount(TotalPatchCount);
356+
CacheManager.SetTotalErrorCount(TotalErrorCount);
357+
}
353358
resolve();
354359
}
355360
}

Runtime/Core/Cache/CacheManager.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,16 @@ public static void InvalidateCache()
8282
CreateCacheFolderIfNotExists();
8383
}
8484

85+
public static void SetTotalPatchCount(int count)
86+
{
87+
Inventory.PatchCount = count;
88+
}
89+
90+
public static void SetTotalErrorCount(int count)
91+
{
92+
Inventory.ErrorCount = count;
93+
}
94+
8595
public static void SaveInventory()
8696
{
8797
Inventory.Save(InventoryPath);

Runtime/Core/Cache/Json/Inventory.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ public sealed class Inventory
3131
[JsonProperty("patch_hashes", Required = Required.Always)]
3232
public PatchHashes Patches { get; internal set; }
3333

34+
[JsonProperty("patch_count")] public int PatchCount { get; internal set; } = 0;
35+
[JsonProperty("error_count")] public int ErrorCount { get; internal set; } = 0;
36+
3437
/// <summary>
3538
/// Get a <see cref="CacheEntry"/> by its label.
3639
/// </summary>

Runtime/Core/CoreModule.cs

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using Unity.VisualScripting;
1616
using UnityEngine;
1717
using UnityEngine.AddressableAssets;
18+
using UnityEngine.ResourceManagement.AsyncOperations;
1819
using UnityEngine.UIElements;
1920
using 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

Comments
 (0)