更新饥荒

This commit is contained in:
2026-10-11 09:09:28 +08:00
parent d87ad60492
commit 3af4bc6b52
53 changed files with 12434 additions and 2733 deletions

View File

@@ -585,6 +585,7 @@ function mkCG(o = {}) {
calls,
me: () => o.me || players[0] || null,
rand: (a) => a,
isLand: () => true,
findLand: (x, y) => (o.findLand ? o.findLand(x, y) : { x, y }),
moveToward: (m, x, y) => { m.x = x; m.y = y; m.moving = true },
damageMob: (m, dmg) => { calls.damageMob.push([m, dmg]); m.hp -= dmg },
@@ -604,10 +605,15 @@ function mkCG(o = {}) {
return g
}
// 假 2D 上下文:任意方法可调,measureText 返回带 width 的对象(供 labor clipText 用)
// 渐变/图案方法返回可链式调用的 stub(守卫等新绘制用 createLinearGradient)
const makeCtx2 = () => new Proxy({}, {
get: (t, k) => {
if (k in t) return t[k]
if (k === 'measureText') return () => ({ width: 12 })
if (k === 'createLinearGradient' || k === 'createRadialGradient' || k === 'createConicGradient') {
return () => ({ addColorStop: () => {} })
}
if (k === 'createPattern') return () => ({})
return () => {}
},
set: (t, k, v) => { t[k] = v; return true },
@@ -636,7 +642,9 @@ console.log('== A. 世界缩放(configureWorld)==')
configureWorld(0.1)
ok(GW === 32 && GH === 24, `0.1 夹到下限 0.5 → 32/24 (${GW}/${GH})`)
configureWorld(3)
ok(GW === 128 && GH === 96, `3 夹到上限 2 → 128/96 (${GW}/${GH})`)
ok(GW === 192 && GH === 144, `3 倍不再夹断 → 192/144 (${GW}/${GH})`)
configureWorld(6)
ok(GW === 256 && GH === 192, `6 夹到上限 4 → 256/192 (${GW}/${GH})`)
let e0 = null
try { configureWorld(0) } catch (e) { e0 = e.message }
ok(e0 === null && GW === 64 && GH === 48, `configureWorld(0) 不崩且回落默认 (${GW}/${GH})`)
@@ -724,7 +732,8 @@ const campHooks = (name) => hookFn(rt, name, 'camp')
const ents = g.calls.addEntity.map((c) => c[0])
ok(ents.includes('camphouse'), 'onWorldGen 放出 camphouse')
ok(g.calls.spawnMob.some((s) => s[0] === 'guard'), 'onWorldGen 生成守卫')
ok(g.calls.addFire.length === 1 && g.calls.addFire[0].eternal === true, 'onWorldGen 放出 eternal 火焰')
ok(g.calls.addFire.length >= 1, `onWorldGen 放出长明篝火(火环 ${g.calls.addFire.length} 个)`)
ok(g.calls.addFire.every((f2) => f2.eternal === true), '全部篝火均为 eternal')
const f = g.calls.addFire[0]
ok(f.pit === true && f.ttl === 150 && f.max === 150, `长明篝火 pit/ttl/max 正确 (${f && f.pit}/${f && f.ttl}/${f && f.max})`)
}
@@ -1272,13 +1281,14 @@ console.log('== 核心钩子契约(防回归)==')
ok(bad.length === 0, `核心钩子全部传 gCtx (${bad.length ? '缺: ' + bad.join(',') : hookCalls + ' 处'})`)
// 3) mod 侧每个钩子的首参必须是 g(位置契约一致)
// 注意:onPick 是 zoneUtil 菜单动作回调(不是 gCtx 钩子),排除
const modFiles = fs.readdirSync(url('./src/games/starve/mods'))
.filter((f) => f.endsWith('.js') && f !== 'index.js' && f !== 'registry.js')
const badSig = []
let hookDefs = 0
for (const f of modFiles) {
const src = fs.readFileSync(url('./src/games/starve/mods/' + f), 'utf8')
for (const m of src.matchAll(/^\s{4}(on[A-Z][A-Za-z]*)\(([^)]*)\)/gm)) {
for (const m of src.matchAll(/^\s{4}(on(?!Pick\b)[A-Z][A-Za-z]*)\(([^)]*)\)/gm)) {
hookDefs++
const first = (m[2].split(',')[0] || '').trim()
if (first !== 'g') badSig.push(`${f}:${m[1]}(${m[2]})`)