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

192 lines
6.0 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')
}
// ---- 编辑器:日间主题 + 歌词页 + 自定义配色保存
patch('editor/Editor.tsx', [
[
"type Tab = 'item' | 'job' | 'level'",
"type Tab = 'item' | 'job' | 'level' | 'lyric'"
],
[
" const [periodic, setPeriodic] = useState<PeriodicStyle>(DEFAULT_PERIODIC_STYLE)",
` const [periodic, setPeriodic] = useState<PeriodicStyle>(DEFAULT_PERIODIC_STYLE)
const [lyric, setLyric] = useState({
lyricBg: 'rgba(16,20,30,0.55)',
lyricColor: '#ffffff',
lyricOutline: '#000000',
lyricSize: 20
})
const [presetName, setPresetName] = useState('')`
],
[
` void api()?.getConfig().then((c) => setTheme(c.theme))`,
` void api()?.getConfig().then((c) => {
setTheme(c.theme)
setLyric({
lyricBg: c.lyricBg,
lyricColor: c.lyricColor,
lyricOutline: c.lyricOutline,
lyricSize: c.lyricSize
})
})
const offCfg = api()?.onConfig((c) => setTheme(c.theme))
return () => offCfg?.()`
],
[
` ['item', '物品'],
['job', '活动'],
['level', '等级']`,
` ['item', '物品'],
['job', '活动'],
['level', '等级'],
['lyric', '歌词浮窗']`
],
// 歌词页表单
[
` {tab === 'level' && (`,
` {tab === 'lyric' && (
<>
<div className="field">
<span>浮窗底色</span>
<input
className="text-input"
value={lyric.lyricBg}
onChange={(e) => setLyric({ ...lyric, lyricBg: e.target.value })}
/>
</div>
<div className="field">
<span>文字颜色</span>
<input
type="color"
value={lyric.lyricColor}
onChange={(e) => setLyric({ ...lyric, lyricColor: e.target.value })}
/>
</div>
<div className="field">
<span>描边颜色</span>
<input
type="color"
value={lyric.lyricOutline}
onChange={(e) => setLyric({ ...lyric, lyricOutline: e.target.value })}
/>
</div>
<div className="field">
<span>字号</span>
<input
type="range"
min={14}
max={44}
step={1}
value={lyric.lyricSize}
onChange={(e) => setLyric({ ...lyric, lyricSize: Number(e.target.value) })}
/>
<b className="set-value">{lyric.lyricSize}px</b>
</div>
<button
className="mini wide"
onClick={() => {
void api()?.setConfig(lyric).then(() => {
setToast('歌词样式已保存')
window.setTimeout(() => setToast(''), 1600)
})
}}
>
保存歌词样式
</button>
<p className="tips">底色支持 rgba(半透明);描边是文字外的深色光晕。</p>
</>
)}
{tab === 'level' && (`
],
// 自定义配色保存
[
` <button
className="mini wide"
onClick={() => {
void api()?.saveCatalog({ items, jobs, levels: levelsMeta, periodic }).then((r) => {`,
` <div className="field">
<span>另存配色</span>
<input
className="text-input"
placeholder="给这套配色起个名字"
value={presetName}
onChange={(e) => setPresetName(e.target.value)}
/>
</div>
<button
className="mini wide"
onClick={() => {
if (!presetName.trim()) return
const presets = [
...(((periodic as { presets?: unknown[] }).presets ?? []) as unknown[]),
{ id: 'custom-' + Date.now(), name: presetName.trim(), scheme: periodic.scheme, colors: periodic.colors ?? {} }
]
const next = { ...periodic, presets }
setPeriodic(next as PeriodicStyle)
setPresetName('')
void api()?.saveCatalog({ items, jobs, levels: levelsMeta, periodic: next }).then((r) => {
if (r) {
setToast('配色方案已保存')
window.setTimeout(() => setToast(''), 1600)
}
})
}}
>
另存为自定义配色
</button>
<button
className="mini wide"
onClick={() => {
void api()?.saveCatalog({ items, jobs, levels: levelsMeta, periodic }).then((r) => {`
]
])
// 编辑器日间配色
{
const p = base + 'editor/editor.css'
let c = fs.readFileSync(p, 'utf8')
c += `
[data-theme='day'] html,
[data-theme='day'] body,
[data-theme='day'] #root {
background: #eef2f8;
}
[data-theme='day'] .editor {
background: #eef2f8;
color: #1b2434;
}
[data-theme='day'] .editor-row:hover,
[data-theme='day'] .editor-row.on {
background: #e6eef9;
border-color: #cfd8e6;
}
[data-theme='day'] .editor-form .field,
[data-theme='day'] .color-row {
color: #33415a;
}
[data-theme='day'] .editor-row-id {
color: #7a879b;
}
`
fs.writeFileSync(p, c, 'utf8')
}
console.log('editor day + lyric + preset save patched')