0.1.38 存档根治·石碑重刻:OPFS降级+错误上浮+回读校验+持久化请求+诊断面板+driver.open锁死修复+exportSave补open
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { GameState, SaveMeta, SnapshotMeta, Id } from '../types/domain'
|
||||
import { validateLoadedState, exportEnvelope, parseImportEnvelope } from './migrate'
|
||||
|
||||
const GAME_VERSION = '0.1.37'
|
||||
const GAME_VERSION = '0.1.38'
|
||||
|
||||
const DB_PREFIX = 'cotyc-save-'
|
||||
let seqCounter = 0
|
||||
@@ -47,6 +47,23 @@ export class SaveSlot {
|
||||
`INSERT INTO snapshot (id, year, month, savedAt, label, data) VALUES (?, ?, ?, ?, ?, ?)`,
|
||||
[id, state.year, state.month, new Date().toISOString(), label, json]
|
||||
)
|
||||
// 0.1.38 P1-F:回读校验——确认数据真正落盘
|
||||
const verify = await this.driver.all<{ data: string }>(
|
||||
`SELECT data FROM snapshot WHERE id = ?`,
|
||||
[id]
|
||||
)
|
||||
if (!verify.length || !verify[0]!.data) {
|
||||
throw new Error(`存档写入校验失败:数据未落盘(slot=${this.slot}, id=${id})`)
|
||||
}
|
||||
// 校验 JSON 可解析且关键字段在
|
||||
try {
|
||||
const check = JSON.parse(verify[0]!.data) as GameState
|
||||
if (!check.family || !check.members || typeof check.seed !== 'string') {
|
||||
throw new Error('存档回读校验失败:关键字段缺失')
|
||||
}
|
||||
} catch (e) {
|
||||
throw new Error(`存档回读校验失败:${String(e).slice(0, 80)}`)
|
||||
}
|
||||
const keep = 12
|
||||
const rows = await this.driver.all<{ id: string }>(
|
||||
`SELECT id FROM snapshot ORDER BY year DESC, month DESC, savedAt DESC`
|
||||
|
||||
Reference in New Issue
Block a user