Files
SodiumPet/tools/patch-p39-b.cjs
T

169 lines
7.1 KiB
JavaScript
Raw 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/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')
}
// ---- Detail:使用配色方案
patch('detail/Detail.tsx', [
[
"import { ELEMENTS, elementName, levelLabelWrapped, MAX_LEVEL } from '../../../shared/elements'",
"import {\n CATEGORY_COLORS,\n CATEGORY_LABEL,\n DEFAULT_PERIODIC_STYLE,\n ELEMENTS,\n elementName,\n levelLabelWrapped,\n MAX_LEVEL,\n periodicCellColor,\n type PeriodicStyle\n} from '../../../shared/elements'"
],
[
" const [lvMode, setLvMode] = useState<'auto' | 'chemistry' | 'normal'>('auto')",
" const [lvMode, setLvMode] = useState<'auto' | 'chemistry' | 'normal'>('auto')\n const [periodic, setPeriodic] = useState<PeriodicStyle>(DEFAULT_PERIODIC_STYLE)"
],
[
` void a?.getCatalog().then((cat) => {
try {
setLevels(((cat as { levels?: CatalogLevels }).levels ?? {}) as CatalogLevels)
} catch {
setLevels({})
}
})`,
` void a?.getCatalog().then((cat) => {
try {
setLevels(((cat as { levels?: CatalogLevels }).levels ?? {}) as CatalogLevels)
setPeriodic(
((cat as { periodic?: PeriodicStyle }).periodic ?? DEFAULT_PERIODIC_STYLE) as PeriodicStyle
)
} catch {
setLevels({})
}
})`
],
[
` <div className="periodic">`,
` <div className="periodic" style={{ background: periodic.bg }}>`
],
[
` style={{ gridRow: row, gridColumn: col, background: el.color }}`,
` style={{
gridRow: row,
gridColumn: col,
background: periodicCellColor(el, periodic)
}}`
],
// 图例
[
` <div className="element-panel">`,
` <div className="periodic-legend">
{periodic.scheme === 'category'
? (Object.keys(CATEGORY_LABEL) as Array<keyof typeof CATEGORY_LABEL>).map((k) => (
<span key={k} className="legend-item">
<i style={{ background: periodic.colors?.[k] ?? CATEGORY_COLORS[k] }} />
{CATEGORY_LABEL[k]}
</span>
))
: (['s', 'p', 'd', 'f'] as const).map((b) => (
<span key={b} className="legend-item">
<i style={{ background: periodic.colors?.[b] ?? ({s:'#ffd54a',p:'#6fc8ff',d:'#8ef0b0',f:'#cf9bff'} as Record<string,string>)[b] }} />
{b} 区
</span>
))}
</div>
<div className="element-panel">`
]
])
// ---- Editor:周期表配色编辑(等级页底部)
patch('editor/Editor.tsx', [
[
"import { elementName, MAX_LEVEL } from '../../../shared/elements'",
"import {\n CATEGORY_COLORS,\n CATEGORY_LABEL,\n DEFAULT_PERIODIC_STYLE,\n elementName,\n MAX_LEVEL,\n type PeriodicStyle\n} from '../../../shared/elements'"
],
[
" const [lvDraft, setLvDraft] = useState<{ desc: string; icon: string }>({ desc: '', icon: '' })",
" const [lvDraft, setLvDraft] = useState<{ desc: string; icon: string }>({ desc: '', icon: '' })\n const [periodic, setPeriodic] = useState<PeriodicStyle>(DEFAULT_PERIODIC_STYLE)"
],
[
" setLevelsMeta(((c as { levels?: CatalogLevels }).levels ?? {}) as CatalogLevels)",
" setLevelsMeta(((c as { levels?: CatalogLevels }).levels ?? {}) as CatalogLevels)\n setPeriodic(\n ((c as { periodic?: PeriodicStyle }).periodic ?? DEFAULT_PERIODIC_STYLE) as PeriodicStyle\n )"
],
// 周期表配置块(放在等级表单之后,仍属于等级页)
[
` <p className="tips">等级描述会显示在「详细 → 等级预览」里;化学等级还能用元素名做提示。</p>`,
` <p className="tips">等级描述会显示在「详细 → 等级预览」里;化学等级还能用元素名做提示。</p>
<div className="section-title">周期表配色</div>
<div className="field">
<span>配色方案</span>
<select
className="text-input"
value={periodic.scheme}
onChange={(e) =>
setPeriodic({ ...periodic, scheme: e.target.value as 'block' | 'category' })
}
>
<option value="block">按能级块(s / p / d / f)</option>
<option value="category">按元素分类(碱金属 / 过渡金属 / 卤素…)</option>
</select>
</div>
<div className="periodic-colors">
{(periodic.scheme === 'category'
? (Object.keys(CATEGORY_LABEL) as Array<keyof typeof CATEGORY_LABEL>).map((k) => ({
key: k as string,
label: CATEGORY_LABEL[k],
fallback: CATEGORY_COLORS[k]
}))
: (['s', 'p', 'd', 'f'] as const).map((b) => ({
key: b as string,
label: b + ' 区',
fallback: ({ s: '#ffd54a', p: '#6fc8ff', d: '#8ef0b0', f: '#cf9bff' } as Record<
string,
string
>)[b]
}))
).map((row) => (
<label key={row.key} className="color-row">
<input
type="color"
value={periodic.colors?.[row.key] ?? row.fallback}
onChange={(e) =>
setPeriodic({
...periodic,
colors: { ...(periodic.colors ?? {}), [row.key]: e.target.value }
})
}
/>
<span>{row.label}</span>
</label>
))}
</div>
<div className="field">
<span>底图背景</span>
<input
type="color"
value={periodic.bg ?? '#0e1420'}
onChange={(e) => setPeriodic({ ...periodic, bg: e.target.value })}
/>
</div>
<button
className="mini wide"
onClick={() => {
void api()?.saveCatalog({ items, jobs, levels: levelsMeta, periodic }).then((r) => {
if (r) {
setToast(r.message)
window.setTimeout(() => setToast(''), 1800)
}
})
}}
>
保存周期表配色
</button>`
]
])
console.log('periodic wiring patched')