diff --git a/IGP/Pages/BuildCalculator/Parts/HotkeyViewerComponent.razor b/IGP/Pages/BuildCalculator/Parts/HotkeyViewerComponent.razor index bd4a3a1..3ebea29 100644 --- a/IGP/Pages/BuildCalculator/Parts/HotkeyViewerComponent.razor +++ b/IGP/Pages/BuildCalculator/Parts/HotkeyViewerComponent.razor @@ -343,34 +343,32 @@ { var hotkey = KeyService.GetHotkey(); - if (hotkey == "") - { + if(hotkey is "`") + HandleCancelEntity(); + + if (EntityFromKey(hotkey, out var entity)) return; - } - if (hotkey == "`") - { - BuildOrderService.RemoveLast(); + if (BuildOrderService.Add(entity!, EconomyService)) EconomyService.Calculate(BuildOrderService, TimingService, BuildOrderService.GetLastRequestInterval()); - return; - } + } + + private void HandleCancelEntity() + { + BuildOrderService.RemoveLast(); + EconomyService.Calculate(BuildOrderService, TimingService, BuildOrderService.GetLastRequestInterval()); + } + private bool EntityFromKey(string? hotkey, out EntityModel? entity) + { var hotkeyGroup = KeyService.GetHotkeyGroup(); var isHoldSpace = KeyService.IsHoldingSpace(); var faction = FilterService.GetFaction(); var immortal = FilterService.GetImmortal(); - var entity = EntityModel.GetFrom(hotkey!, hotkeyGroup, isHoldSpace, faction, immortal); + entity = EntityModel.GetFrom(hotkey!, hotkeyGroup, isHoldSpace, faction, immortal); - if (entity == null) - { - return; - } - - if (BuildOrderService.Add(entity, EconomyService)) - { - EconomyService.Calculate(BuildOrderService, TimingService, BuildOrderService.GetLastRequestInterval()); - } + return entity == null; } private void ButtonClicked(MouseEventArgs mouseEventArgs, HotkeyModel hotkey)