切换语言: Deutsch English Русский

Modding overview

From Official Factorio Wiki
Revision as of 19:19, 3 February 2017 by Bilka (talk | contribs) (removed links to soon to be deleted pages)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

(本文是业余翻译翻译的,此条目尚在翻译中,先凑合着看) 皆在大致阐述 0.8.x 版本的MOD:


TL;DR

For users: 只要正确安装了MOD,并且把MOD放到了 mods 子目录内, 无论是未压缩的还是zip格式的. 游戏都会自动搜索并将其加入modlist(MOD列表). 你可以手动编译 mods/mod-list.json ,或者通过游戏中的图形用户界面(在主菜单→MODS选项).

For developers: 新手请参阅 __read_data__/base 这个文件/夹里面的MOD,是一个很好地示范(info.json, data.lua, locale, etc.)


Mods directory

每一个MOD都是独立的(至少做到目录上独立)。 所有MOD都放在这个目录下: __write_data__/mods 。 __write_data__ part is different based on your operating system (it is the same as for the saves directory). 在 Linux 中 mods 目录在:~/.factorio/mods. 在 OSX 目录变为:~/Library/Application\ Support/factorio/mods. 在 Windows 7 目录变为 C:\Users\<username>\AppData\Roaming\Factorio\mods, but you can type %appdata%\Factorio\mods 也可以通过这个文件夹更快的到达 (安装文件夹) C:\Program Files\Factorio 有一个快捷方式到文件夹,如果你在64位win7上安装了32位版本的Factorio ,目录将变为:C:\Program Files (x86)\Factorio. When using the zip package, the __write_data__ is located in the Factorio directory, both saves mods scenarios and player data is directly in the factorio folder.

Modlist

mods overview 通常写在这个文件里: mods/mod-list.json。 关于这些MOD的顺序。MOD越晚加入列表就越晚被游戏载入。Also when running mod scripts the scripts of earlier mods are run before the latter ones. The mods settings are loaded on the game startup.只有被打上 "enable" 标记的MOD才会随游戏运行。凡在mods(目录)下的MOD,都会在游戏启动时自动录入mods列表(加入列表的最后一行)。在 Other settings 中有一个值可以设置是否自动录入mods中尚未登记的MOD. MOD的设置可以通过MODS菜单改变(主目录 > Mods)。你可以启用、禁用MOD,并改变其在列表的排序。设置将在游戏重启后生效。

Mod structure

一个MOD由一个包含info.json文件的目录(详见下一章)和MOD的其他内容组成。 一个规范的MOD目录名由:MOD名称+下划线+版本号组成(since 0.10.7, see http://www.factorioforums.com/forum/viewtopic.php?f=14&t=5364)。 MOD的名称和版本必须和这个MOD目录下的info.json文件内的定义相匹配(切记)。

MOD名称建议格式是小写的,由短划线分隔的单词。如果拿不定注意,请参照group-of-mods_module 这个格式。

MOD结构的例子:

foo_0.1.5
  |- info.json (必须将名字设置为"foo" 且版本号为"0.1.5")
  |- ...
  |- 任何有关于MOD的内容
  |- ...

MOD也可以存储在一个压缩文件(仅允许Deflate压缩方法)。 zip文件名必须遵循同样的规则,并保证目录名正确且含有扩展名“.zip”是小写。 压缩文件内必须包含MOD全部内容(不能分包压缩)。目录的名字并不重要,但建议遵循MOD的命名原则。

例子:zipped格式的MOD结构

foo_0.1.5.zip
  |- foo_0.1.5
       |- info.json (必须将名字设置为"foo" 且版本号为"0.1.5")
       |- ...
       |- 任何有关于MOD的内容
       |- ...


Mod meta information

每一个MOD需要提供一定的元信息。还是用刚才的名字为“foo”的MOD来打比方:如果MOD的元信息存储在 mods/foo-mod/info.json 文件中。文件内容应该(按顺序)包含这些元素:name*, author*, version*, title*, homepage, description, dependencies (0.4版本以上).有星号的是必需的。"name"元素的值必须和当下目录名称相符。版本字段格式为“这里x.y.z“X是主版本号,Y是中间的版本号,和Z是次要版本号”(0.4增加了次要版本号)。"dependencies"元素首先要设定"base"MOD——如果你是用的是0.4.1或更高级版本,任何一个版本的MOD都要有一个 "scenario-pack",如果想使用"bar" MOD则必须是0.3版本(究竟是高于还是低于这个版本,原文没有明示)。 如果没有指定“dependencies ”元素,则值将默认定为["base"] (至少要一个任何版本的 “base” MOD)

示例:

{
  "name": "foo-mod",
  "version": "0.1.0",
  "title": "Foo Mod",
  "author": "Factorio team",
  "contact": "dev@factorio.com",
  "homepage": "http://factorio.com",
  "description": "Basic mod with all the default game data and standard campaign.",
  "dependencies": ["base >= 0.4.1", "scenario-pack", "? bar = 0.3"]
}

Prototype definitions

MOD能添加现有的“实体”(prototypes)并且能在foo-mod/data.lua 文件里编辑现有的“实体”(prototypes)。 All the data.lua files across different mods are run in the ordering defined by the mods. Afterwards the prototype definitions are retrieved from the data.raw table. The format of the data in here is that data.raw is a map indexed by prototype types and values are maps indexed by names with values being prototype tables. However preffered way is to use a predefined extend method on the data variable.

例子:

添加新的定义:

 data:extend(
 {
   {
     type="ammo",
     name="piercing-bullet-magazine",
     ...
   },
   {
     type="ammo",
     name="flame-thrower-ammo",
     ...
   }
 })

改变现有的定义:

   data.raw.ammo["piercing-bullet-magazine"].magazine_size = 20

这和在json 文件里的做法很相似。基本上每一个prototype(“实体”) 在lua table(lua表)中都有一个专属名字。所有的prototypes都会录入global table(全局表)

Mod scripts

每一个MOD都可以包含一个control.lua 脚本。如果游戏启动,首先执行 scenario 脚本,随后执行所有的MOD的control.lua 脚本。这使得MOD在嵌入游戏时不污染源文件(参看 freeplay.lua).

Locale

游戏会从MOD的目录为MOD添加语言环境(例如:mods/foo-mod/locale)。必须按特定的格式规划locale目录(至少要有两个含有不同语言环境的文件夹,还要含有.cfg文件)。设定好的语言环境会整合到游戏中。The locale for a mod control.lua script can be placed in the script-locale directory (每一个语言都要具有一个正确格式的 .cfg 文件).

Base mod

如果有MOD支持了游戏运行的全部必要信息,那就非“base mod”莫属。 “base mod”已经不在__write_data__目录了,而是放置在__read_data__目录。例如在Windows系统下,目录在C:/Program Files/Factorio/data/base。 “base mod”可以被关掉,但是它包含了游戏必要的要素(目前没有MOD可以取代)。它负责维护人物、物品、地图。如果你能重写一个“base mod”你就可以放心大胆的禁用原版的“base mod”了(当然我也不保证啥乱子都不出:))。