mirror of
https://github.com/xmanrui/OpenClaw-bot-review.git
synced 2026-07-30 03:12:14 +00:00
- Add layout editor with floor/wall paint, erase, furniture place/move/rotate/delete tools - Add editor state management (undo/redo, selection, drag, ghost preview) - Add EditorToolbar and EditActionBar UI components - Add layout persistence API (GET/POST to ~/.openclaw/pixel-office/layout.json) - Add notification sound system (Web Audio API ascending chime on agent completion) - Add sub-agent visualization via session JSONL parsing - Fix agent activity API to read from agents.list config and correct session paths - Add agent name labels above character sprites in canvas renderer - Add i18n translations for editor features (zh/en)
39 lines
837 B
TypeScript
39 lines
837 B
TypeScript
import { MAX_DELTA_TIME_SEC } from '../constants'
|
|
|
|
export interface GameLoopCallbacks {
|
|
update: (dt: number) => void
|
|
render: (ctx: CanvasRenderingContext2D) => void
|
|
}
|
|
|
|
export function startGameLoop(
|
|
canvas: HTMLCanvasElement,
|
|
callbacks: GameLoopCallbacks,
|
|
): () => void {
|
|
const ctx = canvas.getContext('2d')!
|
|
ctx.imageSmoothingEnabled = false
|
|
|
|
let lastTime = 0
|
|
let rafId = 0
|
|
let stopped = false
|
|
|
|
const frame = (time: number) => {
|
|
if (stopped) return
|
|
const dt = lastTime === 0 ? 0 : Math.min((time - lastTime) / 1000, MAX_DELTA_TIME_SEC)
|
|
lastTime = time
|
|
|
|
callbacks.update(dt)
|
|
|
|
ctx.imageSmoothingEnabled = false
|
|
callbacks.render(ctx)
|
|
|
|
rafId = requestAnimationFrame(frame)
|
|
}
|
|
|
|
rafId = requestAnimationFrame(frame)
|
|
|
|
return () => {
|
|
stopped = true
|
|
cancelAnimationFrame(rafId)
|
|
}
|
|
}
|