1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-08 20:57:25 +08:00
osu-lazer/osu.Game.Tournament/Components/TournamentModIcon.cs
Bartłomiej Dach 87d6a743dd
Migrate custom tournament client assets to uppercased directories
It has transpired that on filename-case-sensitive filesystems, the
tournament client does not consistently handle custom asset paths.
Videos and mods could only be looked up from `videos` and `mods`
directories (lowercase), while flags could only be looked up from the
`Flags` directory (uppercase).

A complicating circumstance is that default country flags, coming from
osu-resources, also depend on the flag lookup being uppercased.

To attempt to clean up the handling as much as it appears to be
possible, automatically move user-supplied lowercase directories to
uppercase.
2021-11-28 16:36:19 +01:00

65 lines
1.9 KiB
C#

// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures;
using osu.Game.Rulesets;
using osu.Game.Rulesets.UI;
using osu.Game.Tournament.Models;
using osuTK;
namespace osu.Game.Tournament.Components
{
/// <summary>
/// Mod icon displayed in tournament usages, allowing user overridden graphics.
/// </summary>
public class TournamentModIcon : CompositeDrawable
{
private readonly string modAcronym;
[Resolved]
private RulesetStore rulesets { get; set; }
public TournamentModIcon(string modAcronym)
{
this.modAcronym = modAcronym;
}
[BackgroundDependencyLoader]
private void load(TextureStore textures, LadderInfo ladderInfo)
{
var customTexture = textures.Get($"Mods/{modAcronym}");
if (customTexture != null)
{
AddInternal(new Sprite
{
FillMode = FillMode.Fit,
RelativeSizeAxes = Axes.Both,
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
Texture = customTexture
});
return;
}
var ruleset = rulesets.GetRuleset(ladderInfo.Ruleset.Value?.ID ?? 0);
var modIcon = ruleset?.CreateInstance().CreateModFromAcronym(modAcronym);
if (modIcon == null)
return;
AddInternal(new ModIcon(modIcon, false)
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Scale = new Vector2(0.5f)
});
}
}
}