mirror of
https://github.com/ppy/osu.git
synced 2025-01-26 12:25:04 +08:00
Add ability to lookup arbitrary SkinConfiguration values
This commit is contained in:
parent
c4fe6a04c5
commit
425d4aa766
@ -23,5 +23,9 @@ namespace osu.Game.Skinning
|
||||
SampleChannel GetSample(string sampleName);
|
||||
|
||||
Color4? GetColour(string colourName);
|
||||
|
||||
TValue GetConfiguration<TConfiguration, TValue>(Func<TConfiguration, TValue> query) where TConfiguration : SkinConfiguration where TValue : class;
|
||||
|
||||
TValue? GetConfiguration<TConfiguration, TValue>(Func<TConfiguration, TValue?> query) where TConfiguration : SkinConfiguration where TValue : struct;
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,26 @@ namespace osu.Game.Skinning
|
||||
|
||||
public Color4? GetColour(string colourName) => source.GetColour(colourName) ?? fallbackSource?.GetColour(colourName);
|
||||
|
||||
public TValue? GetConfiguration<TConfiguration, TValue>(Func<TConfiguration, TValue?> query) where TConfiguration : SkinConfiguration where TValue : struct
|
||||
{
|
||||
TValue? val = null;
|
||||
var conf = (source as Skin)?.Configuration as TConfiguration;
|
||||
if (conf != null)
|
||||
val = query?.Invoke(conf);
|
||||
|
||||
return val ?? fallbackSource?.GetConfiguration(query);
|
||||
}
|
||||
|
||||
public TValue GetConfiguration<TConfiguration, TValue>(Func<TConfiguration, TValue> query) where TConfiguration : SkinConfiguration where TValue : class
|
||||
{
|
||||
TValue val = null;
|
||||
var conf = (source as Skin)?.Configuration as TConfiguration;
|
||||
if (conf != null)
|
||||
val = query?.Invoke(conf);
|
||||
|
||||
return val ?? fallbackSource?.GetConfiguration(query);
|
||||
}
|
||||
|
||||
private readonly ISkinSource source;
|
||||
private ISkinSource fallbackSource;
|
||||
|
||||
|
@ -34,7 +34,7 @@ namespace osu.Game.Skinning
|
||||
{
|
||||
case "Combo":
|
||||
int index = int.Parse(namespaces[2]);
|
||||
return Configuration.ComboColours.Count == 0 ? (Color4?)null : Configuration.ComboColours[index % Configuration.ComboColours.Count];
|
||||
return GetConfiguration<SkinConfiguration, Color4>(s => s.ComboColours.Count == 0 ? (Color4?)null : Configuration.ComboColours[index % Configuration.ComboColours.Count]);
|
||||
}
|
||||
|
||||
break;
|
||||
@ -43,6 +43,12 @@ namespace osu.Game.Skinning
|
||||
return null;
|
||||
}
|
||||
|
||||
public TValue GetConfiguration<TConfiguration, TValue>(Func<TConfiguration, TValue> query) where TConfiguration : SkinConfiguration where TValue : class
|
||||
=> Configuration is TConfiguration conf ? query?.Invoke(conf) : null;
|
||||
|
||||
public TValue? GetConfiguration<TConfiguration, TValue>(Func<TConfiguration, TValue?> query) where TConfiguration : SkinConfiguration where TValue : struct
|
||||
=> Configuration is TConfiguration conf ? query?.Invoke(conf) : null;
|
||||
|
||||
protected Skin(SkinInfo skin)
|
||||
{
|
||||
SkinInfo = skin;
|
||||
|
@ -119,10 +119,14 @@ namespace osu.Game.Skinning
|
||||
|
||||
public Drawable GetDrawableComponent(string componentName) => CurrentSkin.Value.GetDrawableComponent(componentName);
|
||||
|
||||
public Texture GetTexture(string componentName)=> CurrentSkin.Value.GetTexture(componentName);
|
||||
public Texture GetTexture(string componentName) => CurrentSkin.Value.GetTexture(componentName);
|
||||
|
||||
public SampleChannel GetSample(string sampleName) => CurrentSkin.Value.GetSample(sampleName);
|
||||
|
||||
public Color4? GetColour(string colourName) => CurrentSkin.Value.GetColour(colourName);
|
||||
|
||||
public TValue GetConfiguration<TConfiguration, TValue>(Func<TConfiguration, TValue> query) where TConfiguration : SkinConfiguration where TValue : class => CurrentSkin.Value.GetConfiguration(query);
|
||||
|
||||
public TValue? GetConfiguration<TConfiguration, TValue>(Func<TConfiguration, TValue?> query) where TConfiguration : SkinConfiguration where TValue : struct => CurrentSkin.Value.GetConfiguration(query);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user