Files
SodiumPet/tools/patch-rich3.cjs

129 lines
3.9 KiB
JavaScript

const fs = require('fs')
const base = 'C:/Users/ASUS/Documents/deepseek-harness/default-workspace/desktop-pet/src/'
function patch(file, pairs) {
const p = base + file
let c = fs.readFileSync(p, 'utf8')
for (const [from, to] of pairs) {
if (!c.includes(from)) {
console.log('MISS in', file, '::', from.slice(0, 70).replace(/\n/g, '\\n'))
continue
}
c = c.replace(from, to)
}
fs.writeFileSync(p, c, 'utf8')
}
// ---- 适配器接口 + Live2D 视线跟随
patch('renderer/src/pet/types.ts', [
[
` /** 预留:情绪驱动(后续接状态条) */
setMood?(mood: string): void`,
` /** 预留:情绪驱动(后续接状态条) */
setMood?(mood: string): void
/** Live2D:视线看向画布内某点(CSS 坐标,相对画布左上角) */
lookAt?(x: number, y: number): void`
]
])
patch('renderer/src/pet/adapters/live2d.ts', [
[
` setMood(mood: string): void {
this.expression(mood)
}`,
` setMood(mood: string): void {
this.expression(mood)
}
lookAt(x: number, y: number): void {
try {
this.model?.focus(x, y)
} catch {
/* 某些模型没有视线参数,忽略 */
}
}`
]
])
// ---- App:指针移动时驱动视线
patch('renderer/src/App.tsx', [
[
` if (Math.abs(e.clientX - d.sx) > TAP_SLOP || Math.abs(e.clientY - d.sy) > TAP_SLOP) {
d.moved = true
document.getElementById('root')?.classList.add('dragging')
}
}`,
` if (Math.abs(e.clientX - d.sx) > TAP_SLOP || Math.abs(e.clientY - d.sy) > TAP_SLOP) {
d.moved = true
document.getElementById('root')?.classList.add('dragging')
}
if (cfg.eyeFollow) {
adapterRef.current?.lookAt?.(e.clientX + cfg.cropLeft, e.clientY + cfg.cropTop)
}
}`
]
])
// ---- preload / api:资料窗口与每日系统
patch('preload/index.ts', [
[
" importPhotos: () => Promise<PhotoMeta[]>",
" importPhotos: () => Promise<PhotoMeta[]>\n openStorage: () => void\n getDailySpecial: () => Promise<{ itemId: string; price: number; day: string; name: string; origin: number; claimed: boolean }>\n claimDailyGift: () => Promise<ActionResult>\n buyDailySpecial: () => Promise<ActionResult>"
],
[
" importPhotos: () => ipcRenderer.invoke('pet:photos:import'),",
" importPhotos: () => ipcRenderer.invoke('pet:photos:import'),\n openStorage: () => ipcRenderer.send('pet:storage:open'),\n getDailySpecial: () => ipcRenderer.invoke('pet:daily:special'),\n claimDailyGift: () => ipcRenderer.invoke('pet:daily:gift'),\n buyDailySpecial: () => ipcRenderer.invoke('pet:daily:buy'),"
]
])
patch('renderer/src/api.ts', [
[
" importPhotos: () => Promise<PhotoMeta[]>",
" importPhotos: () => Promise<PhotoMeta[]>\n openStorage: () => void\n getDailySpecial: () => Promise<{ itemId: string; price: number; day: string; name: string; origin: number; claimed: boolean }>\n claimDailyGift: () => Promise<ActionResult>\n buyDailySpecial: () => Promise<ActionResult>"
]
])
// ---- Menu:面板子菜单加「资料库」
patch('renderer/src/menu/Menu.tsx', [
[
`interface SubItem {
label: string
tab?: string
arg?: string
action?: 'sleep'
}`,
`interface SubItem {
label: string
tab?: string
arg?: string
action?: 'sleep' | 'storage'
}`
],
[
` panel: [
{ label: '状态', tab: 'panel' },
{ label: '详细', tab: 'detail' },
{ label: '任务', tab: 'interact' }
],`,
` panel: [
{ label: '状态', tab: 'panel' },
{ label: '详细', tab: 'detail' },
{ label: '任务', tab: 'interact' },
{ label: '资料库', action: 'storage' }
],`
],
[
` if (item.action === 'sleep') {
void api()?.action('sleep')
return
}`,
` if (item.action === 'sleep') {
void api()?.action('sleep')
return
}
if (item.action === 'storage') {
api()?.openStorage()
return
}`
]
])
console.log('renderer rich patched')