feat: SodiumPet 小钠桌宠 v0.1.0(Live2D 桌宠 / 经济任务 / 音乐 / 成就 / 编辑器 / MOD)
This commit is contained in:
@@ -0,0 +1,263 @@
|
||||
const fs = require('fs')
|
||||
const p = 'C:/Users/ASUS/Documents/deepseek-harness/default-workspace/desktop-pet/src/renderer/src/panel/Panel.tsx'
|
||||
let c = fs.readFileSync(p, 'utf8')
|
||||
|
||||
function rep(from, to) {
|
||||
if (!c.includes(from)) {
|
||||
console.log('MISS ::', from.slice(0, 80).replace(/\n/g, '\\n'))
|
||||
return
|
||||
}
|
||||
c = c.replace(from, to)
|
||||
}
|
||||
|
||||
// 状态与类型导入
|
||||
rep(
|
||||
"import { elementOf } from '../../../shared/elements'",
|
||||
"import { elementOf } from '../../../shared/elements'\nimport type { JobDef } from '../../../shared/petState'"
|
||||
)
|
||||
rep(
|
||||
" const [cat, setCat] = useState<'all' | ItemCategory>(() => {",
|
||||
" const [kind, setKind] = useState<JobDef['kind']>('work')\n const [taskId, setTaskId] = useState('wash')\n const [cat, setCat] = useState<'all' | ItemCategory>(() => {"
|
||||
)
|
||||
|
||||
// ---- 投喂:卡片化背包
|
||||
const feedOld = ` {tab === 'feed' && (
|
||||
<>
|
||||
<div className="chips">
|
||||
{(['meal', 'drink', 'drug', 'gear', 'book', 'gift'] as const).map((c) => (
|
||||
<button
|
||||
key={c}
|
||||
className="chip"
|
||||
onClick={() => {
|
||||
setCat(c)
|
||||
setTab('shop')
|
||||
}}
|
||||
>
|
||||
{CATEGORY_LABEL[c]}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
<div className="list">
|
||||
{ITEMS.filter((i) => (state.inventory[i.id] ?? 0) > 0).length === 0 && (
|
||||
<div className="empty">
|
||||
实验台是空的,去<span className="link" onClick={() => setTab('shop')}>试剂店</span>领用一点吧
|
||||
</div>
|
||||
)}
|
||||
{ITEMS.filter((i) => (state.inventory[i.id] ?? 0) > 0).map((item) => (
|
||||
<div className="row" key={item.id}>
|
||||
<div className="row-main">
|
||||
<div className="row-title">
|
||||
{item.name} <span className="count">×{state.inventory[item.id]}</span>
|
||||
</div>
|
||||
<div className="row-sub">{effectText(item)}</div>
|
||||
</div>
|
||||
<button className="mini" onClick={() => void call('use', item.id)}>
|
||||
使用
|
||||
</button>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</>
|
||||
)}`
|
||||
const feedNew = ` {tab === 'feed' && (
|
||||
<>
|
||||
<div className="chips">
|
||||
{(['all', 'meal', 'drink', 'drug', 'gear', 'book', 'gift'] as const).map((c) => (
|
||||
<button
|
||||
key={c}
|
||||
className={\`chip \${cat === c ? 'on' : ''}\`}
|
||||
onClick={() => setCat(c)}
|
||||
>
|
||||
{c === 'all' ? '全部' : CATEGORY_LABEL[c]}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
{ITEMS.filter(
|
||||
(i) => (cat === 'all' || i.category === cat) && (state.inventory[i.id] ?? 0) > 0
|
||||
).length === 0 && (
|
||||
<div className="empty">
|
||||
这里还没有东西,去
|
||||
<span className="link" onClick={() => setTab('shop')}>
|
||||
试剂店
|
||||
</span>
|
||||
领用一点吧
|
||||
</div>
|
||||
)}
|
||||
<div className="shop-grid">
|
||||
{ITEMS.filter(
|
||||
(i) => (cat === 'all' || i.category === cat) && (state.inventory[i.id] ?? 0) > 0
|
||||
).map((item) => (
|
||||
<div className="card" key={item.id}>
|
||||
<div className="card-name">
|
||||
{item.name} <span className="count">×{state.inventory[item.id]}</span>
|
||||
</div>
|
||||
<div className="card-effect">{effectText(item)}</div>
|
||||
<div className="card-foot">
|
||||
<span className="price">{CATEGORY_LABEL[item.category]}</span>
|
||||
<button className="mini" onClick={() => void call('use', item.id)}>
|
||||
使用
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</>
|
||||
)}`
|
||||
rep(feedOld, feedNew)
|
||||
|
||||
// ---- 互动:下拉选择 + 数值面板
|
||||
const interOld = ` <div className="section-title">工作 · 赚钱</div>
|
||||
<div className="list">
|
||||
{JOBS.filter((j) => j.kind === 'work').map((j) => {
|
||||
const locked = level < j.level
|
||||
return (
|
||||
<div className={\`row \${locked ? 'locked' : ''}\`} key={j.id}>
|
||||
<div className="row-main">
|
||||
<div className="row-title">
|
||||
{j.name}
|
||||
{locked && <span className="count"> Lv.{j.level}</span>}
|
||||
</div>
|
||||
<div className="row-sub">
|
||||
{j.minutes} 分钟 · ◆{Math.round(j.coin * mult)} · 经验 {Math.round(j.exp * mult)}
|
||||
</div>
|
||||
</div>
|
||||
<button
|
||||
className="mini"
|
||||
disabled={locked || !!job}
|
||||
onClick={() => void call('work', j.id)}
|
||||
>
|
||||
{job?.id === j.id ? '进行中' : '开始'}
|
||||
</button>
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
|
||||
<div className="section-title">学习 · 涨经验</div>
|
||||
<div className="list">
|
||||
{JOBS.filter((j) => j.kind === 'study').map((j) => {
|
||||
const locked = level < j.level
|
||||
return (
|
||||
<div className={\`row \${locked ? 'locked' : ''}\`} key={j.id}>
|
||||
<div className="row-main">
|
||||
<div className="row-title">
|
||||
{j.name}
|
||||
{locked && <span className="count"> Lv.{j.level}</span>}
|
||||
</div>
|
||||
<div className="row-sub">
|
||||
{j.minutes} 分钟 · 经验 {Math.round(j.exp * mult)} · 电子 −{j.electron}
|
||||
</div>
|
||||
</div>
|
||||
<button
|
||||
className="mini"
|
||||
disabled={locked || !!job}
|
||||
onClick={() => void call('work', j.id)}
|
||||
>
|
||||
{job?.id === j.id ? '进行中' : '开始'}
|
||||
</button>
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>`
|
||||
const interNew = ` <div className="section-title">活动</div>
|
||||
<div className="picker">
|
||||
<select
|
||||
className="text-input"
|
||||
value={kind}
|
||||
onChange={(e) => {
|
||||
const k = e.target.value as JobDef['kind']
|
||||
setKind(k)
|
||||
setTaskId(JOBS.find((j) => j.kind === k)?.id ?? '')
|
||||
}}
|
||||
>
|
||||
<option value="work">工作 · 赚钱</option>
|
||||
<option value="study">学习 · 涨经验</option>
|
||||
<option value="play">玩耍 · 放松</option>
|
||||
</select>
|
||||
<select
|
||||
className="text-input"
|
||||
value={taskId}
|
||||
onChange={(e) => setTaskId(e.target.value)}
|
||||
>
|
||||
{JOBS.filter((j) => j.kind === kind).map((j) => (
|
||||
<option key={j.id} value={j.id}>
|
||||
{j.name}
|
||||
{level < j.level ? \`(需 Lv.\${j.level})\` : ''}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
{(function renderTask() {
|
||||
const active = JOBS.find((j) => j.id === taskId && j.kind === kind) ?? JOBS.find((j) => j.kind === kind)
|
||||
if (!active) return null
|
||||
const locked = level < active.level
|
||||
return (
|
||||
<div className="task-card">
|
||||
<div className="task-line">
|
||||
<span>时长</span>
|
||||
<span>{active.minutes} 分钟</span>
|
||||
</div>
|
||||
{active.coin > 0 && (
|
||||
<div className="task-line">
|
||||
<span>金币</span>
|
||||
<span className="money">◆ {Math.round(active.coin * mult)}</span>
|
||||
</div>
|
||||
)}
|
||||
{active.exp > 0 && (
|
||||
<div className="task-line">
|
||||
<span>经验</span>
|
||||
<span>{Math.round(active.exp * mult)}</span>
|
||||
</div>
|
||||
)}
|
||||
<div className="task-line">
|
||||
<span>电子</span>
|
||||
<span>{active.electron >= 0 ? '−' : '+'}{Math.abs(active.electron)}</span>
|
||||
</div>
|
||||
<div className="task-line">
|
||||
<span>饱食</span>
|
||||
<span>−{active.satiety}</span>
|
||||
</div>
|
||||
{active.mood !== 0 && (
|
||||
<div className="task-line">
|
||||
<span>心情</span>
|
||||
<span>{active.mood > 0 ? '+' : ''}{active.mood}</span>
|
||||
</div>
|
||||
)}
|
||||
<div className="task-line">
|
||||
<span>等级倍率</span>
|
||||
<span>×{mult.toFixed(2)}</span>
|
||||
</div>
|
||||
<button
|
||||
className="mini wide"
|
||||
disabled={locked || !!job}
|
||||
onClick={() => void call('work', active.id)}
|
||||
>
|
||||
{locked ? \`需要 Lv.\${active.level}\` : job?.id === active.id ? '进行中' : '开始'}
|
||||
</button>
|
||||
</div>
|
||||
)
|
||||
})()}
|
||||
{job && (
|
||||
<div className="job">
|
||||
<div className="job-top">
|
||||
<span>进行中 · {job.name}</span>
|
||||
<span>{Math.max(0, Math.ceil((job.endAt - now) / 1000))}s</span>
|
||||
</div>
|
||||
<div className="bar job-bar">
|
||||
<i
|
||||
style={{
|
||||
width: \`\${Math.min(
|
||||
100,
|
||||
Math.max(0, ((now - job.startAt) / (job.endAt - job.startAt)) * 100)
|
||||
)}%\`,
|
||||
background: '#ffd54a'
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)}`
|
||||
rep(interOld, interNew)
|
||||
|
||||
fs.writeFileSync(p, c, 'utf8')
|
||||
console.log('panel patched')
|
||||
Reference in New Issue
Block a user