74 lines
2.2 KiB
JavaScript
74 lines
2.2 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')
|
||
}
|
||
|
||
// tick 里检查成就(例如在线时长、等级)
|
||
patch('main/stateStore.ts', [
|
||
[
|
||
` applyElapsed(this.save, dt, now)
|
||
this.save.lastTick = now
|
||
this.emit()`,
|
||
` applyElapsed(this.save, dt, now)
|
||
this.save.lastTick = now
|
||
this.checkAchievements()
|
||
this.emit()`
|
||
]
|
||
])
|
||
|
||
// main:成就播报 + 生日 IPC + 拍照计数
|
||
patch('main/index.ts', [
|
||
[
|
||
` bindStoreBroadcast()
|
||
store.start()`,
|
||
` bindStoreBroadcast()
|
||
store.onAchievement((a) => {
|
||
say('(举起小牌子)解锁成就:' + a.title + '!', 6000)
|
||
})
|
||
store.start()`
|
||
],
|
||
[
|
||
` ipcMain.handle('pet:daily:gift', () => store.claimDaily())`,
|
||
` ipcMain.handle('pet:daily:gift', () => store.claimDaily())
|
||
ipcMain.handle('pet:birthday:set', (_e, day: string) => store.setBirthday(String(day)))`
|
||
],
|
||
[
|
||
` media.addPhoto(name)
|
||
broadcastMedia()`,
|
||
` media.addPhoto(name)
|
||
store['save'].counters['photo:capture'] = (store['save'].counters['photo:capture'] ?? 0) + 1
|
||
store.checkAchievements()
|
||
broadcastMedia()`
|
||
]
|
||
])
|
||
|
||
// preload/api:生日
|
||
patch('preload/index.ts', [
|
||
[
|
||
" claimDailyGift: () => Promise<ActionResult>",
|
||
" claimDailyGift: () => Promise<ActionResult>\n setBirthday: (day: string) => Promise<ActionResult>"
|
||
],
|
||
[
|
||
" claimDailyGift: () => ipcRenderer.invoke('pet:daily:gift'),",
|
||
" claimDailyGift: () => ipcRenderer.invoke('pet:daily:gift'),\n setBirthday: (day: string) => ipcRenderer.invoke('pet:birthday:set', day),"
|
||
]
|
||
])
|
||
patch('renderer/src/api.ts', [
|
||
[
|
||
" claimDailyGift: () => Promise<ActionResult>",
|
||
" claimDailyGift: () => Promise<ActionResult>\n setBirthday: (day: string) => Promise<ActionResult>"
|
||
]
|
||
])
|
||
|
||
console.log('achievement hook + birthday + photo counter patched')
|