mirror of
https://github.com/ppy/osu
synced 2024-12-16 20:05:41 +00:00
Merge pull request #2244 from peppy/skin-ini-parsing
Add skin.ini parsing
This commit is contained in:
commit
606ad4b93b
@ -96,7 +96,7 @@ namespace osu.Game.Beatmaps.Formats
|
||||
|
||||
private void handleGeneral(string line)
|
||||
{
|
||||
var pair = SplitKeyVal(line, ':');
|
||||
var pair = SplitKeyVal(line);
|
||||
|
||||
var metadata = beatmap.BeatmapInfo.Metadata;
|
||||
switch (pair.Key)
|
||||
@ -155,7 +155,7 @@ namespace osu.Game.Beatmaps.Formats
|
||||
|
||||
private void handleEditor(string line)
|
||||
{
|
||||
var pair = SplitKeyVal(line, ':');
|
||||
var pair = SplitKeyVal(line);
|
||||
|
||||
switch (pair.Key)
|
||||
{
|
||||
@ -179,7 +179,7 @@ namespace osu.Game.Beatmaps.Formats
|
||||
|
||||
private void handleMetadata(string line)
|
||||
{
|
||||
var pair = SplitKeyVal(line, ':');
|
||||
var pair = SplitKeyVal(line);
|
||||
|
||||
var metadata = beatmap.BeatmapInfo.Metadata;
|
||||
switch (pair.Key)
|
||||
@ -220,7 +220,7 @@ namespace osu.Game.Beatmaps.Formats
|
||||
|
||||
private void handleDifficulty(string line)
|
||||
{
|
||||
var pair = SplitKeyVal(line, ':');
|
||||
var pair = SplitKeyVal(line);
|
||||
|
||||
var difficulty = beatmap.BeatmapInfo.BaseDifficulty;
|
||||
switch (pair.Key)
|
||||
|
@ -55,7 +55,7 @@ namespace osu.Game.Beatmaps.Formats
|
||||
|
||||
private void handleColours(T output, string line)
|
||||
{
|
||||
var pair = SplitKeyVal(line, ':');
|
||||
var pair = SplitKeyVal(line);
|
||||
|
||||
bool isCombo = pair.Key.StartsWith(@"Combo");
|
||||
|
||||
@ -89,7 +89,7 @@ namespace osu.Game.Beatmaps.Formats
|
||||
}
|
||||
}
|
||||
|
||||
protected KeyValuePair<string, string> SplitKeyVal(string line, char separator)
|
||||
protected KeyValuePair<string, string> SplitKeyVal(string line, char separator = ':')
|
||||
{
|
||||
var split = line.Trim().Split(new[] { separator }, 2);
|
||||
|
||||
|
@ -47,7 +47,7 @@ namespace osu.Game.Overlays.Settings.Sections
|
||||
},
|
||||
};
|
||||
|
||||
void reloadSkins() => skinDropdown.Items = skins.GetAllUsableSkins().Select(s => new KeyValuePair<string, int>(s.Name, s.ID));
|
||||
void reloadSkins() => skinDropdown.Items = skins.GetAllUsableSkins().Select(s => new KeyValuePair<string, int>(s.ToString(), s.ID));
|
||||
skins.ItemAdded += _ => reloadSkins();
|
||||
skins.ItemRemoved += _ => reloadSkins();
|
||||
|
||||
|
@ -11,6 +11,7 @@ namespace osu.Game.Skinning
|
||||
public DefaultSkin()
|
||||
: base(SkinInfo.Default)
|
||||
{
|
||||
Configuration = new SkinConfiguration();
|
||||
}
|
||||
|
||||
public override Drawable GetDrawableComponent(string componentName)
|
||||
|
@ -25,6 +25,14 @@ namespace osu.Game.Skinning
|
||||
storage = new LegacySkinResourceStore(skin, storage);
|
||||
samples = audioManager.GetSampleManager(storage);
|
||||
textures = new TextureStore(new RawTextureLoaderStore(storage));
|
||||
|
||||
Stream stream = storage.GetStream("skin.ini");
|
||||
|
||||
if (stream != null)
|
||||
using (StreamReader reader = new StreamReader(stream))
|
||||
Configuration = new LegacySkinDecoder().Decode(reader);
|
||||
else
|
||||
Configuration = new SkinConfiguration();
|
||||
}
|
||||
|
||||
public override Drawable GetDrawableComponent(string componentName)
|
||||
@ -60,10 +68,12 @@ namespace osu.Game.Skinning
|
||||
|
||||
private string getPathForFile(string filename)
|
||||
{
|
||||
bool hasExtension = filename.Contains('.');
|
||||
|
||||
string lastPiece = filename.Split('/').Last();
|
||||
|
||||
var file = skin.Files.FirstOrDefault(f =>
|
||||
string.Equals(Path.GetFileNameWithoutExtension(f.Filename), lastPiece, StringComparison.InvariantCultureIgnoreCase));
|
||||
string.Equals(hasExtension ? f.Filename : Path.GetFileNameWithoutExtension(f.Filename), lastPiece, StringComparison.InvariantCultureIgnoreCase));
|
||||
return file?.FileInfo.StoragePath;
|
||||
}
|
||||
|
||||
@ -73,9 +83,17 @@ namespace osu.Game.Skinning
|
||||
this.underlyingStore = underlyingStore;
|
||||
}
|
||||
|
||||
public Stream GetStream(string name) => underlyingStore.GetStream(getPathForFile(name));
|
||||
public Stream GetStream(string name)
|
||||
{
|
||||
string path = getPathForFile(name);
|
||||
return path == null ? null : underlyingStore.GetStream(path);
|
||||
}
|
||||
|
||||
byte[] IResourceStore<byte[]>.Get(string name) => underlyingStore.Get(getPathForFile(name));
|
||||
byte[] IResourceStore<byte[]>.Get(string name)
|
||||
{
|
||||
string path = getPathForFile(name);
|
||||
return path == null ? null : underlyingStore.Get(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
38
osu.Game/Skinning/LegacySkinDecoder.cs
Normal file
38
osu.Game/Skinning/LegacySkinDecoder.cs
Normal file
@ -0,0 +1,38 @@
|
||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using osu.Game.Beatmaps.Formats;
|
||||
|
||||
namespace osu.Game.Skinning
|
||||
{
|
||||
public class LegacySkinDecoder : LegacyDecoder<SkinConfiguration>
|
||||
{
|
||||
public LegacySkinDecoder()
|
||||
: base(1)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void ParseLine(SkinConfiguration output, Section section, string line)
|
||||
{
|
||||
switch (section)
|
||||
{
|
||||
case Section.General:
|
||||
var pair = SplitKeyVal(line);
|
||||
|
||||
switch (pair.Key)
|
||||
{
|
||||
case @"Name":
|
||||
output.SkinInfo.Name = pair.Value;
|
||||
break;
|
||||
case @"Author":
|
||||
output.SkinInfo.Creator = pair.Value;
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
base.ParseLine(output, section, line);
|
||||
}
|
||||
}
|
||||
}
|
@ -10,6 +10,8 @@ namespace osu.Game.Skinning
|
||||
{
|
||||
public readonly SkinInfo SkinInfo;
|
||||
|
||||
public virtual SkinConfiguration Configuration { get; protected set; }
|
||||
|
||||
public abstract Drawable GetDrawableComponent(string componentName);
|
||||
|
||||
public abstract SampleChannel GetSample(string sampleName);
|
||||
|
18
osu.Game/Skinning/SkinConfiguration.cs
Normal file
18
osu.Game/Skinning/SkinConfiguration.cs
Normal file
@ -0,0 +1,18 @@
|
||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System.Collections.Generic;
|
||||
using osu.Game.Beatmaps.Formats;
|
||||
using OpenTK.Graphics;
|
||||
|
||||
namespace osu.Game.Skinning
|
||||
{
|
||||
public class SkinConfiguration : IHasComboColours, IHasCustomColours
|
||||
{
|
||||
public readonly SkinInfo SkinInfo = new SkinInfo();
|
||||
|
||||
public List<Color4> ComboColours { get; set; } = new List<Color4>();
|
||||
|
||||
public Dictionary<string, Color4> CustomColours { get; set; } = new Dictionary<string, Color4>();
|
||||
}
|
||||
}
|
@ -24,5 +24,7 @@ namespace osu.Game.Skinning
|
||||
public static SkinInfo Default { get; } = new SkinInfo { Name = "osu!lazer", Creator = "team osu!" };
|
||||
|
||||
public bool Equals(SkinInfo other) => other != null && ID == other.ID;
|
||||
|
||||
public override string ToString() => $"\"{Name}\" by {Creator}";
|
||||
}
|
||||
}
|
||||
|
@ -39,6 +39,31 @@ namespace osu.Game.Skinning
|
||||
Name = archive.Name
|
||||
};
|
||||
|
||||
protected override void Populate(SkinInfo model, ArchiveReader archive)
|
||||
{
|
||||
base.Populate(model, archive);
|
||||
populate(model);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Populate a <see cref="SkinInfo"/> from its <see cref="SkinConfiguration"/> (if possible).
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
private void populate(SkinInfo model)
|
||||
{
|
||||
Skin reference = GetSkin(model);
|
||||
if (!string.IsNullOrEmpty(reference.Configuration.SkinInfo.Name))
|
||||
{
|
||||
model.Name = reference.Configuration.SkinInfo.Name;
|
||||
model.Creator = reference.Configuration.SkinInfo.Creator;
|
||||
}
|
||||
else
|
||||
{
|
||||
model.Name = model.Name.Replace(".osk", "");
|
||||
model.Creator = "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve a <see cref="Skin"/> instance for the provided <see cref="SkinInfo"/>
|
||||
/// </summary>
|
||||
@ -65,6 +90,16 @@ namespace osu.Game.Skinning
|
||||
if (skin.SkinInfo != CurrentSkinInfo.Value)
|
||||
throw new InvalidOperationException($"Setting {nameof(CurrentSkin)}'s value directly is not supported. Use {nameof(CurrentSkinInfo)} instead.");
|
||||
};
|
||||
|
||||
// migrate older imports which didn't have access to skin.ini
|
||||
using (ContextFactory.GetForWrite())
|
||||
{
|
||||
foreach (var skinInfo in ModelStore.ConsumableItems.Where(s => s.Name.EndsWith(".osk")))
|
||||
{
|
||||
populate(skinInfo);
|
||||
Update(skinInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -873,7 +873,9 @@
|
||||
<Compile Include="Screens\Tournament\Teams\StorageBackedTeamList.cs" />
|
||||
<Compile Include="Skinning\DefaultSkin.cs" />
|
||||
<Compile Include="Skinning\LegacySkin.cs" />
|
||||
<Compile Include="Skinning\LegacySkinDecoder.cs" />
|
||||
<Compile Include="Skinning\Skin.cs" />
|
||||
<Compile Include="Skinning\SkinConfiguration.cs" />
|
||||
<Compile Include="Skinning\SkinFileInfo.cs" />
|
||||
<Compile Include="Skinning\SkinInfo.cs" />
|
||||
<Compile Include="Skinning\SkinManager.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user