From b07d2340a9a6da22ee0fd95f2c6ccca3939cb7ab Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Tue, 22 Mar 2022 23:00:18 -0400 Subject: encapsulate & cache asset operation groups (#766) This is needed for the upcoming Stardew Valley 1.6 to avoid duplicate checks between DoesAssetExist and Load calls, and to make sure the answer doesn't change between them. --- .../ContentManagers/GameContentManager.cs | 44 +++------------------- 1 file changed, 6 insertions(+), 38 deletions(-) (limited to 'src/SMAPI/Framework/ContentManagers') diff --git a/src/SMAPI/Framework/ContentManagers/GameContentManager.cs b/src/SMAPI/Framework/ContentManagers/GameContentManager.cs index 7ed1fcda..642e526c 100644 --- a/src/SMAPI/Framework/ContentManagers/GameContentManager.cs +++ b/src/SMAPI/Framework/ContentManagers/GameContentManager.cs @@ -26,12 +26,6 @@ namespace StardewModdingAPI.Framework.ContentManagers /// The assets currently being intercepted by instances. This is used to prevent infinite loops when a loader loads a new asset. private readonly ContextHash AssetsBeingLoaded = new(); - /// Interceptors which provide the initial versions of matching assets. - private IList> Loaders => this.Coordinator.Loaders; - - /// Interceptors which edit matching assets after they're loaded. - private IList> Editors => this.Coordinator.Editors; - /// Maps asset names to their localized form, like LooseSprites\Billboard => LooseSprites\Billboard.fr-FR (localized) or Maps\AnimalShop => Maps\AnimalShop (not localized). private IDictionary LocalizedAssetNames => LocalizedContentManager.localizedAssetNames; @@ -370,22 +364,9 @@ namespace StardewModdingAPI.Framework.ContentManagers /// The basic asset metadata. private IEnumerable GetLoaders(IAssetInfo info) { - return this.Loaders - .Where(loader => - { - try - { - return loader.Data.CanLoad(info); - } - catch (Exception ex) - { - loader.Mod.LogAsMod($"Mod failed when checking whether it could load asset '{info.Name}', and will be ignored. Error details:\n{ex.GetLogSummary()}", LogLevel.Error); - return false; - } - }) - .Select( - loader => new AssetLoadOperation(loader.Mod, assetInfo => loader.Data.Load(assetInfo)) - ); + return this.Coordinator + .GetAssetOperations(info) + .SelectMany(p => p.LoadOperations); } /// Get the asset editors to apply to an asset. @@ -393,22 +374,9 @@ namespace StardewModdingAPI.Framework.ContentManagers /// The basic asset metadata. private IEnumerable GetEditors(IAssetInfo info) { - return this.Editors - .Where(editor => - { - try - { - return editor.Data.CanEdit(info); - } - catch (Exception ex) - { - editor.Mod.LogAsMod($"Mod crashed when checking whether it could edit asset '{info.Name}', and will be ignored. Error details:\n{ex.GetLogSummary()}", LogLevel.Error); - return false; - } - }) - .Select( - editor => new AssetEditOperation(editor.Mod, assetData => editor.Data.Edit(assetData)) - ); + return this.Coordinator + .GetAssetOperations(info) + .SelectMany(p => p.EditOperations); } /// Assert that at most one loader will be applied to an asset. -- cgit