import {game} from "../../game/game.js"; import * as net from "../../net/netcode.js"; import { canvas } from "../../display/html.js" class Cursor { constructor(){ this.x = 0 this.y = 0 this.xold = 0 this.yold = 0 } } export var cursor = new Cursor(); canvas.addEventListener('mousemove', e => { mouseMoved(e) }); canvas.addEventListener("mousedown", e => { getMousePosition(e); }); function mouseMoved(event) { const tileSize = game.tileSize const x = Math.floor(event.offsetX/tileSize) const y = Math.floor(event.offsetY/tileSize) if (cursor.xold != x || cursor.yold != y) { cursor.x = x cursor.y = y // renderHud(x, y) cursor.xold = x cursor.yold = y } } function getMousePosition(event) { const tileSize = game.tileSize // Get mouse position on canvas const rect = canvas.getBoundingClientRect(); const mouseX = event.clientX - rect.left; const mouseY = event.clientY - rect.top; // scale mouse coordinates to canvas coordinates const xu = Math.floor((mouseX * canvas.width / canvas.clientWidth)/tileSize); const yu = Math.floor((mouseY * canvas.height / canvas.clientHeight)/tileSize); const button = event.button console.log("Click!") console.log(xu,yu) net.clickCanvas({tilePosition: [xu,yu], mode: button}) }