0.1.38 存档根治·石碑重刻:OPFS降级+错误上浮+回读校验+持久化请求+诊断面板+driver.open锁死修复+exportSave补open

This commit is contained in:
2026-09-13 08:02:04 +08:00
parent 8f1f8d48ce
commit 5030eb04d2
11 changed files with 634 additions and 42 deletions
+18 -1
View File
@@ -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`