Skip to content

Commit

Permalink
Remove keyboard controls
Browse files Browse the repository at this point in the history
  • Loading branch information
Zikoat committed Aug 3, 2024
1 parent dcd3032 commit 706cdb8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 82 deletions.
76 changes: 2 additions & 74 deletions src/Controls.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,8 @@
import {
Cursor,
ScreenPos,
// WorldCoord,
// worldCoordToCellCoord,
WorldPos,
} from "./Cursor";
// import { CHUNK_SIZE } from "./Chunk";
// import { Field } from "./Field";
import { Cursor, ScreenPos, WorldPos } from "./Cursor";
import * as PIXI from "pixi.js";
// import { FieldPersistence } from "./FieldPersistence";
// import { scale } from "./CellSprite";
import { zoom } from "d3-zoom";
import {
// BaseType,
select,
} from "d3-selection";
import { select } from "d3-selection";
import { z } from "zod";
// import { SCALE } from "./CellSprite";
import { Field } from "./Field";
import { FieldPersistence } from "./FieldPersistence";
import { assert } from "./assert";
Expand Down Expand Up @@ -56,8 +42,6 @@ export class Controls {
// Controls.addMouseControls(rootObject);
Controls.setupZoom(rootObject);
// Controls.addTouchControls(rootObject);
// Controls.addKeyboardControls();
// Controls.removeUIEventBubbling();
Controls.disableRightClickContextMenu();
}

Expand All @@ -78,62 +62,6 @@ export class Controls {
// // .on("touchendoutside", Controls._onDragEnd);
// }

// private static addKeyboardControls() {
// window.addEventListener(
// "keydown",
// (event) => {
// Controls.mouseInput = false;

// const move = (deltaX: number, deltaY: number) => {
// Controls.moveViewTo(
// Controls.cursor.getX() + deltaX,
// Controls.cursor.getY() + deltaY,
// );
// Controls.cursor.move(deltaX, deltaY);
// // disable mouse cursor
// (
// document.getElementsByTagName("BODY")[0] as HTMLElement
// ).style.cursor = "none";
// };
// switch (event.keyCode) {
// case 88:
// Controls.open();
// break;
// case 90:
// Controls.flag();
// break;
// case 37:
// move(-1, 0);
// break;
// case 38:
// move(0, -1);
// break;
// case 40:
// move(0, 1);
// break;
// case 39:
// move(1, 0);
// break;
// }
// },
// false,
// );
// }

// todo is this still needed?
// private static removeUIEventBubbling() {
// const uiElements = document.getElementsByClassName("ui");
// for (const element of uiElements) {
// element.addEventListener(
// "click",
// (event) => {
// event.stopPropagation();
// },
// false,
// );
// }
// }

private static disableRightClickContextMenu() {
document.addEventListener("contextmenu", (event) => event.preventDefault());
}
Expand Down
13 changes: 5 additions & 8 deletions src/Cursor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as PIXI from "pixi.js";
import { CELL_WIDTH } from "./CellSprite";
import { getTextures } from "./Textures";
import type { Tagged } from "type-fest";
import { assert } from "./assert";

// todo move these to a different file
type Pos<T> = { x: T; y: T };
Expand Down Expand Up @@ -43,20 +44,16 @@ export class Cursor extends PIXI.Sprite {
this.cellCoordX = worldCoordToCellCoord(x);
this.cellCoordY = worldCoordToCellCoord(y);

const snappedWorldCoordX = cellCoordToWorldCoord(this.cellCoordX);
const snappedWorldCoordY = cellCoordToWorldCoord(this.cellCoordY);
assert(this.cellCoordX % 1 === 0);
assert(this.cellCoordY % 1 === 0);

TweenMax.to(this, 0.1, {
x: snappedWorldCoordX,
y: snappedWorldCoordY,
x: cellCoordToWorldCoord(this.cellCoordX),
y: cellCoordToWorldCoord(this.cellCoordY),
ease: Power4.easeOut,
});
}

// private moveDelta(dx: CellCoord, dy: CellCoord) {
// this.moveTo(add(this.pointX, dx), add(this.pointY, dy));
// }

public getX() {
return this.cellCoordX;
}
Expand Down

0 comments on commit 706cdb8

Please sign in to comment.