feat: SodiumPet 小钠桌宠 v0.1.0(Live2D 桌宠 / 经济任务 / 音乐 / 成就 / 编辑器 / MOD)
This commit is contained in:
@@ -0,0 +1,121 @@
|
||||
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')
|
||||
}
|
||||
|
||||
// ---- catalog:levels 字段
|
||||
patch('shared/catalog.ts', [
|
||||
[
|
||||
`export interface CatalogData {
|
||||
items?: Item[]
|
||||
jobs?: JobDef[]
|
||||
}`,
|
||||
`export interface LevelMeta {
|
||||
desc?: string
|
||||
icon?: string
|
||||
}
|
||||
|
||||
export interface CatalogLevels {
|
||||
chemistry?: Record<string, LevelMeta>
|
||||
normal?: Record<string, LevelMeta>
|
||||
}
|
||||
|
||||
export interface CatalogData {
|
||||
items?: Item[]
|
||||
jobs?: JobDef[]
|
||||
levels?: CatalogLevels
|
||||
}
|
||||
|
||||
let CURRENT_LEVELS: CatalogLevels = {}
|
||||
|
||||
export function getCatalogLevels(): CatalogLevels {
|
||||
return CURRENT_LEVELS
|
||||
}`
|
||||
],
|
||||
[
|
||||
`export function applyCatalog(data: CatalogData | null | undefined): boolean {
|
||||
if (!data) return false
|
||||
let changed = false`,
|
||||
`export function applyCatalog(data: CatalogData | null | undefined): boolean {
|
||||
if (!data) return false
|
||||
let changed = false
|
||||
if (data.levels) CURRENT_LEVELS = data.levels`
|
||||
],
|
||||
[
|
||||
`export function snapshotCatalog(): CatalogData {
|
||||
return { items: JSON.parse(JSON.stringify(ITEMS)), jobs: JSON.parse(JSON.stringify(JOBS)) }
|
||||
}`,
|
||||
`export function snapshotCatalog(): CatalogData {
|
||||
return {
|
||||
items: JSON.parse(JSON.stringify(ITEMS)),
|
||||
jobs: JSON.parse(JSON.stringify(JOBS)),
|
||||
levels: JSON.parse(JSON.stringify(CURRENT_LEVELS))
|
||||
}
|
||||
}`
|
||||
]
|
||||
])
|
||||
|
||||
// ---- main:元素信息搜索缓存
|
||||
patch('main/index.ts', [
|
||||
[
|
||||
` ipcMain.handle('pet:icon:import', async () => {`,
|
||||
` let elementInfoCache: Record<string, string> = {}
|
||||
try {
|
||||
const cachePath = path.join(HOME, 'data', 'element-info.json')
|
||||
if (fs.existsSync(cachePath)) elementInfoCache = JSON.parse(fs.readFileSync(cachePath, 'utf8'))
|
||||
} catch {
|
||||
elementInfoCache = {}
|
||||
}
|
||||
|
||||
ipcMain.handle('pet:element:info', async (_e, z: number, name: string, symbol: string) => {
|
||||
const key = String(z)
|
||||
if (elementInfoCache[key]) return { text: elementInfoCache[key], cached: true }
|
||||
const q = \`元素 \${name} \${symbol} 主要物理化学性质\`
|
||||
const raw = await webSearchAll(q)
|
||||
const text = raw
|
||||
? raw.replace(/\\s+/g, ' ').slice(0, 400)
|
||||
: '(暂时没查到,网络可能不通)'
|
||||
if (raw) {
|
||||
elementInfoCache[key] = text
|
||||
try {
|
||||
fs.writeFileSync(path.join(HOME, 'data', 'element-info.json'), JSON.stringify(elementInfoCache, null, 2), 'utf8')
|
||||
} catch {
|
||||
/* 忽略 */
|
||||
}
|
||||
}
|
||||
return { text, cached: false }
|
||||
})
|
||||
|
||||
ipcMain.handle('pet:icon:import', async () => {`
|
||||
]
|
||||
])
|
||||
|
||||
// preload / api
|
||||
patch('preload/index.ts', [
|
||||
[
|
||||
" importIcon: () => Promise<string>",
|
||||
" importIcon: () => Promise<string>\n getElementInfo: (z: number, name: string, symbol: string) => Promise<{ text: string; cached: boolean }>"
|
||||
],
|
||||
[
|
||||
" importIcon: () => ipcRenderer.invoke('pet:icon:import'),",
|
||||
" importIcon: () => ipcRenderer.invoke('pet:icon:import'),\n getElementInfo: (z: number, name: string, symbol: string) => ipcRenderer.invoke('pet:element:info', z, name, symbol),"
|
||||
]
|
||||
])
|
||||
patch('renderer/src/api.ts', [
|
||||
[
|
||||
" importIcon: () => Promise<string>",
|
||||
" importIcon: () => Promise<string>\n getElementInfo: (z: number, name: string, symbol: string) => Promise<{ text: string; cached: boolean }>"
|
||||
]
|
||||
])
|
||||
|
||||
console.log('levels plumbing + element info patched')
|
||||
Reference in New Issue
Block a user