Files

208 lines
6.2 KiB
JavaScript

const fs = require('fs')
const base = 'C:/Users/ASUS/Documents/deepseek-harness/default-workspace/desktop-pet/src/renderer/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')
}
// Menu:保存 tabIcons
patch('menu/Menu.tsx', [
[
` const [flavor, setFlavor] = useState<'chemistry' | 'normal'>('chemistry')`,
` const [flavor, setFlavor] = useState<'chemistry' | 'normal'>('chemistry')\n const [tabIcons, setTabIcons] = useState<Record<string, string>>({})`
],
[
` const applyTheme = (c: { theme: string; accent: string }): void => {
document.documentElement.dataset.theme = c.theme`,
` const applyTheme = (c: {
theme: string
accent: string
tabIcons?: Record<string, string>
}): void => {
setTabIcons(c.tabIcons ?? {})
document.documentElement.dataset.theme = c.theme`
],
[
` {cfg?.tabIcons?.[c.id] && (
<img className="tab-icon" src={iconUrl(cfg.tabIcons[c.id])} alt="" />
)}`,
` {tabIcons[c.id] && <img className="tab-icon" src={iconUrl(tabIcons[c.id])} alt="" />}`
]
])
// Editor:新增「界面」页签(底栏图标)
patch('editor/Editor.tsx', [
[
"type Tab = 'item' | 'job' | 'level' | 'lyric'",
"type Tab = 'item' | 'job' | 'level' | 'lyric' | 'ui'"
],
[
" const [customDirty, setCustomDirty] = useState(false)",
` const [customDirty, setCustomDirty] = useState(false)
const [tabIcons, setTabIcons] = useState<Record<string, string>>({})
const [uiTab, setUiTab] = useState('feed')`
],
[
` setLyric({
lyricBg: c.lyricBg,
lyricColor: c.lyricColor,
lyricOutline: c.lyricOutline,
lyricSize: c.lyricSize
})`,
` setLyric({
lyricBg: c.lyricBg,
lyricColor: c.lyricColor,
lyricOutline: c.lyricOutline,
lyricSize: c.lyricSize
})
setTabIcons(c.tabIcons ?? {})`
],
[
` ['lyric', '歌词浮窗']`,
` ['lyric', '歌词浮窗'],
['ui', '界面']`
],
// 界面页:底栏图标设置
[
` {tab === 'lyric' && (`,
` {tab === 'ui' && (
<>
<div className="field">
<span>底栏按钮</span>
<select
className="text-input"
value={uiTab}
onChange={(e) => setUiTab(e.target.value)}
>
<option value="feed">投喂</option>
<option value="panel">面板</option>
<option value="interact">互动</option>
<option value="shop">商店 / 试剂店</option>
<option value="photos">图库</option>
<option value="settings">设置</option>
</select>
</div>
<div className="field">
<span>当前图标</span>
<div className="icon-picked">
<Icon value={tabIcons[uiTab]?.startsWith('sticker:') ? '🖼️' : tabIcons[uiTab]} className="icon-preview" />
<button className="mini" onClick={() => {
const next = { ...tabIcons }
delete next[uiTab]
setTabIcons(next)
}}>
清除
</button>
<button
className="mini"
onClick={() => {
void api()
?.importIcon()
.then((v) => {
if (v) setTabIcons({ ...tabIcons, [uiTab]: v })
})
}}
>
导入图片
</button>
</div>
</div>
<div className="tips">选一个表情包作为这个按钮的图标:</div>
<div className="sticker-grid">
{[
'1.0.png','2.0.png','3.0.png','4.0.png','5.0.png','6.0.png','7.0.png',
'8.0.png','9.0.png','10.02.png','11.2.png','16.0.png','20.0.png','23.1.png'
].map((name) => (
<button
key={name}
className={'sticker-cell' + (tabIcons[uiTab] === 'sticker:' + name ? ' on' : '')}
onClick={() => setTabIcons({ ...tabIcons, [uiTab]: 'sticker:' + name })}
>
<img src={'pet://stickers/' + encodeURIComponent(name)} alt={name} />
</button>
))}
</div>
<button
className="mini wide"
onClick={() => {
void api()?.setConfig({ tabIcons }).then(() => {
setToast('底栏图标已保存')
window.setTimeout(() => setToast(''), 1600)
})
}}
>
保存底栏图标
</button>
</>
)}
{tab === 'lyric' && (`
]
])
// 样式:tab 图标 + 表情包网格
{
const p = base + 'editor/editor.css'
let c = fs.readFileSync(p, 'utf8')
c += `
.sticker-grid {
display: grid;
grid-template-columns: repeat(7, 1fr);
gap: 6px;
}
.sticker-cell {
padding: 0;
border: 1px solid #2b3648;
border-radius: 10px;
background: transparent;
cursor: pointer;
overflow: hidden;
aspect-ratio: 1;
}
.sticker-cell img {
width: 100%;
height: 100%;
object-fit: cover;
display: block;
}
.sticker-cell.on {
border-color: #2f9cf0;
box-shadow: 0 0 0 2px #2f9cf0 inset;
}
[data-theme='day'] .sticker-cell {
border-color: #cfd8e6;
}
`
fs.writeFileSync(p, c, 'utf8')
}
{
const p = base + 'panel/panel.css'
let c = fs.readFileSync(p, 'utf8')
c += `
.tab-icon {
width: 17px;
height: 17px;
object-fit: cover;
border-radius: 4px;
margin-right: 4px;
vertical-align: -3px;
}
`
fs.writeFileSync(p, c, 'utf8')
}
console.log('ui icons editor patched')