Make CycleBuildings select last used item when empty

This commit is contained in:
Dimava 2020-05-27 15:58:33 +03:00
parent eb87550b36
commit 6a5d1a0890
1 changed files with 2 additions and 2 deletions

View File

@ -110,8 +110,8 @@ export class HUDBuildingsToolbar extends BaseHUDPart {
cycleBuildings() { cycleBuildings() {
let newIndex = this.lastSelectedIndex; let newIndex = this.lastSelectedIndex;
for (let i = 0; i < toolbarBuildings.length; ++i) { for (let i = 0; i < toolbarBuildings.length; ++i, ++newIndex) {
newIndex = (newIndex + 1) % toolbarBuildings.length; newIndex %= toolbarBuildings.length;
const metaBuilding = gMetaBuildingRegistry.findByClass(toolbarBuildings[newIndex]); const metaBuilding = gMetaBuildingRegistry.findByClass(toolbarBuildings[newIndex]);
const handle = this.buildingHandles[metaBuilding.id]; const handle = this.buildingHandles[metaBuilding.id];
if (!handle.selected && handle.unlocked) { if (!handle.selected && handle.unlocked) {