Files

346 lines
12 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')
}
// ---- 配置:文本风格开关(不绑定存档)
patch('shared/petState.ts', [
[
` /** 当前角色存档 id */
profile: string`,
` /** 当前角色存档 id */
profile: string
/** 文本风格:auto 跟随皮肤,chemistry 强制化学,normal 强制普通 */
flavorMode: 'auto' | 'chemistry' | 'normal'`
],
[
` currentSkin: 'xiaona',
profile: '',`,
` currentSkin: 'xiaona',
profile: '',
flavorMode: 'auto',`
]
])
// ---- main:currentFlavor 尊重 flavorMode;面板尺寸 16:10
patch('main/index.ts', [
[
`function currentFlavor(): string {
try {
const root = userSkins()
const m = JSON.parse(
fs.readFileSync(path.join(root, store.getConfig().currentSkin || 'xiaona', 'skin.json'), 'utf8')
)
return m.flavor === 'normal' ? 'normal' : 'chemistry'
} catch {
return 'chemistry'
}
}`,
`function currentFlavor(): string {
const mode = store.getConfig().flavorMode || 'auto'
if (mode === 'chemistry') return 'chemistry'
if (mode === 'normal') return 'normal'
try {
const root = userSkins()
const m = JSON.parse(
fs.readFileSync(path.join(root, store.getConfig().currentSkin || 'xiaona', 'skin.json'), 'utf8')
)
return m.flavor === 'normal' ? 'normal' : 'chemistry'
} catch {
return 'chemistry'
}
}`
],
[
` panelWindow = new BrowserWindow({
width: 400,
height: 540,`,
` panelWindow = new BrowserWindow({
width: 640,
height: 430,`
]
])
// ---- Panel:ChipsRow、重命名行内编辑、风格开关、普通风味残留文本、普通等级显示
patch('renderer/src/panel/Panel.tsx', [
// ChipsRow 组件
[
`const PHOTO_CATS = ['默认', '表情', '纪念']`,
`const PHOTO_CATS = ['默认', '表情', '纪念']
function ChipsRow({ children }: { children: React.ReactNode }): React.ReactElement {
const ref = React.useRef<HTMLDivElement>(null)
const [more, setMore] = React.useState(false)
React.useEffect(() => {
const el = ref.current
if (!el) return
const check = (): void => setMore(el.scrollWidth > el.clientWidth + 4)
check()
window.addEventListener('resize', check)
return () => window.removeEventListener('resize', check)
})
return (
<div className="chips-row">
<div className="chips" ref={ref}>
{children}
</div>
{more && (
<button
className="chip-more"
onClick={() => ref.current?.scrollBy({ left: 130, behavior: 'smooth' })}
>
›
</button>
)}
</div>
)
}`
],
// 重命名状态
[
" const [newSkin, setNewSkin] = useState('xiaona')",
" const [newSkin, setNewSkin] = useState('xiaona')\n const [renamePid, setRenamePid] = useState('')\n const [renameSkinId, setRenameSkinId] = useState('')\n const [renameText, setRenameText] = useState('')"
],
// 面板打开时重新检查 chips(ChipsRow effect 无 deps 但每次渲染重跑,够用)
// 换三处 chips 包裹
[
` <div className="chips">
{(['all', 'meal', 'drink', 'drug', 'gear', 'book', 'gift'] as const).map((c) => (
<button
key={c}
className={\`chip \${cat === c ? 'on' : ''}\`}
onClick={() => setCat(c)}
>
{c === 'all' ? '全部' : catLabel(c)}
</button>
))}
</div>`,
` <ChipsRow>
{(['all', 'meal', 'drink', 'drug', 'gear', 'book', 'gift'] as const).map((c) => (
<button
key={c}
className={\`chip \${cat === c ? 'on' : ''}\`}
onClick={() => setCat(c)}
>
{c === 'all' ? '全部' : catLabel(c)}
</button>
))}
</ChipsRow>`
],
[
` {(['all', 'meal', 'drink', 'drug', 'gear', 'book', 'gift'] as const).map((c) => (
<button
key={c}
className={\`chip \${cat === c ? 'on' : ''}\`}
onClick={() => setCat(c)}
>
{c === 'all' ? '全部' : catLabel(c)}
</button>
))}
</div>
{(() => {`,
` {(['all', 'meal', 'drink', 'drug', 'gear', 'book', 'gift'] as const).map((c) => (
<button
key={c}
className={\`chip \${cat === c ? 'on' : ''}\`}
onClick={() => setCat(c)}
>
{c === 'all' ? '全部' : catLabel(c)}
</button>
))}
</ChipsRow>
{(() => {`
],
// 照片分类 chips
[
` <div className="chips">
{['全部', '默认', '表情', '纪念'].map((catName) => (`,
` <ChipsRow>
{['全部', '默认', '表情', '纪念'].map((catName) => (`
],
[
` {catName}
</button>
))}
</div>
{(() => {`,
` {catName}
</button>
))}
</ChipsRow>
{(() => {`
],
// 投喂页 chips 也在内:feed tab 有一个(feed 页的第一个 chips 已在上面对上)
// 存档重命名行内编辑
[
` <button
className="mini"
onClick={() => {
const n = window.prompt('新的存档名', p.name || p.id)
if (n) void api()?.renameProfile(p.id, n).then(setProfiles)
}}
>
重命名
</button>`,
` {renamePid === p.id ? (
<>
<input
className="text-input rename-input"
value={renameText}
onChange={(e) => setRenameText(e.target.value)}
/>
<button
className="mini"
onClick={() => {
if (renameText.trim()) void api()?.renameProfile(p.id, renameText).then(setProfiles)
setRenamePid('')
}}
>
确定
</button>
<button className="mini" onClick={() => setRenamePid('')}>
取消
</button>
</>
) : (
<button
className="mini"
onClick={() => {
setRenamePid(p.id)
setRenameText(p.name || p.id)
}}
>
重命名
</button>
)}`
],
// 皮肤重命名行内编辑
[
` <button
className="mini"
onClick={() => {
const n = window.prompt('新的角色名', s.name)
if (n) void api()?.renameSkin(s.id, n).then(setSkins)
}}
>
重命名
</button>`,
` {renameSkinId === s.id ? (
<>
<input
className="text-input rename-input"
value={renameText}
onChange={(e) => setRenameText(e.target.value)}
/>
<button
className="mini"
onClick={() => {
if (renameText.trim()) void api()?.renameSkin(s.id, renameText).then(setSkins)
setRenameSkinId('')
}}
>
确定
</button>
<button className="mini" onClick={() => setRenameSkinId('')}>
取消
</button>
</>
) : (
<button
className="mini"
onClick={() => {
setRenameSkinId(s.id)
setRenameText(s.name)
}}
>
重命名
</button>
)}`
],
// 文本风格开关(设置里,放角色分区之前)
[
` <div className="section-title" id="sec-profile">角色存档</div>`,
` <div className="field">
<span>文本风格</span>
<select
className="text-input"
value={cfg.flavorMode}
onChange={(e) =>
void patchConfig({ flavorMode: e.target.value as 'auto' | 'chemistry' | 'normal' })
}
>
<option value="auto">自动(跟随角色)</option>
<option value="chemistry">化学风格</option>
<option value="normal">普通桌宠风格</option>
</select>
</div>
<p className="tips">不再与存档强制绑定,随时可切;下次聊天也会用对应人设。</p>
<div className="section-title" id="sec-profile">角色存档</div>`
],
// applyFlavor 结合 flavorMode
[
` const applyFlavor = (cfg2: { currentSkin?: string }): void => {
const id = cfg2.currentSkin || 'xiaona'
void fetch('pet://skins/' + id + '/skin.json')
.then((r) => (r.ok ? r.json() : null))
.then((m) => setFlavor(m && m.flavor === 'normal' ? 'normal' : 'chemistry'))
.catch(() => setFlavor('chemistry'))
}`,
` const applyFlavor = (cfg2: { currentSkin?: string; flavorMode?: string }): void => {
const mode = cfg2.flavorMode || 'auto'
if (mode === 'chemistry') {
setFlavor('chemistry')
return
}
if (mode === 'normal') {
setFlavor('normal')
return
}
const id = cfg2.currentSkin || 'xiaona'
void fetch('pet://skins/' + id + '/skin.json')
.then((r) => (r.ok ? r.json() : null))
.then((m) => setFlavor(m && m.flavor === 'normal' ? 'normal' : 'chemistry'))
.catch(() => setFlavor('chemistry'))
}`
],
// 普通风味:睡觉注释 / 去商店 / 等级显示
[
` <span className="action-meta">{state.sleeping ? '把她叫起来' : '电子回充中'}</span>`,
` <span className="action-meta">
{state.sleeping ? '把她叫起来' : flavor === 'normal' ? '恢复精力中' : '电子回充中'}
</span>`
],
[
` <button className="action" onClick={() => setTab('shop')}>
<span className="action-label">去试剂店</span>
<span className="action-meta">补充试剂</span>
</button>`,
` <button className="action" onClick={() => setTab('shop')}>
<span className="action-label">{flavor === 'normal' ? '去商店' : '去试剂店'}</span>
<span className="action-meta">{flavor === 'normal' ? '补充食物' : '补充试剂'}</span>
</button>`
],
[
` {state.name} <ElementBadge level={level} />`,
` {state.name}{' '}
{flavor === 'normal' ? (
<span className="panel-lv-normal">Lv.{level}</span>
) : (
<ElementBadge level={level} />
)}`
]
])
console.log('panel p27 patched')