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

use safeModulo

This commit is contained in:
EmeraldBlock 2020-10-08 20:12:34 -05:00 committed by GitHub
parent f4fa25d339
commit 4141c939d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -164,11 +164,8 @@ export class HUDBaseToolbar extends BaseHUDPart {
? -1
: 1;
let newIndex = this.lastSelectedIndex;
for (let i = 0; i < this.primaryBuildings.length; ++i, newIndex += direction) {
newIndex %= this.primaryBuildings.length;
if (newIndex < 0) {
newIndex += this.primaryBuildings.length;
}
for (let i = 0; i < this.primaryBuildings.length; ++i) {
newIndex = safeModulo(newIndex + direction, this.primaryBuildings.length);
const metaBuilding = gMetaBuildingRegistry.findByClass(this.primaryBuildings[newIndex]);
const handle = this.buildingHandles[metaBuilding.id];
if (!handle.selected && handle.unlocked) {