// Input-State: Tastatur, Maus-Look (Edge-Flags fuer Klicks). export class Input { constructor(domElement) { this.el = domElement; this.keys = new Set(); this.mouseDX = 0; this.mouseDY = 0; this.leftClick = false; // Edge (diese Frame) this.rightClick = false; // Edge (diese Frame) this.locked = false; window.addEventListener('keydown', (e) => { this.keys.add(e.code); if (e.code === 'Space') e.preventDefault(); }); window.addEventListener('keyup', (e) => this.keys.delete(e.code)); document.addEventListener('pointerlockchange', () => { this.locked = document.pointerLockElement === this.el; }); this.el.addEventListener('mousedown', (e) => { if (!this.locked) return; if (e.button === 0) this.leftClick = true; if (e.button === 2) this.rightClick = true; }); this.el.addEventListener('contextmenu', (e) => e.preventDefault()); document.addEventListener('mousemove', (e) => { if (!this.locked) return; this.mouseDX += e.movementX || 0; this.mouseDY += e.movementY || 0; }); } requestLock() { this.el.requestPointerLock(); } // Am Ende jedes Frames aufrufen. endFrame() { this.mouseDX = 0; this.mouseDY = 0; this.leftClick = false; this.rightClick = false; } down(code) { return this.keys.has(code); } }