Merge pull request #883 from SinZ163/feature/sinz/farmhand-mapedit
Add logic to remove from the multiplayer map cache for asset propagation
This commit is contained in:
commit
a52f888c3f
|
@ -129,6 +129,7 @@ namespace StardewModdingAPI.Framework
|
||||||
/// <param name="rootDirectory">The root directory to search for content.</param>
|
/// <param name="rootDirectory">The root directory to search for content.</param>
|
||||||
/// <param name="currentCulture">The current culture for which to localize content.</param>
|
/// <param name="currentCulture">The current culture for which to localize content.</param>
|
||||||
/// <param name="monitor">Encapsulates monitoring and logging.</param>
|
/// <param name="monitor">Encapsulates monitoring and logging.</param>
|
||||||
|
/// <param name="multiplayer">The multiplayer instance whose map cache to update during asset propagation.</param>
|
||||||
/// <param name="reflection">Simplifies access to private code.</param>
|
/// <param name="reflection">Simplifies access to private code.</param>
|
||||||
/// <param name="jsonHelper">Encapsulates SMAPI's JSON file parsing.</param>
|
/// <param name="jsonHelper">Encapsulates SMAPI's JSON file parsing.</param>
|
||||||
/// <param name="onLoadingFirstAsset">A callback to invoke the first time *any* game content manager loads an asset.</param>
|
/// <param name="onLoadingFirstAsset">A callback to invoke the first time *any* game content manager loads an asset.</param>
|
||||||
|
@ -136,7 +137,7 @@ namespace StardewModdingAPI.Framework
|
||||||
/// <param name="getFileLookup">Get a file lookup for the given directory.</param>
|
/// <param name="getFileLookup">Get a file lookup for the given directory.</param>
|
||||||
/// <param name="onAssetsInvalidated">A callback to invoke when any asset names have been invalidated from the cache.</param>
|
/// <param name="onAssetsInvalidated">A callback to invoke when any asset names have been invalidated from the cache.</param>
|
||||||
/// <param name="requestAssetOperations">Get the load/edit operations to apply to an asset by querying registered <see cref="IContentEvents.AssetRequested"/> event handlers.</param>
|
/// <param name="requestAssetOperations">Get the load/edit operations to apply to an asset by querying registered <see cref="IContentEvents.AssetRequested"/> event handlers.</param>
|
||||||
public ContentCoordinator(IServiceProvider serviceProvider, string rootDirectory, CultureInfo currentCulture, IMonitor monitor, Reflector reflection, JsonHelper jsonHelper, Action onLoadingFirstAsset, Action<BaseContentManager, IAssetName> onAssetLoaded, Func<string, IFileLookup> getFileLookup, Action<IList<IAssetName>> onAssetsInvalidated, Func<IAssetInfo, AssetOperationGroup?> requestAssetOperations)
|
public ContentCoordinator(IServiceProvider serviceProvider, string rootDirectory, CultureInfo currentCulture, IMonitor monitor, Multiplayer multiplayer, Reflector reflection, JsonHelper jsonHelper, Action onLoadingFirstAsset, Action<BaseContentManager, IAssetName> onAssetLoaded, Func<string, IFileLookup> getFileLookup, Action<IList<IAssetName>> onAssetsInvalidated, Func<IAssetInfo, AssetOperationGroup?> requestAssetOperations)
|
||||||
{
|
{
|
||||||
this.GetFileLookup = getFileLookup;
|
this.GetFileLookup = getFileLookup;
|
||||||
this.Monitor = monitor ?? throw new ArgumentNullException(nameof(monitor));
|
this.Monitor = monitor ?? throw new ArgumentNullException(nameof(monitor));
|
||||||
|
@ -177,7 +178,7 @@ namespace StardewModdingAPI.Framework
|
||||||
this.ContentManagers.Add(contentManagerForAssetPropagation);
|
this.ContentManagers.Add(contentManagerForAssetPropagation);
|
||||||
|
|
||||||
this.VanillaContentManager = new LocalizedContentManager(serviceProvider, rootDirectory);
|
this.VanillaContentManager = new LocalizedContentManager(serviceProvider, rootDirectory);
|
||||||
this.CoreAssets = new CoreAssetPropagator(this.MainContentManager, contentManagerForAssetPropagation, this.Monitor, reflection, name => this.ParseAssetName(name, allowLocales: true));
|
this.CoreAssets = new CoreAssetPropagator(this.MainContentManager, contentManagerForAssetPropagation, this.Monitor, multiplayer, reflection, name => this.ParseAssetName(name, allowLocales: true));
|
||||||
this.LocaleCodes = new Lazy<Dictionary<string, LocalizedContentManager.LanguageCode>>(() => this.GetLocaleCodes(customLanguages: Enumerable.Empty<ModLanguage>()));
|
this.LocaleCodes = new Lazy<Dictionary<string, LocalizedContentManager.LanguageCode>>(() => this.GetLocaleCodes(customLanguages: Enumerable.Empty<ModLanguage>()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1351,6 +1351,7 @@ namespace StardewModdingAPI.Framework
|
||||||
rootDirectory: rootDirectory,
|
rootDirectory: rootDirectory,
|
||||||
currentCulture: Thread.CurrentThread.CurrentUICulture,
|
currentCulture: Thread.CurrentThread.CurrentUICulture,
|
||||||
monitor: this.Monitor,
|
monitor: this.Monitor,
|
||||||
|
multiplayer: this.Multiplayer,
|
||||||
reflection: this.Reflection,
|
reflection: this.Reflection,
|
||||||
jsonHelper: this.Toolkit.JsonHelper,
|
jsonHelper: this.Toolkit.JsonHelper,
|
||||||
onLoadingFirstAsset: this.InitializeBeforeFirstAssetLoaded,
|
onLoadingFirstAsset: this.InitializeBeforeFirstAssetLoaded,
|
||||||
|
|
|
@ -40,6 +40,9 @@ namespace StardewModdingAPI.Metadata
|
||||||
/// <summary>Writes messages to the console.</summary>
|
/// <summary>Writes messages to the console.</summary>
|
||||||
private readonly IMonitor Monitor;
|
private readonly IMonitor Monitor;
|
||||||
|
|
||||||
|
/// <summary>The multiplayer instance whose map cache to update.</summary>
|
||||||
|
private readonly Multiplayer Multiplayer;
|
||||||
|
|
||||||
/// <summary>Simplifies access to private game code.</summary>
|
/// <summary>Simplifies access to private game code.</summary>
|
||||||
private readonly Reflector Reflection;
|
private readonly Reflector Reflection;
|
||||||
|
|
||||||
|
@ -70,13 +73,15 @@ namespace StardewModdingAPI.Metadata
|
||||||
/// <param name="mainContent">The main content manager through which to reload assets.</param>
|
/// <param name="mainContent">The main content manager through which to reload assets.</param>
|
||||||
/// <param name="disposableContent">An internal content manager used only for asset propagation.</param>
|
/// <param name="disposableContent">An internal content manager used only for asset propagation.</param>
|
||||||
/// <param name="monitor">Writes messages to the console.</param>
|
/// <param name="monitor">Writes messages to the console.</param>
|
||||||
|
/// <param name="multiplayer">The multiplayer instance whose map cache to update.</param>
|
||||||
/// <param name="reflection">Simplifies access to private code.</param>
|
/// <param name="reflection">Simplifies access to private code.</param>
|
||||||
/// <param name="parseAssetName">Parse a raw asset name.</param>
|
/// <param name="parseAssetName">Parse a raw asset name.</param>
|
||||||
public CoreAssetPropagator(LocalizedContentManager mainContent, GameContentManagerForAssetPropagation disposableContent, IMonitor monitor, Reflector reflection, Func<string, IAssetName> parseAssetName)
|
public CoreAssetPropagator(LocalizedContentManager mainContent, GameContentManagerForAssetPropagation disposableContent, IMonitor monitor, Multiplayer multiplayer, Reflector reflection, Func<string, IAssetName> parseAssetName)
|
||||||
{
|
{
|
||||||
this.MainContentManager = mainContent;
|
this.MainContentManager = mainContent;
|
||||||
this.DisposableContentManager = disposableContent;
|
this.DisposableContentManager = disposableContent;
|
||||||
this.Monitor = monitor;
|
this.Monitor = monitor;
|
||||||
|
this.Multiplayer = multiplayer;
|
||||||
this.Reflection = reflection;
|
this.Reflection = reflection;
|
||||||
this.ParseAssetName = parseAssetName;
|
this.ParseAssetName = parseAssetName;
|
||||||
}
|
}
|
||||||
|
@ -1166,6 +1171,10 @@ namespace StardewModdingAPI.Metadata
|
||||||
GameLocation location = locationInfo.Location;
|
GameLocation location = locationInfo.Location;
|
||||||
Vector2? playerPos = Game1.player?.Position;
|
Vector2? playerPos = Game1.player?.Position;
|
||||||
|
|
||||||
|
// clear multiplayer cache for farmhands
|
||||||
|
if (!Context.IsMainPlayer)
|
||||||
|
this.Multiplayer.cachedMultiplayerMaps.Remove(location.NameOrUniqueName);
|
||||||
|
|
||||||
// reload map
|
// reload map
|
||||||
location.interiorDoors.Clear(); // prevent errors when doors try to update tiles which no longer exist
|
location.interiorDoors.Clear(); // prevent errors when doors try to update tiles which no longer exist
|
||||||
location.reloadMap();
|
location.reloadMap();
|
||||||
|
|
Loading…
Reference in New Issue