const fs = require('fs') const base = 'C:/Users/ASUS/Documents/deepseek-harness/default-workspace/desktop-pet/src/' // ---- 1) lookAt:限幅锥形跟随 + 复位用 focusController { const p = base + 'renderer/src/pet/adapters/live2d.ts' let c = fs.readFileSync(p, 'utf8') c = c.replace( ` lookAt(x: number, y: number): void { try { if (x < 0 || y < 0) { // 复位:看向画布中央(正前方) this.model?.focus(this.baseSize.w / 2, this.baseSize.h / 2) return } this.model?.focus(x, y) } catch { /* 某些模型没有视线参数,忽略 */ } }`, ` lookAt(x: number, y: number): void { try { if (x < 0 || y < 0) { // 复位:直接把 FocusController 归零(正视前方) const fc = this.model?.internalModel?.focusController if (fc && typeof fc.focus === 'function') { fc.focus(0, 0, true) } return } // 以脸的位置为中心,把目标限制在一个锥形范围内,鼠标很远时也不会锁死 const s = this.model.scale.x || 1 const cx = this.model.x + (this.baseSize.w / 2) * s const cy = this.model.y + (this.baseSize.h * 0.45) * s let dx = x - cx let dy = y - cy const dist = Math.hypot(dx, dy) const R = 260 if (dist > R) { dx = (dx / dist) * R dy = (dy / dist) * R } this.model?.focus(cx + dx, cy + dy) } catch { /* 某些模型没有视线参数,忽略 */ } }` ) fs.writeFileSync(p, c, 'utf8') } // ---- 2) App boot:先取配置再加载皮肤(修复切换皮肤重载循环) { const p = base + 'renderer/src/App.tsx' let c = fs.readFileSync(p, 'utf8') c = c.replace( ` async function boot(): Promise { try { const skinId = cfgRef.current.currentSkin || 'xiaona'`, ` async function boot(): Promise { try { const a = api() const latest = (await a?.getConfig()) ?? cfgRef.current cfgRef.current = latest setCfg(latest) const skinId = latest.currentSkin || 'xiaona'` ) fs.writeFileSync(p, c, 'utf8') } console.log('lookAt + boot patched')