Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/excaliburjs/sample-excalitris. excaliburjs.com/sample-excalitris
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556import type { Engine } from 'excalibur';
type UiHandlers = { start?: () => void; restart?: () => void; move: (dx: number, dy: number) => void; rotate: () => void; hardDrop: () => void;};
// Centralizes mapping of UI events (buttons, title/restart actions)// to game actions. Gameplay actions are gated by `active` while// start/restart always pass through.export class UiController { private active = false;
constructor(engine: Engine, private handlers: UiHandlers) { engine.on('ui:action', (evt: any) => { const type = evt?.type as string | undefined; if (!type) return;
// Start/Restart should always be allowed if (type === 'start') { this.handlers.start?.(); return; } if (type === 'restart') { this.handlers.restart?.(); return; }
// Gameplay inputs: respect active gate if (!this.active) return;
switch (type) { case 'left': this.handlers.move(-1, 0); break; case 'right': this.handlers.move(1, 0); break; case 'rotate': this.handlers.rotate(); break; case 'drop': this.handlers.hardDrop(); break; } }); }
public setActive(active: boolean): void { this.active = active; }}