1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 01:27:29 +08:00

Merge pull request #21168 from peppy/fix-storyboard-extension-lookup

Fix sprites not displaying in storyboard if filename extension is missing in script
This commit is contained in:
Dan Balasescu 2022-11-10 12:31:00 +09:00 committed by GitHub
commit dddbc7496a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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 @@ namespace osu.Game.Storyboards
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;
}