aboutsummaryrefslogtreecommitdiff
path: root/static/src/mouse_controller.ts
diff options
context:
space:
mode:
authorElizabeth Hunt <elizabeth@simponic.xyz>2024-09-07 20:20:07 -0700
committerElizabeth Hunt <elizabeth@simponic.xyz>2024-09-12 17:23:30 -0700
commit8ec7f5368232d59f344e1067e1bad5e48dbcb7ae (patch)
tree1ad2df4dc00773f2307d1525cc80ac7410ea8fba /static/src/mouse_controller.ts
parente4e31978bae7e45be57b376415a4b925ac8cbc03 (diff)
downloadkennel.hatecomputers.club-8ec7f5368232d59f344e1067e1bad5e48dbcb7ae.tar.gz
kennel.hatecomputers.club-8ec7f5368232d59f344e1067e1bad5e48dbcb7ae.zip
get "cats" up there
Diffstat (limited to 'static/src/mouse_controller.ts')
-rw-r--r--static/src/mouse_controller.ts47
1 files changed, 0 insertions, 47 deletions
diff --git a/static/src/mouse_controller.ts b/static/src/mouse_controller.ts
deleted file mode 100644
index bd8d51a..0000000
--- a/static/src/mouse_controller.ts
+++ /dev/null
@@ -1,47 +0,0 @@
-import { Vec2 } from "./vector";
-export class MouseController {
- private last_event_time = Date.now();
- private last_movement: Vec2 | undefined;
- private interval_id: number | undefined;
-
- constructor(
- private readonly publisher: (new_movement: Vec2) => void | Promise<void>,
- private readonly debounce_ms = 200,
- ) {}
-
- public start() {
- if (typeof this.interval_id !== "undefined") {
- return;
- }
- this.interval_id = setInterval(
- () => this.publish_movement(),
- this.debounce_ms,
- );
- }
-
- public stop() {
- if (this.interval_id === null) {
- return;
- }
- clearInterval(this.interval_id);
- delete this.interval_id;
- }
-
- public move(x: number, y: number) {
- this.last_movement = new Vec2(x, y);
- this.publish_movement();
- }
-
- private publish_movement() {
- if (
- Date.now() - this.last_event_time < this.debounce_ms ||
- typeof this.last_movement === "undefined"
- ) {
- return;
- }
-
- this.last_event_time = Date.now();
- this.publisher(this.last_movement.copy());
- delete this.last_movement;
- }
-}