创始人指令:游戏要有日志,读日志诊断运行时问题,模板+可选插件自带日志。 日志基建: - plugin.js:受控面 ctx 加 log(tag,...args) → window.__gameLog 环形(800)+ console;用受控 time.nowMs。 - boot-game-host.js:B2 插件 Proxy wrap 顺手记插件语义调用进 __gameLog(跳 draw/update/current/get 等高频)→ 插件自带日志免逐个改;recHook 仍记 __engineCalls 供 F_wiring。 - _template game-logic.js:ctx.log 生命周期(init/scene play/over)→ 模板自带。 - play.mjs smokeBoot:抓 __gameLog 写 staged evidence/game-log.json + 末12条进 out.logTail(boot 成败都抓,失败时最有诊断价值)。 - 实证:scaffold→smoke logtest → logCount:165、game-log.json 有 [p:sceneFsm:define/start]+[game:init];读日志诊断可用。 九门对齐(C 之 A+B2,recon ad3c564): - A(SaaGenNodes validateAmodelStaged):amodel 路 validate-ok→play 短路了 scaffoldNode(唯一写 play-spec.json 处)→ 补写 play-spec.json(从 design 产 K_PLAY_SPEC)→ 九门可驱动(治 E_live/G_input/H_progress 机制)。 - B2(boot-game-host):插件 recHook wrap → F_wiring callCount>0(实证 e2e 从 [E_live,F_wiring] → [E_live,H_progress],F_wiring 已过)。叠加式,factory/gamedef 零回归。 预算(gen.mjs):maxSteps 45→70 / maxWallMs 12→20min —— SAA design 富化 brief 比 raw(7步)需更多步。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
_template — A-model 游戏克隆起点(3 层架构)
一个可玩的最小游戏「点圆得分」(menu→play→over)。克隆它、只改 src/game-logic.js(按需拆 core.js/render.js),改成 brief 要的游戏。别从零搭骨架,在 game-logic.js 起点上改最省事。
3 层 + 你只碰 L3
| 层 | 文件 | 你 |
|---|---|---|
| L1 固定 plumbing(write 会被拒) | index.html · entry-bundle.js · src/host-config.js(已注入全 11 插件 + viewport 390×844 + wiring) · src/game.js(薄 wrapper:摊平 opts.runtime → 交 game-logic) |
不碰 |
| L3 你写的游戏本体 | src/game-logic.js(必写) · src/core.js(推荐:纯逻辑,可内联) · src/render.js(推荐:画面) · src/balance.js(可选:数值) · src/assets.js(可选:资产) |
只写这些 |
入口契约(钉死)
// src/game-logic.js —— 你写这个
export function createGame({ plugins, bundle, viewport }) {
// 插件已扁平注入(全 11 件,用到才解构):
const { sceneFsm, sessionScore, hudUi, timerScheduler } = plugins;
// 可用键:sceneFsm sessionScore hudUi timerScheduler save gamefeel juice palettePost audioMusic collision physics
return {
async init(boot) { const ctx = boot.ctx; /* 装资产→订阅 ctx.getInput→定义场景→start */ },
update(dt) { bundle.tick(dt); /* ★必调;再推进玩法 */ },
render(g) { /* 画在 g;读 viewport.w/h */ },
destroy() {},
// 可选·建议:_forensicsView(){ return { state(){…}, measures(){…} }; }
};
}
铁律(check 会拦)
- 入参扁平
{plugins, bundle, viewport}—— 没有 opts、没有 opts.runtime、没有 ctx(L1 已摊平)。受控面 ctx 只在init(boot).boot.ctx(时间/随机/输入/引擎)。 - 插件直接
const {…} = plugins—— 别写opts.runtime.plugins(L1 内部的,你见不到)。游戏只用、不 new、不 register。 update(dt)必调bundle.tick(dt)—— 否则 timer-scheduler/gamefeel 等 onFrame 不推进、timer 永不到期、一局不结束。- 零引擎 import(引擎经
boot.ctx.getEngine());游戏源零裸 Math.random/Date.now/setTimeout/new AudioContext/addEventListener —— 时间随机经 boot.ctx,定时经 timer-scheduler,音效经 plugins.audioMusic,输入经 ctx.getInput。 - 插件方法名一律以
src/plugins/<name>/api.d.ts为准,别臆测(scene-fsm 是define不是 defineScenes;particles-juice 没有burst)。 - 画面读
viewport.w/h,别硬编码 390×844。
你写什么 vs 调什么
- 你写(玩法身份):规则/胜负/计分逻辑(core)、画面与命中区(render)、数值(balance)、资产声明(assets)、把它们接到五法(game-logic)。
- 你调(通用机制):计分
sessionScore· 场景机sceneFsm· UI 原语hudUi· 受控定时timerScheduler· 持久save· 手感gamefeel· 粒子juice· 后处理palettePost· 音频audioMusic· 碰撞/物理collision/physics(全已注入,用到才取)。 - 手感:全局氛围(palettePost/gamefeel)自动生效;事件特效(命中/死亡/过关)在事件点调 juice/gamefeel 事件 API(方法名以 api.d.ts 为准)。
详见 .agents/skills/littlejs-game-dev.md(12 插件 API 速查 + ❌→✅ 易犯错)。