191 lines
8.4 KiB
JavaScript
191 lines
8.4 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')
|
|
}
|
|
|
|
// ---- preload / api
|
|
patch('preload/index.ts', [
|
|
[
|
|
" getProfiles: () => Promise<Array<{ id: string; active: boolean }>>",
|
|
" getProfiles: () => Promise<Array<{ id: string; active: boolean; level: string }>>\n delProfile: (id: string) => Promise<Array<{ id: string; active: boolean; level: string }>>\n onLook: (cb: (p: { x: number; y: number }) => void) => () => void\n onSkins: (cb: (list: Array<{ id: string; name: string; active: boolean }>) => void) => () => void"
|
|
],
|
|
[
|
|
" switchProfile: (id: string) => ipcRenderer.invoke('pet:profiles:switch', id),",
|
|
" switchProfile: (id: string) => ipcRenderer.invoke('pet:profiles:switch', id),\n delProfile: (id: string) => ipcRenderer.invoke('pet:profiles:del', id),\n onLook: (cb: (p: { x: number; y: number }) => void) => {\n const l = (_e: unknown, p: { x: number; y: number }): void => cb(p)\n ipcRenderer.on('pet:look', l)\n return () => ipcRenderer.removeListener('pet:look', l)\n },\n onSkins: (cb: (list: Array<{ id: string; name: string; active: boolean }>) => void) => {\n const l = (_e: unknown, list: Array<{ id: string; name: string; active: boolean }>): void => cb(list)\n ipcRenderer.on('pet:skins:update', l)\n return () => ipcRenderer.removeListener('pet:skins:update', l)\n },"
|
|
]
|
|
])
|
|
patch('renderer/src/api.ts', [
|
|
[
|
|
" getProfiles: () => Promise<Array<{ id: string; active: boolean }>>",
|
|
" getProfiles: () => Promise<Array<{ id: string; active: boolean; level: string }>>\n delProfile: (id: string) => Promise<Array<{ id: string; active: boolean; level: string }>>\n onLook: (cb: (p: { x: number; y: number }) => void) => () => void\n onSkins: (cb: (list: Array<{ id: string; name: string; active: boolean }>) => void) => () => void"
|
|
]
|
|
])
|
|
|
|
// ---- App:全屏视线 + 复位改正前方
|
|
patch('renderer/src/App.tsx', [
|
|
[
|
|
" const offMotion = a?.onMotion((name) => {\n void adapterRef.current?.play(name)\n })",
|
|
" const offMotion = a?.onMotion((name) => {\n void adapterRef.current?.play(name)\n })\n const offLook = a?.onLook((p) => {\n adapterRef.current?.lookAt?.(p.x, p.y)\n })"
|
|
],
|
|
[
|
|
" offMotion?.()\n window.clearInterval(eventTimer)",
|
|
" offMotion?.()\n offLook?.()\n window.clearInterval(eventTimer)"
|
|
],
|
|
// 本地悬停跟随可保留,但全屏轮询已覆盖;本地仍保留以更平滑
|
|
[
|
|
` // 视线跟随:只要鼠标在窗口内移动就更新(不要求按住)
|
|
if (cfg.eyeFollow) {
|
|
adapterRef.current?.lookAt?.(e.clientX + cfg.cropLeft, e.clientY + cfg.cropTop)
|
|
}
|
|
const d = dragRef.current`,
|
|
` const d = dragRef.current`
|
|
]
|
|
])
|
|
patch('renderer/src/pet/adapters/live2d.ts', [
|
|
[
|
|
` if (x < 0 || y < 0) {
|
|
// 复位:看向画布中央偏下,即正前方
|
|
this.model?.focus(this.baseSize.w / 2, this.baseSize.h * 1.5)
|
|
return
|
|
}`,
|
|
` if (x < 0 || y < 0) {
|
|
// 复位:看向画布中央(正前方)
|
|
this.model?.focus(this.baseSize.w / 2, this.baseSize.h / 2)
|
|
return
|
|
}`
|
|
]
|
|
])
|
|
|
|
// ---- Panel:删除存档 + 等级标识 + 分区锚点 + 皮肤订阅
|
|
patch('renderer/src/panel/Panel.tsx', [
|
|
[
|
|
" const [profiles, setProfiles] = useState<Array<{ id: string; active: boolean }>>([])",
|
|
" const [profiles, setProfiles] = useState<Array<{ id: string; active: boolean; level: string }>>([])\n const [pendingSection, setPendingSection] = useState('')"
|
|
],
|
|
[
|
|
" void a?.getProfiles().then(setProfiles)",
|
|
" void a?.getProfiles().then(setProfiles)\n const offSkins = a?.onSkins(setSkins)"
|
|
],
|
|
[
|
|
" offFlavor?.()\n clearInterval(timer)",
|
|
" offFlavor?.()\n offSkins?.()\n clearInterval(timer)"
|
|
],
|
|
// 锚点滚动
|
|
[
|
|
" const level = useMemo(() => (state ? levelOf(state.exp) : 1), [state])",
|
|
" const level = useMemo(() => (state ? levelOf(state.exp) : 1), [state])\n\n useEffect(() => {\n if (!pendingSection) return\n const t = window.setTimeout(() => {\n document.getElementById('sec-' + pendingSection)?.scrollIntoView({ behavior: 'smooth', block: 'start' })\n }, 150)\n return () => window.clearTimeout(t)\n }, [pendingSection, tab])"
|
|
],
|
|
// 导航 arg 支持分区
|
|
[
|
|
` if (arg) {
|
|
const cats = ['meal', 'drink', 'drug', 'gear', 'book', 'gift']
|
|
if (cats.includes(arg)) setCat(arg as ItemCategory)
|
|
if (arg === 'work' || arg === 'study' || arg === 'play') {
|
|
setKind(arg)
|
|
setTaskId(JOBS.find((j) => j.kind === arg)?.id ?? '')
|
|
}
|
|
}`,
|
|
` if (arg) {
|
|
const cats = ['meal', 'drink', 'drug', 'gear', 'book', 'gift']
|
|
if (cats.includes(arg)) setCat(arg as ItemCategory)
|
|
if (arg === 'work' || arg === 'study' || arg === 'play') {
|
|
setKind(arg)
|
|
setTaskId(JOBS.find((j) => j.kind === arg)?.id ?? '')
|
|
}
|
|
if (['ai', 'profile', 'skin'].includes(arg)) setPendingSection(arg)
|
|
}`
|
|
],
|
|
// 存档行:等级 + 删除
|
|
[
|
|
` {profiles.map((p) => (
|
|
<div className="row" key={p.id}>
|
|
<div className="row-main">
|
|
<div className="row-title">
|
|
{p.id}
|
|
{p.active && <span className="count">(当前)</span>}
|
|
</div>
|
|
</div>
|
|
<button
|
|
className="mini"
|
|
disabled={p.active}
|
|
onClick={() => void api()?.switchProfile(p.id).then(setProfiles)}
|
|
>
|
|
切换
|
|
</button>
|
|
</div>
|
|
))}`,
|
|
` {profiles.map((p) => (
|
|
<div className="row" key={p.id}>
|
|
<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>
|
|
<button
|
|
className="mini"
|
|
disabled={p.active}
|
|
onClick={() => void api()?.switchProfile(p.id).then(setProfiles)}
|
|
>
|
|
切换
|
|
</button>
|
|
<button
|
|
className="mini"
|
|
disabled={p.active}
|
|
onClick={() => {
|
|
if (window.confirm('确定删除存档「' + p.id + '」?不可恢复。')) {
|
|
void api()?.delProfile(p.id).then(setProfiles)
|
|
}
|
|
}}
|
|
>
|
|
删除
|
|
</button>
|
|
</div>
|
|
))}`
|
|
],
|
|
// 分区锚点
|
|
[
|
|
` <div className="section-title">角色存档</div>`,
|
|
` <div className="section-title" id="sec-profile">角色存档</div>`
|
|
],
|
|
[
|
|
` <div className="section-title">角色 · Live2D</div>`,
|
|
` <div className="section-title" id="sec-skin">角色 · Live2D</div>`
|
|
],
|
|
[
|
|
` <div className="section-title">AI 对话</div>`,
|
|
` <div className="section-title" id="sec-ai">AI 对话</div>`
|
|
]
|
|
])
|
|
|
|
// ---- Menu:设置子菜单加功能索引
|
|
patch('renderer/src/menu/Menu.tsx', [
|
|
[
|
|
` settings: [
|
|
{ label: '图形', tab: 'settings' },
|
|
{ label: 'AI 与人设', tab: 'settings', arg: 'ai' }
|
|
]`,
|
|
` settings: [
|
|
{ label: '图形', tab: 'settings' },
|
|
{ label: 'AI 与人设', tab: 'settings', arg: 'ai' },
|
|
{ label: '角色存档', tab: 'settings', arg: 'profile' },
|
|
{ label: '角色 · Live2D', tab: 'settings', arg: 'skin' },
|
|
{ label: '图库', tab: 'photos' },
|
|
{ label: '资料库', action: 'storage' }
|
|
]`
|
|
]
|
|
])
|
|
|
|
console.log('p24 renderer patched')
|