SuperAPI AI 工具集

foundry-vtt-system-dev

通用与其它

查看项目

更新于 10-15 21:41

技能介绍

该技能用于构建、扩展和维护 Foundry VTT v14+ 的游戏系统(system),系统定义核心规则,如 Actor/Item 类型、骰子机制、战斗和角色卡;模块(module)则用于扩展系统。技能覆盖从清单文件到发布的全生命周期。技能依赖 foundry-vtt-module-dev 提供的共享参考文献(v14-migration.md、active-effects-v2.md、scene-levels.md、measured-templates.md),需同时安装。

主要能力包括:使用 manifest 的 documentTypes 声明类型,配合 TypeDataModel 的 defineSchema() 定义字段、默认值、校验与派生数据;脚本入口 main.mjs 组织 actor.mjs、item.mjs、data、sheets、templates、styles、packs、lang 等目录;系统与模块共享同一套 Hooks 生命周期,init 钩子用于注册数据模型、自定义文档类、先攻公式与设置;使用命名空间后的 foundry.* 路径替代已移除的全局变量;提供单体 ESM 入口、barrel 文件、globalThis 系统 API、hotReload、htmlFields 与 filePathFields、迁移版本标记、冻结 config.mjs、分阶段 init 钩子、packFolders、构建流水线等生产架构模式。

使用方式:从 boilerplate/system.json 与 boilerplate/main.mjs 起步;在 system.json 中声明 id、type、compatibility(建议 "14")、esmodules、styles、documentTypes 等字段;在 init 钩子中通过 Object.assign(CONFIG.Actor.dataModels, {...}) 注册类型;用自定义子类替换 CONFIG.Actor.documentClass 与 CONFIG.Item.documentClass,实现 getRollData()、_preCreate()、roll() 等;用 ActorSheetV2/ItemSheetV2 搭配 HandlebarsApplicationMixin 注册系统卡。

限制与注意:template.json 自 v14 起弃用、v16 移除,其列出的类型会被服务端重置,迁移需将默认值移入 TypeDataModel 的 initial,将类型名移入 documentTypes;v14 中 Roll#toMessage 的 rollMode 选项弃用,改用 messageMode;prepareDerivedData() 中禁止写数据库;primaryTokenAttribute 与 secondaryTokenAttribute 需指向含 value 与 max 的对象。完整细节涉及参考文献,此处暂未提供完整字段清单。