feat: SodiumPet 小钠桌宠 v0.1.0(Live2D 桌宠 / 经济任务 / 音乐 / 成就 / 编辑器 / MOD)

This commit is contained in:
Tian_XiaRi
2026-12-01 16:41:07 +08:00
commit d25e726ef7
261 changed files with 33676 additions and 0 deletions
+180
View File
@@ -0,0 +1,180 @@
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')
}
// ---- App:按配置加载皮肤 + 皮肤切换时重载
patch('renderer/src/App.tsx', [
[
`const SKIN_ID = 'xiaona'
const TAP_SLOP = 4`,
`const TAP_SLOP = 4`
],
[
` async function boot(): Promise<void> {
try {
const baseUrl = \`pet://skins/\${SKIN_ID}/\``,
` const loadedSkinRef = { value: '' }
async function boot(): Promise<void> {
try {
const skinId = cfgRef.current.currentSkin || 'xiaona'
const baseUrl = \`pet://skins/\${skinId}/\``
],
[
` await adapter.mount(stageRef.current, {
w: DESIGN_W * cfgRef.current.scale,
h: DESIGN_H * cfgRef.current.scale
})
adapterRef.current = adapter
adapter.resize(DESIGN_W * cfgRef.current.scale, DESIGN_H * cfgRef.current.scale)
void adapter.play(skin.motions?.idle ?? 'Idle', true)`,
` await adapter.mount(stageRef.current, {
w: DESIGN_W * cfgRef.current.scale,
h: DESIGN_H * cfgRef.current.scale
})
adapterRef.current = adapter
adapter.resize(DESIGN_W * cfgRef.current.scale, DESIGN_H * cfgRef.current.scale)
void adapter.play(skin.motions?.idle ?? 'Idle', true)
loadedSkinRef.value = cfgRef.current.currentSkin || 'xiaona'`
],
[
` if (!cfg.eyeFollow) adapterRef.current?.lookAt?.(-1, -1)
}, [cfg])`,
` if (!cfg.eyeFollow) adapterRef.current?.lookAt?.(-1, -1)
if ((cfg.currentSkin || 'xiaona') !== loadedSkinRef.value) {
window.location.reload()
}
}, [cfg])`
]
])
// ---- Panel:风味标签 + 角色存档 + 角色管理
patch('renderer/src/panel/Panel.tsx', [
[
"import type { JobDef } from '../../../shared/petState'",
"import type { JobDef } from '../../../shared/petState'\nimport { FLAVOR_HINTS, FLAVOR_LABELS, type Flavor } from '../../../shared/flavor'"
],
[
" const [daily, setDaily] = useState<{ itemId: string; price: number; name: string; origin: number; claimed: boolean } | null>(null)",
" const [daily, setDaily] = useState<{ itemId: string; price: number; name: string; origin: number; claimed: boolean } | null>(null)\n const [flavor, setFlavor] = useState<Flavor>('chemistry')\n const [profiles, setProfiles] = useState<Array<{ id: string; active: boolean }>>([])\n const [skins, setSkins] = useState<Array<{ id: string; name: string; active: boolean }>>([])\n const [newProfile, setNewProfile] = useState('')"
],
[
" void a?.getDailySpecial().then(setDaily)",
` void a?.getDailySpecial().then(setDaily)
void a?.getProfiles().then(setProfiles)
void a?.getSkins().then(setSkins)
// 按当前皮肤加载风味
const applyFlavor = (cfg2: { currentSkin?: string }): void => {
const id = cfg2.currentSkin || 'xiaona'
void fetch('pet://skins/' + id + '/skin.json')
.then((r) => (r.ok ? r.json() : null))
.then((m) => setFlavor(m && m.flavor === 'normal' ? 'normal' : 'chemistry'))
.catch(() => setFlavor('chemistry'))
}
void a?.getConfig().then((c) => applyFlavor(c))
const offFlavor = a?.onConfig((c) => applyFlavor(c))`
],
[
" offNav?.()\n clearInterval(timer)",
" offNav?.()\n offFlavor?.()\n clearInterval(timer)"
],
// 状态条标签按风味
[
` {ORDER.map((key) => {
const meta = STAT_META[key]
const value = Math.round(state.stats[key])`,
` {ORDER.map((key) => {
const meta = STAT_META[key]
const raw = state.stats[key]
const value = flavor === 'normal' && key === 'oxidation' ? Math.round(100 - raw) : Math.round(raw)`
],
[
` <span className="stat-label">{meta.label}</span>`,
` <span className="stat-label">{FLAVOR_LABELS[flavor][key]}</span>`
],
// 设置页:角色存档 + 角色皮肤(放在知识库之前)
[
` <div className="section-title">知识库</div>`,
` <div className="section-title">角色存档</div>
<div className="list">
{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>
))}
</div>
<div className="picker">
<input
className="text-input"
value={newProfile}
placeholder="新存档名"
onChange={(e) => setNewProfile(e.target.value)}
/>
<button
className="mini"
onClick={() => {
if (!newProfile.trim()) return
void api()?.createProfile(newProfile).then(setProfiles)
setNewProfile('')
}}
>
新建
</button>
</div>
<div className="section-title">角色 · Live2D</div>
<div className="list">
{skins.map((s) => (
<div className="row" key={s.id}>
<div className="row-main">
<div className="row-title">
{s.name}
{s.active && <span className="count">(当前)</span>}
</div>
</div>
<button
className="mini"
disabled={s.active}
onClick={() => void api()?.switchSkin(s.id).then(setSkins)}
>
切换
</button>
</div>
))}
</div>
<button className="mini wide" onClick={() => void api()?.importSkin().then(setSkins)}>
一键导入 Live2D 文件夹
</button>
<p className="tips">
导入的角色使用普通桌宠风格文本;预设化拟角色(小钠等)保持化学风格。
</p>
<div className="section-title">知识库</div>`
]
])
console.log('app/panel flavor+profiles patched')