Cataclysm-DDA 怎么创建带 modinfo.json 的最小模组并让游戏识别它?
2026/9/15 14:40:27 网站建设 项目流程

Cataclysm-DDA 怎么创建带 modinfo.json 的最小模组并让游戏识别它?

【免费下载链接】Cataclysm-DDACataclysm - Dark Days Ahead. A turn-based survival game set in a post-apocalyptic world.项目地址: https://gitcode.com/GitHub_Trending/ca/Cataclysm-DDA

Cataclysm-DDA(Cataclysm - Dark Days Ahead)的绝大多数二次开发是通过编辑 JSON 文件完成的,不需要重新编译游戏。如果你要做一个自己的模组,任务就是:在正确的模组目录里建一个文件夹,并在其中放入一个modinfo.json文件——根据 MODDING 指南,Cataclysm 只有在文件夹内存在modinfo.json时才会把该文件夹识别为一个模组。本文按官方文档走一遍这条路径:放置目录、最小modinfo.json写法、可选字段、内容 JSON 的放置位置,以及加载后如何判断模组是否被识别、出错了怎么看。

模组应该放在哪个目录

模组目录取决于模组是随游戏发行的还是第三方/私有模组(doc/MODDING.md):

  • 随 CDDA 发行的模组在data/mods,例如仓库中的 dda 核心模组、Only_Wildlife 模组;
  • 第三方/私有模组放在./mods(游戏安装目录内)或USER_DIR/mods

本文按第三方模组的常规做法走:在游戏安装目录的mods/下新建一个文件夹,文件夹名即模组的目录名。下面以文档中使用的my_mod为例。

创建最小 modinfo.json

在模组文件夹内创建modinfo.json。文档给出的最小可用内容是:

[ { "type": "MOD_INFO", "id": "Mod_ID", "name": "Mod's Display Name" } ]

这是识别模组的绝对下限。其中两个值需要你替换成自己的内容:id是模组的唯一标识,name是显示名称。对id文档给出了明确限制:

  • 不能与其他任何模组的id重复;
  • 不能包含#字符;
  • 必须是合法的文件夹路径(为兼容其他模组做依赖检查)。

如果你希望在 Mod Selection 菜单中展示更多信息,可以继续加authorsdescriptioncategory等字段。

按需填写 MOD_INFO 可选字段

doc/MODDING.md 列出了 MOD_INFO 支持的全部字段,一个带注释的完整示例:

[ { "type": "MOD_INFO", // Mandatory, you're making one of these! "id": "Mod_ID", // Mandatory, unique id for your mod. You should not use the same id as any other mod. Cannot contain the '#' character. Mod ids must also be valid folder pathing in order to support compatibility with other mods. "name": "Mod's Display Name", // Mandatory. "authors": [ "Me", "A really cool friend" ], // Optional, but you probably want to put your name here. More than one entry can be added, as shown. "description": "The best mod ever!", // Optional "category": "graphical", // Optional, see below for a full list of supported values. The category is just for information purposes, so don't worry if your mod might fit more than one category. "dependencies": [ "dda" ], // Optional. What other mods are required for this mod to function? If your mod depends on another one to work properly, adding that mod's `id` attribute to the array causes Cataclysm to force that mod to load before yours. "loading_images": [ "cool.png", "cool2.png" ], // Optional. Filenames for any loading screen images the mod may have. Loading screens are only present on the graphical/"tiles" version. Only supports .png files. Actual loading screen image will be picked randomly from among all mod loading screens, including other loaded mods that have loading screens. "disable_other_loading_screens": true, // Optional, default false. If set to true, only loading screens from this mod are used. "version": "1.3.bacon", // Optional. For informational purposes only. No versioning system is provided, so whatever you put here is up to you. Feel free to name your versions after ice cream. "core": false, // Optional, default false. Core mods will be loaded before anything else. Used for DDA, third-party use will not be supported. "obsolete": false, // Optional, default false. Obsolete mods are loaded for legacy saves but cannot be used when starting new worlds "path": "my_mod_files/" // Optional, this directory relative to modinfo.json's location will be considered the mod's actual directory. e.g. if modinfo.json is located at C:\CDDA\my_mod\modinfo.json, then the mod files would be considered to be at C:\CDDA\my_mod\my_mod_files\. A file such as C:\CDDA\my_mod\some_other_file.json would be ignored, it isn't located inside the specified directory. } ]

几个直接影响识别与加载行为的字段:

  • dependencies:数组中写其他模组的id,Cataclysm 会强制那些模组先于你的模组加载。基础游戏内容的模组iddda(见 data/mods/dda/modinfo.json),仓库里第三方模组普遍如此声明,例如 Only_Wildlife 的 modinfo 使用"dependencies": [ "dda" ]。如果你的模组依赖核心内容,建议加上"dda"
  • category:决定模组在 Mod Selection 菜单中出现在哪个分类。文档列出的可用取值有:contenttotal_conversionitemscreaturesmisc_additionsbuildingsvehiclesrebalancemagicalitem_excludemonster_excludegraphical。分类只是信息用途,一个模组符合多个分类也没关系。
  • path:可选。指定相对modinfo.json的目录作为模组实际目录;该目录之外的 JSON 文件会被忽略。不写这个字段时,模组文件夹内的 JSON 即被读取。

放入模组内容 JSON

建好modinfo.json后,把要加入游戏的内容写成 JSON 放进模组文件夹。文件结构上没有强制要求:模组文件夹及其子文件夹中的所有 JSON 文件都会被 Cataclysm 检测并读取,官方建议按内容类型拆分成不同的 JSON 文件(doc/MODDING.md 的 "File structure" 一节)。

具体能定义哪些内容(物品、职业、场景、怪物黑名单等)以 doc/JSON/JSON_INFO.md 为准。doc/MODDING.md本身也给了一份可直接复制的最低限度示例,比如在items.json中定义一个通用物品:

[ { "id": "family_photo", "type": "GENERIC", "//": "Unique mission item for the CITY_COP.", "category": "other", "name": "family photo", "description": "A photo of a smiling family on a camping trip. One of the parents looks like a cleaner, happier version of the person you know.", "weight": "1 g", "volume": 0, "price": "8 USD", "material": [ "paper" ], "symbol": "*", "color": "light_gray" } ]

基础游戏的数据同样用这套 JSON 定义,不确定字段写法时可以对照data/json下的核心游戏文件。

验证游戏是否识别模组

识别与加载的判定来自两处文档描述:

  1. Mod Selection 菜单category字段决定模组出现在模组选择菜单的哪个分类,即模组被成功识别后,你会在游戏启动时的 Mod Selection 菜单中按分类看到它。可以拿仓库里的现成模组对照确认格式,例如data/mods/Only_Wildlife/modinfo.json只有modinfo.json一个文件即可构成一个完整模组。
  2. 加载游戏世界时dependencies声明的依赖模组会被强制先加载。如果你的 JSON 有语法问题,文档的说明是:"If the game finds any issues in your JSON syntax when you try to load a game world, it will spit out an error message, and you won't be able to load that game until the issue is fixed." 也就是说验证动作是尝试加载世界:能加载说明 JSON 被正常读取;弹出错误信息则按报错定位到具体 JSON。

JSON 语法错误是这类模组最主要的坑

doc/MODDING.md 专门有一节 "Important note on json files":[ { , } ] : "这些字符在 JSON 中非常关键,漏掉一个逗号或括号就是"能用的文件"和"启动时卡死"的区别。两个文档给出的应对方法:

  • 如果需要把上述字符写进文本内容(比如在物品描述里放引号),用反斜杠转义:
    "description": "This is a shirt that says \"I wanna kill ALL the zombies\" on the front.",
  • 编辑器选择带括号配对检查的功能,且该功能要能正确处理转义字符。文档提到 Windows 上 Notepad++ 有该功能,Linux 上自行选择常用编辑器。

限制与边界

  • 识别一个模组的硬性条件就是文件夹内存在modinfo.jsonmodinfo.jsontypeidname三个字段必填,id唯一且不含#
  • core字段仅用于 DDA 核心模组,第三方模组使用不受支持。
  • loading_images只在图形/tiles 版本中有加载画面效果,且只支持.png
  • 模组能修改的只是 JSON 可表达的内容;哪些内容不能被模组修改,见 doc/MODDING.md 的 "That which cannot be modded" 一节,具体字段范围以 doc/JSON/JSON_INFO.md 为准。

下一步如果要往模组里加职业、场景、对话或调整怪物生成,doc/MODDING.md的 "Actually adding things to your mod" 一节提供了每种类型可直接复制的 JSON 片段,可以按同样方式追加到模组文件夹中。

【免费下载链接】Cataclysm-DDACataclysm - Dark Days Ahead. A turn-based survival game set in a post-apocalyptic world.项目地址: https://gitcode.com/GitHub_Trending/ca/Cataclysm-DDA

创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询