mirror of
https://github.com/tobspr/shapez.io.git
synced 2025-12-16 11:41:50 +00:00
added inverse cycling for buildings and variants
This commit is contained in:
parent
a2ee16589f
commit
81ce894103
@ -381,7 +381,7 @@ export class HUDBuildingPlacer extends BaseHUDPart {
|
||||
index >= 0,
|
||||
"Current variant was invalid: " + this.currentVariant.get() + " out of " + availableVariants
|
||||
);
|
||||
const newIndex = (index + 1) % availableVariants.length;
|
||||
const newIndex = this.calculateNewVariantCycleIndex(index, availableVariants.length);
|
||||
const newVariant = availableVariants[newIndex];
|
||||
this.currentVariant.set(newVariant);
|
||||
|
||||
@ -389,6 +389,28 @@ export class HUDBuildingPlacer extends BaseHUDPart {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {number} index the current variant index
|
||||
* @param {number} availableVariantsLength the number of available variants
|
||||
* @returns {number} index for next variant
|
||||
*/
|
||||
calculateNewVariantCycleIndex(index, availableVariantsLength) {
|
||||
let indexModifier = 0;
|
||||
if (
|
||||
this.root.keyMapper.getBinding(KEYMAPPINGS.placementModifiers.cycleInverse).isCurrentlyPressed()
|
||||
) {
|
||||
if (index - 1 < 0) indexModifier = availableVariantsLength - 1;
|
||||
else indexModifier -= 1;
|
||||
} else {
|
||||
indexModifier += 1;
|
||||
}
|
||||
|
||||
console.log(indexModifier);
|
||||
console.log(index);
|
||||
return (index + indexModifier) % availableVariantsLength;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to rotate
|
||||
*/
|
||||
|
||||
@ -109,13 +109,24 @@ export class HUDBuildingsToolbar extends BaseHUDPart {
|
||||
}
|
||||
|
||||
cycleBuildings() {
|
||||
const actionMapper = this.root.keyMapper;
|
||||
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;
|
||||
|
||||
if (actionMapper.getBinding(KEYMAPPINGS.placementModifiers.cycleInverse).isCurrentlyPressed()) {
|
||||
for (let i = 0; i < toolbarBuildings.length; --i, --newIndex) {
|
||||
if (newIndex < 0) newIndex = newIndex + toolbarBuildings.length;
|
||||
newIndex %= toolbarBuildings.length;
|
||||
|
||||
if (this.isCycledBuildingSelectable(newIndex)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (let i = 0; i < toolbarBuildings.length; ++i, ++newIndex) {
|
||||
newIndex %= toolbarBuildings.length;
|
||||
if (this.isCycledBuildingSelectable(newIndex)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
const metaBuildingClass = toolbarBuildings[newIndex];
|
||||
@ -123,6 +134,16 @@ export class HUDBuildingsToolbar extends BaseHUDPart {
|
||||
this.selectBuildingForPlacement(metaBuilding);
|
||||
}
|
||||
|
||||
isCycledBuildingSelectable(toolbarIndex) {
|
||||
const metaBuilding = gMetaBuildingRegistry.findByClass(toolbarBuildings[toolbarIndex]);
|
||||
const handle = this.buildingHandles[metaBuilding.id];
|
||||
if (!handle.selected && handle.unlocked) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {MetaBuilding} metaBuilding
|
||||
*/
|
||||
|
||||
@ -72,6 +72,7 @@ export const KEYMAPPINGS = {
|
||||
placementDisableAutoOrientation: { keyCode: 17 }, // CTRL
|
||||
placeMultiple: { keyCode: 16 }, // SHIFT
|
||||
placeInverse: { keyCode: 18 }, // ALT
|
||||
cycleInverse: { keyCode: 16 }, // SHIFT
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user