mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
Fix atlas breaking if it had a blank slide, cache solid colour texture
This commit is contained in:
parent
45c7971347
commit
96cebc3476
@ -511,6 +511,7 @@ namespace NewHorizons.Builder.Props
|
||||
|
||||
if (useAtlasCache && cacheExists)
|
||||
{
|
||||
NHLogger.LogVerbose($"The atlas cache for slide reel containing [{slides.FirstOrDefault(x => !string.IsNullOrEmpty(x.imagePath))?.imagePath}] is {atlasKey}");
|
||||
// Load the atlas texture used to draw onto the physical slide reel object
|
||||
atlasImageLoader.PathsToLoad.Add((0, Path.Combine(mod.ModHelper.Manifest.ModFolderPath, ATLAS_SLIDE_CACHE_FOLDER, $"{atlasKey}.png")));
|
||||
}
|
||||
@ -523,7 +524,12 @@ namespace NewHorizons.Builder.Props
|
||||
|
||||
if (string.IsNullOrEmpty(slideInfo.imagePath))
|
||||
{
|
||||
imageLoader.imageLoadedEvent?.Invoke(Texture2D.blackTexture, i, null);
|
||||
// Delay at least one frame to let things subscribe to the event before it fires
|
||||
int index = i;
|
||||
Delay.FireOnNextUpdate(() =>
|
||||
{
|
||||
imageLoader.imageLoadedEvent?.Invoke(ImageUtilities.MakeSolidColorTexture(256, 256, Color.black), index, null);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@ -425,6 +425,9 @@ namespace NewHorizons.Utility.Files
|
||||
}
|
||||
public static Texture2D MakeSolidColorTexture(int width, int height, Color color)
|
||||
{
|
||||
var key = $"{color} {width} {height}";
|
||||
if (_textureCache.TryGetValue(key, out var existingTexture)) return (Texture2D)existingTexture;
|
||||
|
||||
var pixels = new Color[width * height];
|
||||
|
||||
for (int i = 0; i < pixels.Length; i++)
|
||||
@ -435,6 +438,9 @@ namespace NewHorizons.Utility.Files
|
||||
var newTexture = new Texture2D(width, height);
|
||||
newTexture.SetPixels(pixels);
|
||||
newTexture.Apply();
|
||||
|
||||
_textureCache.Add(key, newTexture);
|
||||
|
||||
return newTexture;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user