Files
SodiumPet/tools/patch-p25-d.cjs
T

251 lines
9.5 KiB
JavaScript
Raw 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')
}
patch('renderer/src/panel/Panel.tsx', [
// 导入普通名映射
[
"import { FLAVOR_HINTS, FLAVOR_LABELS, type Flavor } from '../../../shared/flavor'",
"import {\n FLAVOR_HINTS,\n FLAVOR_LABELS,\n NORMAL_CAT_LABELS,\n NORMAL_ITEM_NAMES,\n NORMAL_JOB_NAMES,\n type Flavor\n} from '../../../shared/flavor'"
],
// effectText 按风味
[
`function effectText(item: Item): string {
return Object.entries(item.effects)
.map(([k, v]) => \`\${EFFECT_LABEL[k] ?? k} \${v > 0 ? '+' : ''}\${v}\`)
.join(' · ')
}`,
`function effectText(item: Item, flavor: Flavor): string {
return Object.entries(item.effects)
.map(([k, v]) => {
const label = FLAVOR_LABELS[flavor][k as StatKey] ?? k
return \`\${label} \${v > 0 ? '+' : ''}\${v}\`
})
.join(' · ')
}`
],
// 组件内风味助手
[
` const level = useMemo(() => (state ? levelOf(state.exp) : 1), [state])`,
` const level = useMemo(() => (state ? levelOf(state.exp) : 1), [state])
const itemName = (i: Item): string => (flavor === 'normal' ? (NORMAL_ITEM_NAMES[i.id] ?? i.name) : i.name)
const jobName = (id: string): string => (flavor === 'normal' ? (NORMAL_JOB_NAMES[id] ?? id) : id)
const catLabel = (c: ItemCategory): string =>
flavor === 'normal' ? NORMAL_CAT_LABELS[c] : CATEGORY_LABEL[c]
function statusLine(): string {
if (flavor === 'normal') {
if (job) return '工作中 · ' + jobName(job.id)
const s = state.stats
if (s.electron < 20) return '有点累了'
if (s.oxidation > 70) return '想洗个澡了'
if (s.satiety < 20) return '肚子饿了'
if (s.paraffin < 20) return '有点渴'
if (s.mood > 75) return '心情不错'
return '一切正常'
}
return statusText(state.stats, job)
}`
],
// 头部状态
[
` <span>{statusText(state.stats, job)}</span>`,
` <span>{statusLine()}</span>`
],
// 投喂卡
[
` <div className="card-name">
{item.name} <span className="count">×{state.inventory[item.id]}</span>
</div>
<div className="card-effect">{effectText(item)}</div>
<div className="card-foot">
<span className="price">{CATEGORY_LABEL[item.category]}</span>`,
` <div className="card-name">
{itemName(item)} <span className="count">×{state.inventory[item.id]}</span>
</div>
<div className="card-effect">{effectText(item, flavor)}</div>
<div className="card-foot">
<span className="price">{catLabel(item.category)}</span>`
],
// 商店卡
[
` <div className="card" key={item.id}>
<div className="card-name">{item.name}</div>
<div className="card-effect">{effectText(item)}</div>`,
` <div className="card" key={item.id}>
<div className="card-name">{itemName(item)}</div>
<div className="card-effect">{effectText(item, flavor)}</div>`
],
// 分类 chips(两处)
[
` {c === 'all' ? '全部' : CATEGORY_LABEL[c]}`,
` {c === 'all' ? '全部' : catLabel(c)}`
],
[
` {c === 'all' ? '全部' : CATEGORY_LABEL[c]}`,
` {c === 'all' ? '全部' : catLabel(c)}`
],
// 互动任务名(下拉与卡片)
[
` {JOBS.filter((j) => j.kind === kind).map((j) => (
<option key={j.id} value={j.id}>
{j.name}
{level < j.level ? \`(需 Lv.\${j.level})\` : ''}
</option>
))}`,
` {JOBS.filter((j) => j.kind === kind).map((j) => (
<option key={j.id} value={j.id}>
{jobName(j.id)}
{level < j.level ? \`(需 Lv.\${j.level})\` : ''}
</option>
))}`
],
[
` const active = JOBS.find((j) => j.id === taskId && j.kind === kind) ?? JOBS.find((j) => j.kind === kind)`,
` const active = JOBS.find((j) => j.id === taskId && j.kind === kind) ?? JOBS.find((j) => j.kind === kind)`
],
[
` <div className="task-card">`,
` <div className="task-card">`
],
// 进行中任务名
[
` <span>进行中 · {job.name}</span>`,
` <span>进行中 · {jobName(job.id)}</span>`
],
// TABS 标签按风味
[
` {t.label}
</button>
))}
</nav>`,
` {t.id === 'shop' && flavor === 'normal' ? '商店' : t.label}
</button>
))}
</nav>`
],
// 创建存档表单:名字 + 皮肤选择
[
` <div className="picker">
<input
className="text-input"
value={newProfile}
placeholder="新存档名"
onChange={(e) => setNewProfile(e.target.value)}
/>
<button
className="mini"
onClick={() => {
if (!newProfile.trim()) return
void api()?.createProfile(newProfile).then(setProfiles)
setNewProfile('')
}}
>
新建
</button>
</div>`,
` <div className="new-profile">
<input
className="text-input"
value={newProfile}
placeholder="新存档名"
onChange={(e) => setNewProfile(e.target.value)}
/>
<select
className="text-input"
value={newSkin}
onChange={(e) => setNewSkin(e.target.value)}
>
{skins.map((s) => (
<option key={s.id} value={s.id}>
{s.name}
</option>
))}
</select>
<button
className="mini"
onClick={() => {
if (!newProfile.trim()) return
void api()?.createProfile(newProfile, newSkin).then(setProfiles)
setNewProfile('')
}}
>
新建
</button>
</div>
<p className="tips">
新建时会锁定人物立绘与文本风格:预设化拟角色用化学风格,导入角色用普通桌宠风格。
</p>`
],
// newSkin 状态
[
" const [newProfile, setNewProfile] = useState('')",
" const [newProfile, setNewProfile] = useState('')\n const [newSkin, setNewSkin] = useState('xiaona')"
],
// 存档行:显示名字 + 重命名
[
` <div className="row-main">
<div className="row-title">
{p.id}
{p.active && <span className="count">(当前)</span>}
</div>
<div className="row-sub">{p.level}</div>
</div>`,
` <div className="row-main">
<div className="row-title">
{p.name || p.id}
{p.active && <span className="count">(当前)</span>}
</div>
<div className="row-sub">{p.level}</div>
</div>
<button
className="mini"
onClick={() => {
const n = window.prompt('新的存档名', p.name || p.id)
if (n) void api()?.renameProfile(p.id, n).then(setProfiles)
}}
>
重命名
</button>`
],
// 皮肤行:重命名
[
` <button
className="mini"
disabled={s.active}
onClick={() => void api()?.switchSkin(s.id).then(setSkins)}
>
切换
</button>`,
` <button
className="mini"
disabled={s.active}
onClick={() => void api()?.switchSkin(s.id).then(setSkins)}
>
切换
</button>
<button
className="mini"
onClick={() => {
const n = window.prompt('新的角色名', s.name)
if (n) void api()?.renameSkin(s.id, n).then(setSkins)
}}
>
重命名
</button>`
]
])
console.log('panel flavor names patched')