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

Merge pull request #5 from EmeraldBlock/EmeraldBlock-patch-1

use safeModulo
This commit is contained in:
EmeraldBlock 2020-10-08 20:18:53 -05:00 committed by GitHub
commit 024866d5b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 10 deletions

View File

@ -1,6 +1,6 @@
import { gMetaBuildingRegistry } from "../../../core/global_registries";
import { Signal, STOP_PROPAGATION } from "../../../core/signal";
import { makeDiv } from "../../../core/utils";
import { makeDiv, safeModulo } from "../../../core/utils";
import { KEYMAPPINGS } from "../../key_action_mapper";
import { MetaBuilding } from "../../meta_building";
import { GameRoot } from "../../root";
@ -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) {

View File

@ -3,6 +3,7 @@ import { gMetaBuildingRegistry } from "../../../core/global_registries";
import { Signal, STOP_PROPAGATION } from "../../../core/signal";
import { TrackedState } from "../../../core/tracked_state";
import { Vector } from "../../../core/vector";
import { safeModulo } from "../../../core/utils";
import { enumMouseButton } from "../../camera";
import { StaticMapEntityComponent } from "../../components/static_map_entity";
import { Entity } from "../../entity";
@ -471,10 +472,7 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart {
.pressed
? -1
: 1;
let newIndex = (index + direction) % availableVariants.length;
if (newIndex < 0) {
newIndex += availableVariants.length;
}
let newIndex = safeModulo(index + direction, availableVariants.length);
const newVariant = availableVariants[newIndex];
this.setVariant(newVariant);
}