From 914b1382a24ed987f65a539e704e04e81cdd852e Mon Sep 17 00:00:00 2001 From: Ethan Moffat Date: Mon, 18 Apr 2022 16:46:23 -0700 Subject: [PATCH] Ensure spell inventory uses preferred slot from config file if it exists --- EndlessClient/HUD/Panels/ActiveSpellsPanel.cs | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/EndlessClient/HUD/Panels/ActiveSpellsPanel.cs b/EndlessClient/HUD/Panels/ActiveSpellsPanel.cs index 0af262d7a..32b322712 100644 --- a/EndlessClient/HUD/Panels/ActiveSpellsPanel.cs +++ b/EndlessClient/HUD/Panels/ActiveSpellsPanel.cs @@ -219,7 +219,7 @@ protected override void OnUpdateControl(GameTime gameTime) var actualSlot = preferredSlot.Match( some: x => { - return _childItems.Any(ci => ci.Slot == x) + return _childItems.OfType().Any(ci => ci.Slot == x) ? GetNextOpenSlot(_childItems) : Option.Some(x); }, @@ -520,21 +520,21 @@ protected override void Dispose(bool disposing) if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && !File.Exists(Constants.SpellsFile)) { - using var inventoryKey = TryGetCharacterRegistryKey(accountName, characterName); - if (inventoryKey != null) + using var spellsKey = TryGetCharacterRegistryKey(accountName, characterName); + if (spellsKey != null) { - for (int i = 0; i < SpellRowLength * 4; ++i) + for (int i = 0; i < SpellRowLength * SpellRows; ++i) { - if (int.TryParse(inventoryKey.GetValue($"item{i}")?.ToString() ?? string.Empty, out var id)) + if (int.TryParse(spellsKey.GetValue($"item{i}")?.ToString() ?? string.Empty, out var id)) map[i] = id; } } } - var inventory = new IniReader(Constants.SpellsFile); - if (inventory.Load() && inventory.Sections.ContainsKey(accountName)) + var spells = new IniReader(Constants.SpellsFile); + if (spells.Load() && spells.Sections.ContainsKey(accountName)) { - var section = inventory.Sections[accountName]; + var section = spells.Sections[accountName]; foreach (var key in section.Keys.Where(x => x.Contains(characterName, StringComparison.OrdinalIgnoreCase))) { if (!key.Contains(".")) @@ -574,22 +574,22 @@ private static RegistryKey TryGetCharacterRegistryKey(string accountName, string private void SaveSpellsFile(object sender, EventArgs e) { - var inventory = new IniReader(Constants.SpellsFile); + var spells = new IniReader(Constants.SpellsFile); - var section = inventory.Load() && inventory.Sections.ContainsKey(_playerInfoProvider.LoggedInAccountName) - ? inventory.Sections[_playerInfoProvider.LoggedInAccountName] + var section = spells.Load() && spells.Sections.ContainsKey(_playerInfoProvider.LoggedInAccountName) + ? spells.Sections[_playerInfoProvider.LoggedInAccountName] : new SortedList(); var existing = section.Where(x => x.Key.Contains(_characterProvider.MainCharacter.Name)).Select(x => x.Key).ToList(); foreach (var key in existing) section.Remove(key); - foreach (var item in _childItems) + foreach (var item in _childItems.OfType()) section[$"{_characterProvider.MainCharacter.Name}.{item.Slot}"] = $"{item.InventorySpell.ID}"; - inventory.Sections[_playerInfoProvider.LoggedInAccountName] = section; + spells.Sections[_playerInfoProvider.LoggedInAccountName] = section; - inventory.Save(); + spells.Save(); } #endregion