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

API

方法返回值说明
list()Promise<ArchiveSlot[]>列出全部存档槽
save(slotId, options?)Promise<boolean>保存到指定槽位;覆盖时默认调用标准消息框,取消返回 false
load(slotId)Promise<void>读取指定槽位
delete(slotId)Promise<void>删除指定槽位;调用方负责确认
clear()Promise<void>清空全部槽位,包含快速存档;调用方负责确认
move(sourceSlotId, targetSlotId)Promise<boolean>移动到空槽,或与已有槽交换;无效或来源不存在返回 false
preloadSlots()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();
const saved = await ctx.archive.save(3, {
  userParams: { chapterLabel: "第二章" },
});
if (!saved) return;
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": "第二章"
  }
}
实际条目还包含创建时间、修改时间和截图数据。 已有内容的正数槽位默认通过 internal.system.message 显示覆盖确认。只有调用方已经 完成等价确认时,才应显式传入 confirmOverwrite: false;快速存档不受此选项影响。
resetShared() 不会弹出确认框,并会清空所有跨存档数据。调用前应由扩展自行向玩家二次确认。

移动与交换

const moved = await ctx.archive.move(3, 5);
if (!moved) {
  // 来源为空或槽位无效,提示玩家重新选择。
}
目标 5 号槽为空时移动,已有内容时交换 3、5 两个槽位。delete()、clear() 不弹确认;界面需自行完成危险操作确认。clear() 清理存档槽,resetShared() 清理跨存档变量,两者范围分别处理。