跳到主要内容

模块系统

OpenTree 的模块系统是可扩展的功能单元。

模块类型

数据模块

直接与世界树数据库交互:

  • 钥匙串 (keychain)
  • 收藏夹 (favorites)
  • 笔记 (notes)
  • 音乐 (music)
  • 相册 (album)
  • 倒数日 (countdown)
  • 钱包 (wallet)
  • 卡包 (cardHolder)
  • 地址簿 (address)

功能模块

独立功能,不依赖世界树数据:

  • 技能树 (skills)
  • 签到 (checkin)
  • 邮件 (mail)
  • 任务公告榜 (questhall)
  • 副本 (instance)

模块 API 接口

每个数据模块通过 electronAPI 暴露标准 CRUD:

interface ModuleAPI {
getAll(): Promise<Item[]>
create(data: Partial<Item>): Promise<Item>
update(id: string, data: Partial<Item>): Promise<Item>
remove(id: string): Promise<boolean>
}

在元宇宙中接入模块

// 1. 获取 API
const api = getWtElectronAPI()

// 2. 加载数据
const items = await api.keychain.getAll()

// 3. 渲染列表
items.forEach(item => { /* ... */ })

// 4. 操作
await api.keychain.create({ name, password })
await api.keychain.update(id, { name })
await api.keychain.remove(id)