Moved SkinProvidingContainer bindable fetching to common method. Replaced redundant test boolean declarations with inline values.

This commit is contained in:
Mysfit
2021-01-13 16:05:46 -05:00
parent 1248d39d7e
commit 8b95817f7a
2 changed files with 25 additions and 27 deletions

View File

@ -36,41 +36,41 @@ namespace osu.Game.Rulesets.Osu.Tests
config.BindWith(OsuSetting.BeatmapColours, beatmapColours); config.BindWith(OsuSetting.BeatmapColours, beatmapColours);
} }
[TestCase(true, true, true)] [TestCase(true, true)]
[TestCase(true, false, true)] [TestCase(true, false)]
[TestCase(false, true, true)] [TestCase(false, true)]
[TestCase(false, false, true)] [TestCase(false, false)]
public void TestBeatmapComboColours(bool userHasCustomColours, bool useBeatmapSkin, bool useBeatmapColour) public void TestBeatmapComboColours(bool userHasCustomColours, bool useBeatmapSkin)
{ {
ExposedPlayer player = null; ExposedPlayer player = null;
configureSettings(useBeatmapSkin, useBeatmapColour); configureSettings(useBeatmapSkin, true);
AddStep("load coloured beatmap", () => player = loadBeatmap(userHasCustomColours, true)); AddStep("load coloured beatmap", () => player = loadBeatmap(userHasCustomColours, true));
AddUntilStep("wait for player", () => player.IsLoaded); AddUntilStep("wait for player", () => player.IsLoaded);
AddAssert("is beatmap skin colours", () => player.UsableComboColours.SequenceEqual(TestBeatmapSkin.Colours)); AddAssert("is beatmap skin colours", () => player.UsableComboColours.SequenceEqual(TestBeatmapSkin.Colours));
} }
[TestCase(true, false)] [TestCase(true)]
[TestCase(false, false)] [TestCase(false)]
public void TestBeatmapComboColoursOverride(bool useBeatmapSkin, bool useBeatmapColour) public void TestBeatmapComboColoursOverride(bool useBeatmapSkin)
{ {
ExposedPlayer player = null; ExposedPlayer player = null;
configureSettings(useBeatmapSkin, useBeatmapColour); configureSettings(useBeatmapSkin, false);
AddStep("load coloured beatmap", () => player = loadBeatmap(true, true)); AddStep("load coloured beatmap", () => player = loadBeatmap(true, true));
AddUntilStep("wait for player", () => player.IsLoaded); AddUntilStep("wait for player", () => player.IsLoaded);
AddAssert("is user custom skin colours", () => player.UsableComboColours.SequenceEqual(TestSkin.Colours)); AddAssert("is user custom skin colours", () => player.UsableComboColours.SequenceEqual(TestSkin.Colours));
} }
[TestCase(true, false)] [TestCase(true)]
[TestCase(false, false)] [TestCase(false)]
public void TestBeatmapComboColoursOverrideWithDefaultColours(bool useBeatmapSkin, bool useBeatmapColour) public void TestBeatmapComboColoursOverrideWithDefaultColours(bool useBeatmapSkin)
{ {
ExposedPlayer player = null; ExposedPlayer player = null;
configureSettings(useBeatmapSkin, useBeatmapColour); configureSettings(useBeatmapSkin, false);
AddStep("load coloured beatmap", () => player = loadBeatmap(false, true)); AddStep("load coloured beatmap", () => player = loadBeatmap(false, true));
AddUntilStep("wait for player", () => player.IsLoaded); AddUntilStep("wait for player", () => player.IsLoaded);

View File

@ -80,30 +80,28 @@ namespace osu.Game.Skinning
switch (global) switch (global)
{ {
case GlobalSkinColours.ComboColours: case GlobalSkinColours.ComboColours:
var bindable = skin.GetConfig<TLookup, TValue>(lookup); return getBindable<TLookup, TValue>(lookup, AllowColourLookup);
if (bindable != null && AllowColourLookup)
return bindable;
else
return fallbackSource?.GetConfig<TLookup, TValue>(lookup);
} }
break; break;
default: default:
if (AllowConfigurationLookup) return getBindable<TLookup, TValue>(lookup, AllowConfigurationLookup);
{
var bindable = skin.GetConfig<TLookup, TValue>(lookup);
if (bindable != null)
return bindable;
}
break;
} }
} }
return fallbackSource?.GetConfig<TLookup, TValue>(lookup); return fallbackSource?.GetConfig<TLookup, TValue>(lookup);
} }
private IBindable<TValue> getBindable<TLookup, TValue>(TLookup lookup, bool bindableReturnCheck)
{
var bindable = skin.GetConfig<TLookup, TValue>(lookup);
if (bindable != null && bindableReturnCheck)
return bindable;
else
return fallbackSource?.GetConfig<TLookup, TValue>(lookup);
}
protected virtual void TriggerSourceChanged() => SourceChanged?.Invoke(); protected virtual void TriggerSourceChanged() => SourceChanged?.Invoke();
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)