fix private assets from content packs not having tracking info

This commit is contained in:
Jesse Plamondon-Willard 2019-12-14 10:38:17 -05:00
parent 3ba718749c
commit 6dc442803f
No known key found for this signature in database
GPG Key ID: CF8B1456B3E29F49
2 changed files with 19 additions and 12 deletions

View File

@ -11,6 +11,7 @@
* For modders: * For modders:
* Added asset propagation for grass textures. * Added asset propagation for grass textures.
* `helper.Read/WriteSaveData` can now be used while a save is being loaded (e.g. within a `Specialized.LoadStageChanged` event). * `helper.Read/WriteSaveData` can now be used while a save is being loaded (e.g. within a `Specialized.LoadStageChanged` event).
* Fixed private textures loaded from content packs not having their `Name` field set.
* For the web UI: * For the web UI:
* If a JSON validator upload can't be saved to Pastebin (e.g. due to rate limits), it's now uploaded to Amazon S3 instead. Files uploaded to S3 expire after one month. * If a JSON validator upload can't be saved to Pastebin (e.g. due to rate limits), it's now uploaded to Amazon S3 instead. Files uploaded to S3 expire after one month.

View File

@ -105,6 +105,7 @@ namespace StardewModdingAPI.Framework.ContentManagers
// get local asset // get local asset
SContentLoadException GetContentError(string reasonPhrase) => new SContentLoadException($"Failed loading asset '{assetName}' from {this.Name}: {reasonPhrase}"); SContentLoadException GetContentError(string reasonPhrase) => new SContentLoadException($"Failed loading asset '{assetName}' from {this.Name}: {reasonPhrase}");
T asset;
try try
{ {
// get file // get file
@ -118,22 +119,22 @@ namespace StardewModdingAPI.Framework.ContentManagers
// XNB file // XNB file
case ".xnb": case ".xnb":
{ {
T data = this.RawLoad<T>(assetName, useCache: false); asset = this.RawLoad<T>(assetName, useCache: false);
if (data is Map map) if (asset is Map map)
{ {
this.NormalizeTilesheetPaths(map); this.NormalizeTilesheetPaths(map);
this.FixCustomTilesheetPaths(map, relativeMapPath: assetName); this.FixCustomTilesheetPaths(map, relativeMapPath: assetName);
} }
return data;
} }
break;
// unpacked data // unpacked data
case ".json": case ".json":
{ {
if (!this.JsonHelper.ReadJsonFileIfExists(file.FullName, out T data)) if (!this.JsonHelper.ReadJsonFileIfExists(file.FullName, out asset))
throw GetContentError("the JSON file is invalid."); // should never happen since we check for file existence above throw GetContentError("the JSON file is invalid."); // should never happen since we check for file existence above
return data;
} }
break;
// unpacked image // unpacked image
case ".png": case ".png":
@ -143,13 +144,13 @@ namespace StardewModdingAPI.Framework.ContentManagers
throw GetContentError($"can't read file with extension '{file.Extension}' as type '{typeof(T)}'; must be type '{typeof(Texture2D)}'."); throw GetContentError($"can't read file with extension '{file.Extension}' as type '{typeof(T)}'; must be type '{typeof(Texture2D)}'.");
// fetch & cache // fetch & cache
using (FileStream stream = File.OpenRead(file.FullName)) using FileStream stream = File.OpenRead(file.FullName);
{
Texture2D texture = Texture2D.FromStream(Game1.graphics.GraphicsDevice, stream); Texture2D texture = Texture2D.FromStream(Game1.graphics.GraphicsDevice, stream);
texture = this.PremultiplyTransparency(texture); texture = this.PremultiplyTransparency(texture);
return (T)(object)texture; asset = (T)(object)texture;
}
} }
break;
// unpacked map // unpacked map
case ".tbin": case ".tbin":
@ -163,8 +164,9 @@ namespace StardewModdingAPI.Framework.ContentManagers
Map map = formatManager.LoadMap(file.FullName); Map map = formatManager.LoadMap(file.FullName);
this.NormalizeTilesheetPaths(map); this.NormalizeTilesheetPaths(map);
this.FixCustomTilesheetPaths(map, relativeMapPath: assetName); this.FixCustomTilesheetPaths(map, relativeMapPath: assetName);
return (T)(object)map; asset = (T)(object)map;
} }
break;
default: default:
throw GetContentError($"unknown file extension '{file.Extension}'; must be one of '.json', '.png', '.tbin', or '.xnb'."); throw GetContentError($"unknown file extension '{file.Extension}'; must be one of '.json', '.png', '.tbin', or '.xnb'.");
@ -176,6 +178,10 @@ namespace StardewModdingAPI.Framework.ContentManagers
throw GetContentError("couldn't find libgdiplus, which is needed to load mod images. Make sure Mono is installed and you're running the game through the normal launcher."); throw GetContentError("couldn't find libgdiplus, which is needed to load mod images. Make sure Mono is installed and you're running the game through the normal launcher.");
throw new SContentLoadException($"The content manager failed loading content asset '{assetName}' from {this.Name}.", ex); throw new SContentLoadException($"The content manager failed loading content asset '{assetName}' from {this.Name}.", ex);
} }
// track & return asset
this.TrackAsset(assetName, asset, language, useCache);
return asset;
} }
/// <summary>Create a new content manager for temporary use.</summary> /// <summary>Create a new content manager for temporary use.</summary>