Merge pull request #24 from Dimava/master

Make CycleBuildings work properly
This commit is contained in:
tobspr 2020-05-27 15:24:37 +02:00 committed by GitHub
commit 1db5d4f7cb
1 changed files with 9 additions and 1 deletions

View File

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