feat: SodiumPet 小钠桌宠 v0.1.0(Live2D 桌宠 / 经济任务 / 音乐 / 成就 / 编辑器 / MOD)
This commit is contained in:
@@ -0,0 +1,131 @@
|
||||
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('preload/index.ts', [
|
||||
[
|
||||
" importIcon: () => Promise<string>",
|
||||
` importIcon: () => Promise<string>
|
||||
openMusic: () => void
|
||||
chooseMusicDir: () => Promise<{ dir: string; tracks: Array<{ name: string; file: string }> }>
|
||||
listMusic: () => Promise<{ dir: string; tracks: Array<{ name: string; file: string }> }>
|
||||
getLyric: (file: string) => Promise<string>
|
||||
sendMusicNow: (payload: unknown) => void
|
||||
onMusicNow: (cb: (p: unknown) => void) => () => void
|
||||
onMusicList: (
|
||||
cb: (p: { dir: string; tracks: Array<{ name: string; file: string }> }) => void
|
||||
) => () => void
|
||||
openLyric: () => void
|
||||
closeLyric: () => void`
|
||||
],
|
||||
[
|
||||
" importIcon: () => ipcRenderer.invoke('pet:icon:import'),",
|
||||
` importIcon: () => ipcRenderer.invoke('pet:icon:import'),
|
||||
openMusic: () => ipcRenderer.send('pet:music:open'),
|
||||
chooseMusicDir: () => ipcRenderer.invoke('pet:music:choose'),
|
||||
listMusic: () => ipcRenderer.invoke('pet:music:list'),
|
||||
getLyric: (file: string) => ipcRenderer.invoke('pet:music:lyric', file),
|
||||
sendMusicNow: (payload: unknown) => ipcRenderer.send('pet:music:now', payload),
|
||||
onMusicNow: (cb: (p: unknown) => void) => {
|
||||
const l = (_e: unknown, p: unknown): void => cb(p)
|
||||
ipcRenderer.on('pet:music:now', l)
|
||||
return () => ipcRenderer.removeListener('pet:music:now', l)
|
||||
},
|
||||
onMusicList: (
|
||||
cb: (p: { dir: string; tracks: Array<{ name: string; file: string }> }) => void
|
||||
) => {
|
||||
const l = (
|
||||
_e: unknown,
|
||||
p: { dir: string; tracks: Array<{ name: string; file: string }> }
|
||||
): void => cb(p)
|
||||
ipcRenderer.on('pet:music:list', l)
|
||||
return () => ipcRenderer.removeListener('pet:music:list', l)
|
||||
},
|
||||
openLyric: () => ipcRenderer.send('pet:lyric:open'),
|
||||
closeLyric: () => ipcRenderer.send('pet:lyric:close'),`
|
||||
]
|
||||
])
|
||||
|
||||
patch('renderer/src/api.ts', [
|
||||
[
|
||||
" importIcon: () => Promise<string>",
|
||||
` importIcon: () => Promise<string>
|
||||
openMusic: () => void
|
||||
chooseMusicDir: () => Promise<{ dir: string; tracks: Array<{ name: string; file: string }> }>
|
||||
listMusic: () => Promise<{ dir: string; tracks: Array<{ name: string; file: string }> }>
|
||||
getLyric: (file: string) => Promise<string>
|
||||
sendMusicNow: (payload: unknown) => void
|
||||
onMusicNow: (cb: (p: unknown) => void) => () => void
|
||||
onMusicList: (
|
||||
cb: (p: { dir: string; tracks: Array<{ name: string; file: string }> }) => void
|
||||
) => () => void
|
||||
openLyric: () => void
|
||||
closeLyric: () => void`
|
||||
]
|
||||
])
|
||||
|
||||
// 路由 + 菜单 + 设置入口
|
||||
patch('renderer/src/main.tsx', [
|
||||
[
|
||||
"import Editor from './editor/Editor'",
|
||||
"import Editor from './editor/Editor'\nimport Music from './music/Music'\nimport Lyric from './lyric/Lyric'"
|
||||
],
|
||||
[
|
||||
" if (view === 'editor') return <Editor />",
|
||||
" if (view === 'editor') return <Editor />\n if (view === 'music') return <Music />\n if (view === 'lyric') return <Lyric />"
|
||||
]
|
||||
])
|
||||
|
||||
patch('renderer/src/menu/Menu.tsx', [
|
||||
[
|
||||
" action?: 'sleep' | 'storage' | 'editor'",
|
||||
" action?: 'sleep' | 'storage' | 'editor' | 'music'"
|
||||
],
|
||||
[
|
||||
` { label: '摸摸头', action: 'pet' },`,
|
||||
` { label: '摸摸头', action: 'pet' },
|
||||
{ label: '听歌', action: 'music' },`
|
||||
],
|
||||
[
|
||||
` if (item.action === 'editor') {
|
||||
api()?.openEditor()
|
||||
return
|
||||
}`,
|
||||
` if (item.action === 'editor') {
|
||||
api()?.openEditor()
|
||||
return
|
||||
}
|
||||
if (item.action === 'music') {
|
||||
api()?.openMusic()
|
||||
return
|
||||
}`
|
||||
]
|
||||
])
|
||||
|
||||
// Panel:互动侧栏「听歌」
|
||||
patch('renderer/src/panel/Panel.tsx', [
|
||||
[
|
||||
` <button className="side-item" onClick={() => setTab('shop')}>
|
||||
{flavor === 'normal' ? '去商店' : '去试剂店'}
|
||||
</button>`,
|
||||
` <button className="side-item" onClick={() => setTab('shop')}>
|
||||
{flavor === 'normal' ? '去商店' : '去试剂店'}
|
||||
</button>
|
||||
<button className="side-item" onClick={() => api()?.openMusic()}>
|
||||
听歌
|
||||
</button>`
|
||||
]
|
||||
])
|
||||
|
||||
console.log('music bridge patched')
|
||||
Reference in New Issue
Block a user