Fix sprites not displaying in storyboard if filename extension is missing in script

This commit is contained in:
Dean Herbert 2022-11-08 14:34:28 +09:00
parent 49f530910c
commit 0b34340447
1 changed files with 23 additions and 3 deletions

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text.
using System.Collections.Generic;
using System.IO;
using System.Linq;
using osu.Framework.Graphics.Textures;
using osu.Game.Beatmaps;
@ -89,12 +90,31 @@ public bool ReplacesBackground
public DrawableStoryboard CreateDrawable(IReadOnlyList<Mod>? mods = null) =>
new DrawableStoryboard(this, mods);
private static readonly string[] image_extensions = { @".png", @".jpg" };
public Texture? GetTextureFromPath(string path, TextureStore textureStore)
{
string? storyboardPath = BeatmapInfo.BeatmapSet?.GetPathForFile(path);
string? resolvedPath = null;
if (!string.IsNullOrEmpty(storyboardPath))
return textureStore.Get(storyboardPath);
if (Path.HasExtension(path))
{
resolvedPath = BeatmapInfo.BeatmapSet?.GetPathForFile(path);
}
else
{
// Just doing this extension logic locally here for simplicity.
//
// A more "sane" path may be to use the ISkinSource.GetTexture path (which will use the extensions of the underlying TextureStore),
// but comes with potential complexity (what happens if the user has beatmap skins disabled?).
foreach (string ext in image_extensions)
{
if ((resolvedPath = BeatmapInfo.BeatmapSet?.GetPathForFile($"{path}{ext}")) != null)
break;
}
}
if (!string.IsNullOrEmpty(resolvedPath))
return textureStore.Get(resolvedPath);
return null;
}