ctx.archive 管理玩家存档和档案级共享数据。

API

方法返回值说明
list()Promise<ArchiveSlot[]>列出全部存档槽
save(slotId, options?)Promise<void>保存到指定槽位
load(slotId)Promise<void>读取指定槽位
delete(slotId)Promise<void>删除指定槽位
quickSave(options?)Promise<void>写入快速存档
quickLoad()Promise<boolean>尝试快速读档,返回是否成功
useSlots()ArchiveSlot[]React Hook;订阅存档槽变化
cacheGameSnapshot()Promise<void>缓存当前游戏画面供下次存档使用
clearGameSnapshot()void清除画面缓存
flushShared()Promise<void>立即把 shared 变量写入磁盘
resetShared()Promise<void>清空全部 shared 变量

案例:保存到 3 号槽并重新读取列表

输入: 3 号槽当前为空,当前对话是“爱丽丝:明天见。”。
await ctx.archive.cacheGameSnapshot();
await ctx.archive.save(3, {
  userParams: { chapterLabel: "第二章" },
});
ctx.archive.clearGameSnapshot();

const slot = (await ctx.archive.list()).find((item) => item.id === 3);
console.log(slot && {
  id: slot.id,
  speaker: slot.currentSpeaker,
  text: slot.currentDialogueText,
  userParams: slot.userParams,
});
输出:
{
  "id": 3,
  "speaker": "爱丽丝",
  "text": "明天见。",
  "userParams": {
    "chapterLabel": "第二章"
  }
}
实际条目还包含创建时间、修改时间和截图数据。
resetShared() 不会弹出确认框,并会清空所有跨存档数据。调用前应由扩展自行向玩家二次确认。