1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-07 22:22:59 +08:00

Implement mania skin reading functionality

This commit is contained in:
smoogipoo 2020-03-31 10:14:36 +09:00
parent f6f5de7ad1
commit 2b5e9885f6
2 changed files with 33 additions and 7 deletions

View File

@ -9,6 +9,8 @@ namespace osu.Game.Skinning
{ {
public class LegacyBeatmapSkin : LegacySkin public class LegacyBeatmapSkin : LegacySkin
{ {
protected override bool AllowManiaSkin => false;
public LegacyBeatmapSkin(BeatmapInfo beatmap, IResourceStore<byte[]> storage, AudioManager audioManager) public LegacyBeatmapSkin(BeatmapInfo beatmap, IResourceStore<byte[]> storage, AudioManager audioManager)
: base(createSkinInfo(beatmap), new LegacySkinResourceStore<BeatmapSetFileInfo>(beatmap.BeatmapSet, storage), audioManager, beatmap.Path) : base(createSkinInfo(beatmap), new LegacySkinResourceStore<BeatmapSetFileInfo>(beatmap.BeatmapSet, storage), audioManager, beatmap.Path)
{ {

View File

@ -26,12 +26,16 @@ namespace osu.Game.Skinning
[CanBeNull] [CanBeNull]
protected IResourceStore<SampleChannel> Samples; protected IResourceStore<SampleChannel> Samples;
protected virtual bool AllowManiaSkin => true;
public new LegacySkinConfiguration Configuration public new LegacySkinConfiguration Configuration
{ {
get => base.Configuration as LegacySkinConfiguration; get => base.Configuration as LegacySkinConfiguration;
set => base.Configuration = value; set => base.Configuration = value;
} }
private readonly Dictionary<int, LegacyManiaSkinConfiguration> maniaConfigurations = new Dictionary<int, LegacyManiaSkinConfiguration>();
public LegacySkin(SkinInfo skin, IResourceStore<byte[]> storage, AudioManager audioManager) public LegacySkin(SkinInfo skin, IResourceStore<byte[]> storage, AudioManager audioManager)
: this(skin, new LegacySkinResourceStore<SkinFileInfo>(skin, storage), audioManager, "skin.ini") : this(skin, new LegacySkinResourceStore<SkinFileInfo>(skin, storage), audioManager, "skin.ini")
{ {
@ -40,15 +44,26 @@ namespace osu.Game.Skinning
protected LegacySkin(SkinInfo skin, IResourceStore<byte[]> storage, AudioManager audioManager, string filename) protected LegacySkin(SkinInfo skin, IResourceStore<byte[]> storage, AudioManager audioManager, string filename)
: base(skin) : base(skin)
{ {
Stream stream = storage?.GetStream(filename); using (var stream = storage?.GetStream(filename))
if (stream != null)
{ {
using (LineBufferedReader reader = new LineBufferedReader(stream)) if (stream != null)
Configuration = new LegacySkinDecoder().Decode(reader); {
using (LineBufferedReader reader = new LineBufferedReader(stream, true))
Configuration = new LegacySkinDecoder().Decode(reader);
stream.Seek(0, SeekOrigin.Begin);
using (LineBufferedReader reader = new LineBufferedReader(stream))
{
var maniaList = new LegacyManiaSkinDecoder().Decode(reader);
foreach (var config in maniaList)
maniaConfigurations[config.Keys] = config;
}
}
else
Configuration = new LegacySkinConfiguration { LegacyVersion = LegacySkinConfiguration.LATEST_VERSION };
} }
else
Configuration = new LegacySkinConfiguration { LegacyVersion = LegacySkinConfiguration.LATEST_VERSION };
if (storage != null) if (storage != null)
{ {
@ -105,6 +120,15 @@ namespace osu.Game.Skinning
case SkinCustomColourLookup customColour: case SkinCustomColourLookup customColour:
return SkinUtils.As<TValue>(getCustomColour(customColour.Lookup.ToString())); return SkinUtils.As<TValue>(getCustomColour(customColour.Lookup.ToString()));
case LegacyManiaSkinConfigurationLookup legacy:
if (!AllowManiaSkin)
return null;
if (!maniaConfigurations.TryGetValue(legacy.Keys, out _))
maniaConfigurations[legacy.Keys] = new LegacyManiaSkinConfiguration(legacy.Keys);
break;
default: default:
// handles lookups like GlobalSkinConfiguration // handles lookups like GlobalSkinConfiguration