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:
parent
4141c939d6
commit
39e360cc5b
@ -3,6 +3,7 @@ import { gMetaBuildingRegistry } from "../../../core/global_registries";
|
|||||||
import { Signal, STOP_PROPAGATION } from "../../../core/signal";
|
import { Signal, STOP_PROPAGATION } from "../../../core/signal";
|
||||||
import { TrackedState } from "../../../core/tracked_state";
|
import { TrackedState } from "../../../core/tracked_state";
|
||||||
import { Vector } from "../../../core/vector";
|
import { Vector } from "../../../core/vector";
|
||||||
|
import { safeModulo } from "../../../core/utils";
|
||||||
import { enumMouseButton } from "../../camera";
|
import { enumMouseButton } from "../../camera";
|
||||||
import { StaticMapEntityComponent } from "../../components/static_map_entity";
|
import { StaticMapEntityComponent } from "../../components/static_map_entity";
|
||||||
import { Entity } from "../../entity";
|
import { Entity } from "../../entity";
|
||||||
@ -471,10 +472,7 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart {
|
|||||||
.pressed
|
.pressed
|
||||||
? -1
|
? -1
|
||||||
: 1;
|
: 1;
|
||||||
let newIndex = (index + direction) % availableVariants.length;
|
let newIndex = safeModulo(index + direction, availableVariants.length);
|
||||||
if (newIndex < 0) {
|
|
||||||
newIndex += availableVariants.length;
|
|
||||||
}
|
|
||||||
const newVariant = availableVariants[newIndex];
|
const newVariant = availableVariants[newIndex];
|
||||||
this.setVariant(newVariant);
|
this.setVariant(newVariant);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user