Make it async

This commit is contained in:
xen-42 2025-02-13 15:05:02 -05:00
parent 853e03cc99
commit 25fd6cd761

View File

@ -21,6 +21,8 @@ public class NHSlideCollectionContainer : SlideCollectionContainer
public string[] slidePaths;
public IModBehaviour mod;
private HashSet<string> _pathsBeingLoaded = new();
public static Dictionary<string, HashSet<NHSlideCollectionContainer>> _slidesRequiringPath = new();
static NHSlideCollectionContainer()
{
@ -196,10 +198,31 @@ public class NHSlideCollectionContainer : SlideCollectionContainer
_slidesRequiringPath[key].Add(this);
}
if (ImageUtilities.IsTextureLoaded(mod, path))
{
var texture = ImageUtilities.GetTexture(mod, path);
this.slideCollection.slides[wrappedIndex]._image = texture;
return texture;
}
else if (!_pathsBeingLoaded.Contains(path))
{
var loader = new SlideReelAsyncImageLoader();
loader.PathsToLoad.Add((wrappedIndex, path));
loader.Start(true, false);
loader.imageLoadedEvent.AddListener((Texture2D tex, int index, string originalPath) =>
{
slideCollection.slides[wrappedIndex]._image = tex;
_pathsBeingLoaded.Remove(path);
});
_pathsBeingLoaded.Add(path);
return null;
}
else
{
// It is being loaded so we just wait
return null;
}
}
var texture = LoadSlideInt(index);
LoadSlideInt(index - 1);
LoadSlideInt(index + 1);