From 68778674674e7f50598ba9e39d780417eff8a09f Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 29 Nov 2021 17:48:44 +0900 Subject: [PATCH] Make default fallback logic more robust --- .../Overlays/Settings/Sections/SkinSection.cs | 22 +++++-------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/osu.Game/Overlays/Settings/Sections/SkinSection.cs b/osu.Game/Overlays/Settings/Sections/SkinSection.cs index bf0f6bf142..4de5d455fe 100644 --- a/osu.Game/Overlays/Settings/Sections/SkinSection.cs +++ b/osu.Game/Overlays/Settings/Sections/SkinSection.cs @@ -96,11 +96,9 @@ namespace osu.Game.Overlays.Settings.Sections updateItems(); - // Todo: This should not be necessary when OsuConfigManager is databased - if (!Guid.TryParse(configBindable.Value, out var configId) || skinDropdown.Items.All(s => s.ID != configId)) - configBindable.Value = string.Empty; + configBindable.BindValueChanged(id => Scheduler.AddOnce(updateSelectedSkinFromConfig)); + updateSelectedSkinFromConfig(); - configBindable.BindValueChanged(id => Scheduler.AddOnce(updateSelectedSkinFromConfig), true); dropdownBindable.BindValueChanged(skin => { if (skin.NewValue.Equals(random_skin_info)) @@ -124,20 +122,12 @@ namespace osu.Game.Overlays.Settings.Sections private void updateSelectedSkinFromConfig() { - if (!Guid.TryParse(configBindable.Value, out var configId)) return; + ILive skin = null; - var skin = skinDropdown.Items.FirstOrDefault(s => s.ID == configId); + if (Guid.TryParse(configBindable.Value, out var configId)) + skin = skinDropdown.Items.FirstOrDefault(s => s.ID == configId); - // TODO: i don't think this will be required any more. - if (skin == null) - { - // there may be a thread race condition where an item is selected that hasn't yet been added to the dropdown. - // to avoid adding complexity, let's just ensure the item is added so we can perform the selection. - skin = skins.Query(s => s.ID == configId); - updateItems(); - } - - dropdownBindable.Value = skin; + dropdownBindable.Value = skin ?? skinDropdown.Items.First(); } private void updateItems()