1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2025-06-13 13:04:03 +00:00

Cycle to previous building when nothing selected

This allows to quickly select previous building with the
cycle keybinding after placing a building (and removing the selection), instead of always jump to the next one.
This commit is contained in:
Lukáš Doležal 2020-12-26 21:49:28 +00:00
parent 83fa1f23ee
commit 40b94aeb5d

View File

@ -150,6 +150,10 @@ export class HUDBaseToolbar extends BaseHUDPart {
} }
} }
isBuildingSelected() {
return Object.entries(this.buildingHandles).some(([_, handle]) => handle.selected)
}
/** /**
* Cycles through all buildings * Cycles through all buildings
*/ */
@ -161,6 +165,7 @@ export class HUDBaseToolbar extends BaseHUDPart {
let newBuildingFound = false; let newBuildingFound = false;
let newIndex = this.lastSelectedIndex; let newIndex = this.lastSelectedIndex;
if (this.isBuildingSelected()) {
const direction = this.root.keyMapper.getBinding(KEYMAPPINGS.placement.rotateInverseModifier).pressed const direction = this.root.keyMapper.getBinding(KEYMAPPINGS.placement.rotateInverseModifier).pressed
? -1 ? -1
: 1; : 1;
@ -177,6 +182,8 @@ export class HUDBaseToolbar extends BaseHUDPart {
if (!newBuildingFound) { if (!newBuildingFound) {
return; return;
} }
}
const metaBuildingClass = this.primaryBuildings[newIndex]; const metaBuildingClass = this.primaryBuildings[newIndex];
const metaBuilding = gMetaBuildingRegistry.findByClass(metaBuildingClass); const metaBuilding = gMetaBuildingRegistry.findByClass(metaBuildingClass);
this.selectBuildingForPlacement(metaBuilding); this.selectBuildingForPlacement(metaBuilding);