fix cycle building bug

This commit is contained in:
isaisstillalive 2020-06-30 22:26:30 +09:00
parent 30509be6b7
commit ada63459aa
1 changed files with 10 additions and 0 deletions

View File

@ -103,15 +103,25 @@ export class HUDBaseToolbar extends BaseHUDPart {
* Cycles through all buildings * Cycles through all buildings
*/ */
cycleBuildings() { cycleBuildings() {
const visible = this.visibilityCondition();
if (!visible) {
return;
}
let process = false;
let newIndex = this.lastSelectedIndex; let newIndex = this.lastSelectedIndex;
for (let i = 0; i < this.supportedBuildings.length; ++i, ++newIndex) { for (let i = 0; i < this.supportedBuildings.length; ++i, ++newIndex) {
newIndex %= this.supportedBuildings.length; newIndex %= this.supportedBuildings.length;
const metaBuilding = gMetaBuildingRegistry.findByClass(this.supportedBuildings[newIndex]); const metaBuilding = gMetaBuildingRegistry.findByClass(this.supportedBuildings[newIndex]);
const handle = this.buildingHandles[metaBuilding.id]; const handle = this.buildingHandles[metaBuilding.id];
if (!handle.selected && handle.unlocked) { if (!handle.selected && handle.unlocked) {
process = true;
break; break;
} }
} }
if (!process) {
return;
}
const metaBuildingClass = this.supportedBuildings[newIndex]; const metaBuildingClass = this.supportedBuildings[newIndex];
const metaBuilding = gMetaBuildingRegistry.findByClass(metaBuildingClass); const metaBuilding = gMetaBuildingRegistry.findByClass(metaBuildingClass);
this.selectBuildingForPlacement(metaBuilding); this.selectBuildingForPlacement(metaBuilding);