1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-19 12:23:13 +08:00

Simplify available file lookup and include file extension

This commit is contained in:
Dean Herbert 2022-04-01 15:14:53 +09:00
parent 2b7105ac4f
commit 314ad63c6e
2 changed files with 13 additions and 13 deletions

View File

@ -350,7 +350,7 @@ namespace osu.Game.Skinning.Editor
// place component
placeComponent(new SkinnableSprite
{
SpriteName = { Value = Path.GetFileNameWithoutExtension(file.Name) }
SpriteName = { Value = file.Name }
});
});

View File

@ -2,7 +2,6 @@
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
@ -31,13 +30,6 @@ namespace osu.Game.Skinning
[Resolved]
private ISkinSource source { get; set; }
public IEnumerable<string> AvailableFiles => (source.AllSources.First() as Skin)?.SkinInfo.PerformRead(s => s.Files
.Where(f =>
f.Filename.EndsWith(".png", StringComparison.Ordinal)
|| f.Filename.EndsWith(".jpg", StringComparison.Ordinal)
)
.Select(f => f.Filename).Distinct());
public SkinnableSprite(string textureName, ConfineMode confineMode = ConfineMode.NoScaling)
: base(new SpriteComponent(textureName), confineMode)
{
@ -88,14 +80,22 @@ namespace osu.Game.Skinning
public class SpriteSelectorControl : SettingsDropdown<string>
{
public SkinnableSprite Source { get; set; }
protected override void LoadComplete()
{
base.LoadComplete();
if (Source.AvailableFiles.Any())
Items = Source.AvailableFiles;
// Round-about way of getting the user's skin to find available resources.
// In the future we'll probably want to allow access to resources from the fallbacks, or potentially other skins
// but that requires further thought.
var highestPrioritySkin = ((SkinnableSprite)Source).source.AllSources.First() as Skin;
string[] availableFiles = highestPrioritySkin?.SkinInfo.PerformRead(s => s.Files
.Where(f => f.Filename.EndsWith(".png", StringComparison.Ordinal)
|| f.Filename.EndsWith(".jpg", StringComparison.Ordinal))
.Select(f => f.Filename).Distinct()).ToArray();
if (availableFiles?.Length > 0)
Items = availableFiles;
}
}
}