feat: SodiumPet 小钠桌宠 v0.1.0(Live2D 桌宠 / 经济任务 / 音乐 / 成就 / 编辑器 / MOD)
This commit is contained in:
@@ -0,0 +1,529 @@
|
||||
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')
|
||||
|
||||
// ---- 1) 状态:设置分区与搜索
|
||||
if (!c.includes('const [setSec, setSetSec]')) {
|
||||
c = c.replace(
|
||||
" const [sortBy, setSortBy] = useState<'default' | 'name' | 'price-asc' | 'price-desc'>('default')",
|
||||
" const [sortBy, setSortBy] = useState<'default' | 'name' | 'price-asc' | 'price-desc'>('default')\n const [setSec, setSetSec] = useState<'graphic' | 'interact' | 'text' | 'role' | 'save' | 'ai' | 'kb'>('graphic')\n const [setQuery, setSetQuery] = useState('')"
|
||||
)
|
||||
}
|
||||
|
||||
// ---- 2) 新设置界面
|
||||
const start = c.indexOf(' {tab === \'settings\' && cfg && (')
|
||||
const endMark = '\n </div>\n\n <nav className="tabs">'
|
||||
const end = c.indexOf(endMark)
|
||||
if (start < 0 || end < 0) {
|
||||
console.log('MISS markers', start, end)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
const block = [
|
||||
" {tab === 'settings' && cfg && (",
|
||||
' <div className="settings-layout">',
|
||||
' <aside className="settings-side">',
|
||||
' <input',
|
||||
' className="text-input set-search"',
|
||||
' placeholder="搜索设置"',
|
||||
' value={setQuery}',
|
||||
' onChange={(e) => setSetQuery(e.target.value)}',
|
||||
' />',
|
||||
' {SET_SECTIONS.filter((s) => !setQuery || s.label.includes(setQuery)).map((s) => (',
|
||||
' <button',
|
||||
' key={s.id}',
|
||||
" className={'side-item' + (setSec === s.id ? ' on' : '')}",
|
||||
' onClick={() => setSetSec(s.id)}',
|
||||
' >',
|
||||
' {s.label}',
|
||||
' </button>',
|
||||
' ))}',
|
||||
' </aside>',
|
||||
'',
|
||||
' <div className="settings-main">',
|
||||
' <div className="settings-tabs">',
|
||||
' {SET_SECTIONS.map((s) => (',
|
||||
' <button',
|
||||
' key={s.id}',
|
||||
" className={'set-tab' + (setSec === s.id ? ' on' : '')}",
|
||||
' onClick={() => setSetSec(s.id)}',
|
||||
' >',
|
||||
' {s.label}',
|
||||
' </button>',
|
||||
' ))}',
|
||||
' </div>',
|
||||
'',
|
||||
' <div className="settings-body">',
|
||||
" {setSec === 'graphic' && (",
|
||||
' <>',
|
||||
' <div className="toggle-row">',
|
||||
' <span>总在最前</span>',
|
||||
' <input',
|
||||
' type="checkbox"',
|
||||
' checked={cfg.topmost}',
|
||||
' onChange={(e) => void patchConfig({ topmost: e.target.checked })}',
|
||||
' />',
|
||||
' </div>',
|
||||
' <div className="toggle-row">',
|
||||
' <span>鼠标穿透(点不到她)</span>',
|
||||
' <input',
|
||||
' type="checkbox"',
|
||||
' checked={cfg.clickThrough}',
|
||||
' onChange={(e) => void patchConfig({ clickThrough: e.target.checked })}',
|
||||
' />',
|
||||
' </div>',
|
||||
' <label className="field">',
|
||||
' <span>缩放等级</span>',
|
||||
' <input',
|
||||
' type="range"',
|
||||
' min={0.7}',
|
||||
' max={3}',
|
||||
' step={0.05}',
|
||||
' value={cfg.scale}',
|
||||
' onChange={(e) => void patchConfig({ scale: Number(e.target.value) })}',
|
||||
' />',
|
||||
' <b className="set-value">{cfg.scale.toFixed(2)}</b>',
|
||||
' </label>',
|
||||
' <div className="field">',
|
||||
' <span>主题</span>',
|
||||
' <select',
|
||||
' className="text-input"',
|
||||
" value={cfg.theme === 'night' ? 'night' : 'day'}",
|
||||
' onChange={(e) =>',
|
||||
" void patchConfig({ theme: e.target.value === 'night' ? 'night' : 'day' })",
|
||||
' }',
|
||||
' >',
|
||||
' <option value="night">原版默认(深色)</option>',
|
||||
' <option value="day">日间(浅色)</option>',
|
||||
' </select>',
|
||||
' </div>',
|
||||
' <div className="field">',
|
||||
' <span>主色</span>',
|
||||
' <div className="swatches">',
|
||||
" {['#ffd54a', '#6fc8ff', '#ff8fb1', '#8ef0b0', '#cf9bff'].map((color) => (",
|
||||
' <button',
|
||||
' key={color}',
|
||||
" className={'swatch' + (cfg.accent === color ? ' on' : '')}",
|
||||
' style={{ background: color }}',
|
||||
' onClick={() => void patchConfig({ accent: color })}',
|
||||
' />',
|
||||
' ))}',
|
||||
' </div>',
|
||||
' </div>',
|
||||
' <div className="field">',
|
||||
' <span>裁掉顶部</span>',
|
||||
' <input',
|
||||
' type="range"',
|
||||
' min={0}',
|
||||
' max={Math.round(DESIGN_H * cfg.scale * 0.6)}',
|
||||
' step={5}',
|
||||
' value={cfg.cropTop}',
|
||||
' onChange={(e) => void patchConfig({ cropTop: Number(e.target.value) })}',
|
||||
' />',
|
||||
' <b className="set-value">{cfg.cropTop}px</b>',
|
||||
' </div>',
|
||||
' <div className="field">',
|
||||
' <span>裁掉底部</span>',
|
||||
' <input',
|
||||
' type="range"',
|
||||
' min={0}',
|
||||
' max={Math.round(DESIGN_H * cfg.scale * 0.6)}',
|
||||
' step={5}',
|
||||
' value={cfg.cropBottom}',
|
||||
' onChange={(e) => void patchConfig({ cropBottom: Number(e.target.value) })}',
|
||||
' />',
|
||||
' <b className="set-value">{cfg.cropBottom}px</b>',
|
||||
' </div>',
|
||||
' <div className="field">',
|
||||
' <span>裁掉左侧</span>',
|
||||
' <input',
|
||||
' type="range"',
|
||||
' min={0}',
|
||||
' max={Math.round(DESIGN_W * cfg.scale * 0.5)}',
|
||||
' step={5}',
|
||||
' value={cfg.cropLeft}',
|
||||
' onChange={(e) => void patchConfig({ cropLeft: Number(e.target.value) })}',
|
||||
' />',
|
||||
' <b className="set-value">{cfg.cropLeft}px</b>',
|
||||
' </div>',
|
||||
' <div className="field">',
|
||||
' <span>裁掉右侧</span>',
|
||||
' <input',
|
||||
' type="range"',
|
||||
' min={0}',
|
||||
' max={Math.round(DESIGN_W * cfg.scale * 0.5)}',
|
||||
' step={5}',
|
||||
' value={cfg.cropRight}',
|
||||
' onChange={(e) => void patchConfig({ cropRight: Number(e.target.value) })}',
|
||||
' />',
|
||||
' <b className="set-value">{cfg.cropRight}px</b>',
|
||||
' </div>',
|
||||
' <p className="tips">',
|
||||
' 尺寸 {Math.round(DESIGN_W * cfg.scale)}×',
|
||||
' {Math.round(DESIGN_H * cfg.scale - cfg.cropTop - cfg.cropBottom)}',
|
||||
' ,裁掉的部分不响应鼠标。穿透开启后请用托盘菜单关掉。',
|
||||
' </p>',
|
||||
' </>',
|
||||
' )}',
|
||||
'',
|
||||
" {setSec === 'interact' && (",
|
||||
' <>',
|
||||
' <div className="toggle-row">',
|
||||
' <span>视线跟随鼠标</span>',
|
||||
' <input',
|
||||
' type="checkbox"',
|
||||
' checked={cfg.eyeFollow}',
|
||||
' onChange={(e) => void patchConfig({ eyeFollow: e.target.checked })}',
|
||||
' />',
|
||||
' </div>',
|
||||
' <div className="toggle-row">',
|
||||
' <span>随机事件(遇水等)</span>',
|
||||
' <input',
|
||||
' type="checkbox"',
|
||||
' checked={cfg.eventsEnabled}',
|
||||
' onChange={(e) => void patchConfig({ eventsEnabled: e.target.checked })}',
|
||||
' />',
|
||||
' </div>',
|
||||
' <div className="toggle-row">',
|
||||
' <span>饿了自动买东西</span>',
|
||||
' <input',
|
||||
' type="checkbox"',
|
||||
' checked={cfg.autoBuy}',
|
||||
' onChange={(e) => void patchConfig({ autoBuy: e.target.checked })}',
|
||||
' />',
|
||||
' </div>',
|
||||
' <div className="schedule-row">',
|
||||
' <span>睡觉时间</span>',
|
||||
' <input',
|
||||
' type="time"',
|
||||
' className="text-input time-input"',
|
||||
' value={cfg.sleepAt}',
|
||||
' onChange={(e) => void patchConfig({ sleepAt: e.target.value })}',
|
||||
' />',
|
||||
' <span>起床时间</span>',
|
||||
' <input',
|
||||
' type="time"',
|
||||
' className="text-input time-input"',
|
||||
' value={cfg.wakeAt}',
|
||||
' onChange={(e) => void patchConfig({ wakeAt: e.target.value })}',
|
||||
' />',
|
||||
' </div>',
|
||||
' <p className="tips">作息会让她到点自己睡觉 / 起床。</p>',
|
||||
' </>',
|
||||
' )}',
|
||||
'',
|
||||
" {setSec === 'text' && (",
|
||||
' <>',
|
||||
' <div className="field">',
|
||||
' <span>文本风格</span>',
|
||||
' <select',
|
||||
' className="text-input"',
|
||||
' value={cfg.flavorMode}',
|
||||
' onChange={(e) =>',
|
||||
" void patchConfig({",
|
||||
" flavorMode: e.target.value as 'auto' | 'chemistry' | 'normal'",
|
||||
' })',
|
||||
' }',
|
||||
' >',
|
||||
' <option value="auto">自动(跟随角色)</option>',
|
||||
' <option value="chemistry">化学风格</option>',
|
||||
' <option value="normal">普通桌宠风格</option>',
|
||||
' </select>',
|
||||
' </div>',
|
||||
' <p className="tips">',
|
||||
' 化学风格会使用「饱食度 / 石蜡油 / 氧化度」这套词,普通风格用「饱食 / 口渴 / 清洁度」;',
|
||||
' 聊天人设也会跟着切换。',
|
||||
' </p>',
|
||||
' </>',
|
||||
' )}',
|
||||
'',
|
||||
" {setSec === 'role' && (",
|
||||
' <>',
|
||||
' <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>',
|
||||
' {renameSkinId === s.id ? (',
|
||||
' <>',
|
||||
' <input',
|
||||
' className="text-input rename-input"',
|
||||
' value={renameText}',
|
||||
' onChange={(e) => setRenameText(e.target.value)}',
|
||||
' />',
|
||||
' <button',
|
||||
' className="mini"',
|
||||
' onClick={() => {',
|
||||
' if (renameText.trim())',
|
||||
' void api()?.renameSkin(s.id, renameText).then(setSkins)',
|
||||
" setRenameSkinId('')",
|
||||
' }}',
|
||||
' >',
|
||||
' 确定',
|
||||
' </button>',
|
||||
' <button className="mini" onClick={() => setRenameSkinId(\'\')}>',
|
||||
' 取消',
|
||||
' </button>',
|
||||
' </>',
|
||||
' ) : (',
|
||||
' <button',
|
||||
' className="mini"',
|
||||
' onClick={() => {',
|
||||
' setRenameSkinId(s.id)',
|
||||
' setRenameText(s.name)',
|
||||
' }}',
|
||||
' >',
|
||||
' 重命名',
|
||||
' </button>',
|
||||
' )}',
|
||||
' </div>',
|
||||
' ))}',
|
||||
' </div>',
|
||||
' <button className="mini wide" onClick={() => void api()?.importSkin().then(setSkins)}>',
|
||||
' 一键导入 Live2D 文件夹',
|
||||
' </button>',
|
||||
' <p className="tips">',
|
||||
' 把 Live2D 模型文件夹放进 skins 目录,3 秒内自动识别并生成预设。',
|
||||
' </p>',
|
||||
' </>',
|
||||
' )}',
|
||||
'',
|
||||
" {setSec === 'save' && (",
|
||||
' <>',
|
||||
' <div className="list">',
|
||||
' {profiles.map((p) => (',
|
||||
' <div className="row" key={p.id}>',
|
||||
' <div className="row-main">',
|
||||
' <div className="row-title">',
|
||||
' {p.name || p.id}',
|
||||
' {p.active && <span className="count">(当前)</span>}',
|
||||
' </div>',
|
||||
' <div className="row-sub">{p.level}</div>',
|
||||
' </div>',
|
||||
' {renamePid === p.id ? (',
|
||||
' <>',
|
||||
' <input',
|
||||
' className="text-input rename-input"',
|
||||
' value={renameText}',
|
||||
' onChange={(e) => setRenameText(e.target.value)}',
|
||||
' />',
|
||||
' <button',
|
||||
' className="mini"',
|
||||
' onClick={() => {',
|
||||
' if (renameText.trim())',
|
||||
' void api()?.renameProfile(p.id, renameText).then(setProfiles)',
|
||||
" setRenamePid('')",
|
||||
' }}',
|
||||
' >',
|
||||
' 确定',
|
||||
' </button>',
|
||||
' <button className="mini" onClick={() => setRenamePid(\'\')}>',
|
||||
' 取消',
|
||||
' </button>',
|
||||
' </>',
|
||||
' ) : (',
|
||||
' <button',
|
||||
' className="mini"',
|
||||
' onClick={() => {',
|
||||
' setRenamePid(p.id)',
|
||||
' setRenameText(p.name || p.id)',
|
||||
' }}',
|
||||
' >',
|
||||
' 重命名',
|
||||
' </button>',
|
||||
' )}',
|
||||
' <button',
|
||||
' className="mini"',
|
||||
' disabled={p.active}',
|
||||
' onClick={() => void api()?.switchProfile(p.id).then(setProfiles)}',
|
||||
' >',
|
||||
' 切换',
|
||||
' </button>',
|
||||
' <button',
|
||||
' className="mini"',
|
||||
' disabled={p.active}',
|
||||
' onClick={() => {',
|
||||
" if (window.confirm('确定删除存档「' + p.id + '」?不可恢复。')) {",
|
||||
' void api()?.delProfile(p.id).then(setProfiles)',
|
||||
' }',
|
||||
' }}',
|
||||
' >',
|
||||
' 删除',
|
||||
' </button>',
|
||||
' </div>',
|
||||
' ))}',
|
||||
' </div>',
|
||||
' <div className="new-profile">',
|
||||
' <input',
|
||||
' className="text-input"',
|
||||
' value={newProfile}',
|
||||
' placeholder="新存档名"',
|
||||
' onChange={(e) => setNewProfile(e.target.value)}',
|
||||
' />',
|
||||
' <select',
|
||||
' className="text-input"',
|
||||
' value={newSkin}',
|
||||
' onChange={(e) => setNewSkin(e.target.value)}',
|
||||
' >',
|
||||
' {skins.map((s) => (',
|
||||
' <option key={s.id} value={s.id}>',
|
||||
' {s.name}',
|
||||
' </option>',
|
||||
' ))}',
|
||||
' </select>',
|
||||
' <button',
|
||||
' className="mini"',
|
||||
' onClick={() => {',
|
||||
' if (!newProfile.trim()) return',
|
||||
' void api()?.createProfile(newProfile, newSkin).then(setProfiles)',
|
||||
" setNewProfile('')",
|
||||
' }}',
|
||||
' >',
|
||||
' 新建',
|
||||
' </button>',
|
||||
' </div>',
|
||||
' <p className="tips">',
|
||||
' 新建时锁定人物立绘与文本风格;存档名与角色名都可以重命名。',
|
||||
' </p>',
|
||||
' </>',
|
||||
' )}',
|
||||
'',
|
||||
" {setSec === 'ai' && (",
|
||||
' <>',
|
||||
' {llm && (',
|
||||
' <>',
|
||||
' <label className="field">',
|
||||
' <span>接口地址</span>',
|
||||
' <input',
|
||||
' className="text-input"',
|
||||
' value={llm.baseUrl}',
|
||||
' onChange={(e) => setLlm({ ...llm, baseUrl: e.target.value })}',
|
||||
' />',
|
||||
' </label>',
|
||||
' <label className="field">',
|
||||
' <span>模型</span>',
|
||||
' <input',
|
||||
' className="text-input"',
|
||||
' value={llm.model}',
|
||||
' onChange={(e) => setLlm({ ...llm, model: e.target.value })}',
|
||||
' />',
|
||||
' </label>',
|
||||
' <label className="field">',
|
||||
' <span>API 密钥</span>',
|
||||
' <input',
|
||||
' className="text-input"',
|
||||
' type="password"',
|
||||
' value={llm.apiKey}',
|
||||
' placeholder="sk-..."',
|
||||
' onChange={(e) => setLlm({ ...llm, apiKey: e.target.value })}',
|
||||
' />',
|
||||
' </label>',
|
||||
' <label className="field">',
|
||||
' <span>温度</span>',
|
||||
' <input',
|
||||
' type="range"',
|
||||
' min={0.2}',
|
||||
' max={1.4}',
|
||||
' step={0.05}',
|
||||
' value={llm.temperature}',
|
||||
' onChange={(e) => setLlm({ ...llm, temperature: Number(e.target.value) })}',
|
||||
' />',
|
||||
' <b className="set-value">{llm.temperature.toFixed(2)}</b>',
|
||||
' </label>',
|
||||
' <label className="field">',
|
||||
' <span>人设补充</span>',
|
||||
' <textarea',
|
||||
' className="text-area"',
|
||||
' rows={3}',
|
||||
' value={llm.personaExtra}',
|
||||
' placeholder="例如:今天刚考完试,有点累;最喜欢石蜡油的味道"',
|
||||
' onChange={(e) => setLlm({ ...llm, personaExtra: e.target.value })}',
|
||||
' />',
|
||||
' </label>',
|
||||
' <button',
|
||||
' className="mini wide"',
|
||||
' onClick={() => {',
|
||||
' if (!llm) return',
|
||||
' const dirty = llm.apiKey.length > 0 && !llm.apiKey.includes(\'****\')',
|
||||
' const patch: Partial<LlmConfig> = {',
|
||||
' baseUrl: llm.baseUrl,',
|
||||
' model: llm.model,',
|
||||
' temperature: llm.temperature,',
|
||||
' enabled: llm.enabled,',
|
||||
' personaExtra: llm.personaExtra',
|
||||
' }',
|
||||
' if (dirty) patch.apiKey = llm.apiKey',
|
||||
' void api()',
|
||||
' ?.setLlm(patch)',
|
||||
' .then((next) => {',
|
||||
' setLlm(next)',
|
||||
" setToast('已保存')",
|
||||
" window.setTimeout(() => setToast(''), 1500)",
|
||||
' })',
|
||||
' }}',
|
||||
' >',
|
||||
' 保存 AI 设置',
|
||||
' </button>',
|
||||
' <p className="tips">',
|
||||
' 密钥只存在本机 data/llm.json。没配置时她会用本地台词回你。',
|
||||
' </p>',
|
||||
' </>',
|
||||
' )}',
|
||||
' </>',
|
||||
' )}',
|
||||
'',
|
||||
" {setSec === 'kb' && (",
|
||||
' <>',
|
||||
' {kbList.length === 0 && (',
|
||||
' <div className="empty">',
|
||||
' 还没有资料。把 .md/.txt 文件拖给小钠,再到「图库 → 文件袋」点「存知识库」。',
|
||||
' </div>',
|
||||
' )}',
|
||||
' <div className="list">',
|
||||
' {kbList.map((k) => (',
|
||||
' <div className="row" key={k.name}>',
|
||||
' <div className="row-main">',
|
||||
' <div className="row-title">📚 {k.name}</div>',
|
||||
' <div className="row-sub">{k.chars} 字</div>',
|
||||
' </div>',
|
||||
' <button',
|
||||
' className="mini"',
|
||||
' onClick={() => void api()?.delKb(k.name).then(setKbList)}',
|
||||
' >',
|
||||
' 删除',
|
||||
' </button>',
|
||||
' </div>',
|
||||
' ))}',
|
||||
' </div>',
|
||||
' </>',
|
||||
' )}',
|
||||
' </div>',
|
||||
' </div>',
|
||||
' </div>',
|
||||
' )}',
|
||||
''
|
||||
].join('\n')
|
||||
|
||||
c = c.slice(0, start) + block + c.slice(end)
|
||||
|
||||
// SET_SECTIONS 常量
|
||||
if (!c.includes('SET_SECTIONS')) {
|
||||
c = c.replace(
|
||||
"const PHOTO_CATS = ['默认', '表情', '纪念']",
|
||||
"const PHOTO_CATS = ['默认', '表情', '纪念']\n\nconst SET_SECTIONS = [\n { id: 'graphic', label: '图形' },\n { id: 'interact', label: '互动' },\n { id: 'text', label: '文本' },\n { id: 'role', label: '角色' },\n { id: 'save', label: '存档' },\n { id: 'ai', label: 'AI' },\n { id: 'kb', label: '知识库' }\n] as const"
|
||||
)
|
||||
}
|
||||
|
||||
fs.writeFileSync(p, c, 'utf8')
|
||||
console.log('settings rewritten')
|
||||
Reference in New Issue
Block a user