Files

131 lines
5.7 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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')
}
// ---------- shared/petState:统计计数器
patch('shared/petState.ts', [
[
' jobsDone: number\n}',
' jobsDone: number\n /** 使用/任务次数统计,key 形如 use:bread / job:wash */\n counters: Record<string, number>\n}'
],
[' jobsDone: 0\n }', ' jobsDone: 0,\n counters: {}\n }'],
[
' save.jobsDone += 1\n save.job = null',
' save.jobsDone += 1\n save.counters[`job:${job.id}`] = (save.counters[`job:${job.id}`] ?? 0) + 1\n save.job = null'
]
])
// ---------- stateStore:使用次数
patch('main/stateStore.ts', [
[
" case 'use':\n result = useItem(this.save, String(payload))\n break",
" case 'use': {\n const id = String(payload)\n result = useItem(this.save, id)\n if (result.ok) this.save.counters[`use:${id}`] = (this.save.counters[`use:${id}`] ?? 0) + 1\n break\n }"
]
])
// ---------- main:对话条随菜单显隐 + 居中 + 睡觉反馈
patch('main/index.ts', [
[
" chatBar.once('ready-to-show', () => chatBar?.showInactive())",
" chatBar.once('ready-to-show', () => {\n if (menuWindow?.isVisible()) chatBar?.showInactive()\n })"
],
[
' x: Math.round(b.x + b.width / 2 - 185),',
' x: Math.round(b.x + b.width / 2 - 165),'
],
[
'function showMenu(): void {\n createMenuWindow()\n positionMenu()\n menuWindow?.show()\n menuWindow?.focus()\n}',
'function showMenu(): void {\n createMenuWindow()\n positionMenu()\n menuWindow?.show()\n menuWindow?.focus()\n positionChatBar()\n chatBar?.showInactive()\n}'
],
[
'function hideMenu(): void {\n menuWindow?.hide()\n}',
'function hideMenu(): void {\n menuWindow?.hide()\n chatBar?.hide()\n}'
],
[
" ipcMain.handle('pet:action', (_e, name: string, payload?: unknown) => store.action(String(name), payload))",
" ipcMain.handle('pet:action', (_e, name: string, payload?: unknown) => {\n const result = store.action(String(name), payload)\n if (String(name) === 'sleep' && result.ok) {\n const asleep = store.snapshot().sleeping\n say(asleep ? '(钻进被窝)我眯一会儿……晚安 (。-ω-)zzz' : '(揉眼睛)唔…我醒了,刚才好像梦到电子飞来飞去', 6000)\n }\n return result\n })"
]
])
// ---------- Menu:化学化标签
patch('renderer/src/menu/Menu.tsx', [
["{ label: '吃饭', tab: 'shop', arg: 'meal' }", "{ label: '固体制剂', tab: 'shop', arg: 'meal' }"],
["{ label: '喝水', tab: 'shop', arg: 'drink' }", "{ label: '液体制剂', tab: 'shop', arg: 'drink' }"],
["{ label: '耗材', tab: 'shop', arg: 'drug' }", "{ label: '提纯耗材', tab: 'shop', arg: 'drug' }"],
["{ label: '礼品', tab: 'shop', arg: 'gift' }", "{ label: '纪念样本', tab: 'shop', arg: 'gift' }"]
])
// ---------- Panel:详细 = 统计
patch('renderer/src/panel/Panel.tsx', [
[
` {detail && (
<div className="detail-table">
{ORDER.map((key) => (
<div className="detail-line" key={key}>
<span>{STAT_META[key].label}</span>
<span className="muted">
{state.stats[key].toFixed(2)} / 100
</span>
<span className="muted">
{(tickRates(state.stats)[key] * 60).toFixed(2)}/min
</span>
</div>
))}
<div className="detail-line">
<span>累计任务</span>
<span className="muted">{state.jobsDone} 次</span>
<span className="muted">倍率 ×{mult.toFixed(2)}</span>
</div>
</div>
)}`,
` {detail && (
<div className="detail-table">
<div className="detail-line detail-head">
<span>记录</span>
<span className="muted">次数</span>
</div>
{Object.entries(state.counters ?? {})
.sort((a, b) => b[1] - a[1])
.slice(0, 12)
.map(([key, count]) => {
const [kind, id] = key.split(':')
const name =
kind === 'use'
? ITEMS.find((i) => i.id === id)?.name ?? id
: JOBS.find((j) => j.id === id)?.name ?? id
return (
<div className="detail-line" key={key}>
<span>
{kind === 'use' ? '使用 · ' : '完成 · '}
{name}
</span>
<span className="muted">{count}</span>
</div>
)
})}
{(Object.keys(state.counters ?? {}).length === 0) && (
<div className="detail-line">
<span className="muted">还没有记录,去用点东西或做点任务吧</span>
</div>
)}
<div className="detail-line detail-head">
<span>累计任务</span>
<span className="muted">{state.jobsDone} 次 · 倍率 ×{mult.toFixed(2)}</span>
</div>
</div>
)}`
]
])
console.log('patched')