@@ -31,6 +31,9 @@ internal class EditMapPatch : Patch
3131 /// <summary>Encapsulates monitoring and logging.</summary>
3232 private readonly IMonitor Monitor ;
3333
34+ private readonly Func < string , Map ? > TryGetMapCache ;
35+ private readonly Action < string , Map > PopulateMapCache ;
36+
3437 /// <summary>The map area from which to read tiles.</summary>
3538 private readonly TokenRectangle ? FromArea ;
3639
@@ -89,7 +92,7 @@ internal class EditMapPatch : Patch
8992 /// <param name="parentPatch">The parent patch for which this patch was loaded, if any.</param>
9093 /// <param name="monitor">Encapsulates monitoring and logging.</param>
9194 /// <param name="parseAssetName">Parse an asset name.</param>
92- public EditMapPatch ( int [ ] indexPath , LogPathBuilder path , IManagedTokenString assetName , IManagedTokenString ? assetLocale , AssetEditPriority priority , IEnumerable < Condition > conditions , IManagedTokenString ? fromAsset , TokenRectangle ? fromArea , TokenRectangle ? toArea , PatchMapMode patchMode , IEnumerable < EditMapPatchProperty > ? mapProperties , IEnumerable < EditMapPatchTile > ? mapTiles , IEnumerable < IManagedTokenString > ? addNpcWarps , IEnumerable < IManagedTokenString > ? addWarps , IEnumerable < ITextOperation > ? textOperations , UpdateRate updateRate , InvariantDictionary < IManagedTokenString > ? inheritedLocalTokens , InvariantDictionary < IManagedTokenString > ? localTokens , IContentPack contentPack , IRuntimeMigration migrator , IPatch ? parentPatch , IMonitor monitor , Func < string , IAssetName > parseAssetName )
95+ public EditMapPatch ( int [ ] indexPath , LogPathBuilder path , IManagedTokenString assetName , IManagedTokenString ? assetLocale , AssetEditPriority priority , IEnumerable < Condition > conditions , IManagedTokenString ? fromAsset , TokenRectangle ? fromArea , TokenRectangle ? toArea , PatchMapMode patchMode , IEnumerable < EditMapPatchProperty > ? mapProperties , IEnumerable < EditMapPatchTile > ? mapTiles , IEnumerable < IManagedTokenString > ? addNpcWarps , IEnumerable < IManagedTokenString > ? addWarps , IEnumerable < ITextOperation > ? textOperations , UpdateRate updateRate , InvariantDictionary < IManagedTokenString > ? inheritedLocalTokens , InvariantDictionary < IManagedTokenString > ? localTokens , IContentPack contentPack , IRuntimeMigration migrator , IPatch ? parentPatch , IMonitor monitor , Func < string , IAssetName > parseAssetName , Action < string , Map > populateMapCache , Func < string , Map ? > tryGetMapCache )
9396 : base (
9497 indexPath : indexPath ,
9598 path : path ,
@@ -117,6 +120,8 @@ public EditMapPatch(int[] indexPath, LogPathBuilder path, IManagedTokenString as
117120 this . AddWarps = addWarps ? . Reverse ( ) . ToArray ( ) ?? [ ] ;
118121 this . TextOperations = textOperations ? . ToArray ( ) ?? [ ] ;
119122 this . Monitor = monitor ;
123+ this . TryGetMapCache = tryGetMapCache ;
124+ this . PopulateMapCache = populateMapCache ;
120125
121126 this . Contextuals
122127 . Add ( this . FromArea )
@@ -150,7 +155,12 @@ public override void Edit<T>(IAssetData asset)
150155 // apply map area patch
151156 if ( this . AppliesMapPatch )
152157 {
153- Map source = this . ContentPack . ModContent . Load < Map > ( this . FromAsset ! ) ;
158+ Map ? source = this . TryGetMapCache ( this . ContentPack . Manifest . UniqueID + "/" + this . FromAsset ! ) ;
159+ if ( source == null )
160+ {
161+ source = this . ContentPack . ModContent . Load < Map > ( this . FromAsset ! ) ;
162+ this . PopulateMapCache ( this . ContentPack . Manifest . UniqueID + "/" + this . FromAsset ! , source ) ;
163+ }
154164 if ( ! this . TryApplyMapPatch ( source , targetAsset , out string ? error ) )
155165 this . WarnForPatch ( $ "map patch couldn't be applied: { error } ") ;
156166 }
0 commit comments