Tutorial:Mod structure: Difference between revisions

From Official Factorio Wiki
Jump to navigation Jump to search
(Created page with "Mods are expected to have a certain structure in order to be loaded by the game. This page aims to explain that file structure and what each file is used for. == Mod folder a...")
 
Line 100: Line 100:


:: <h4><span class="mw-headline" id="Dependency">Dependency</span></h4>
:: <h4><span class="mw-headline" id="Dependency">Dependency</span></h4>
:: Each dependency is a string that consists of up to three parts: <code>"<prefix> internal-mod-name <equality-operator version>"</code>, for example <code>"! SomeModEveryoneHates > 6.6.6"</code>. The possible prefixes are: <code>!</code> for incompatibility, <code>?</code> for an optional dependency, <code>(?)</code> for a hidden optional dependency or no prefix for a hard requirement for the other mod. The equality operator (<code><, <=, =, >= or ></code>) combined with the version allows to define dependencies that require certain mod versions.
:: Each dependency is a string that consists of up to three parts: <code>"<prefix> internal-mod-name <equality-operator version>"</code>, for example <code>"! SomeModEveryoneHates > 6.6.6"</code>. The possible prefixes are: <code>!</code> for incompatibility, <code>?</code> for an optional dependency, <code>(?)</code> for a hidden optional dependency or no prefix for a hard requirement for the other mod. The equality operator (<code><, <=, =, >= or ></code>) combined with the version allows to define dependencies that require certain mod versions, but it is not required.

Revision as of 20:27, 12 September 2019

Mods are expected to have a certain structure in order to be loaded by the game. This page aims to explain that file structure and what each file is used for.

Mod folder and file structure

The mod must either be in a folder, or in a folder inside a zip file. The mod folder/zip must be named in the pattern of {mod-name}_{version-number}, for example TestMod_0.0.1. When using a zip file for the mod, the folder inside the zip file does not have any naming restrictions; only the zip file itself must be named with the {mod-name}_{version-number} pattern. The mod name and its version number are defined in the info.json file.

Files

Inside the mod folder, the game automatically reads the following files during load:

  • info.json — The only mandatory file. The info.json identifies the mod, defines its version and other general properties.
  • changelog.txt — Version history of the mod, to be shown in the mod browser. The changelog file must follow the strict formatting requirements.
  • thumbnail.png — Thumbnail to be shown on the mod portal and in the mod browser in-game. Ideally a 144x144px image file.
  • settings.lua — This and the next two files are used to set up mod configuration options.
  • settings-updates.lua
  • settings-final-fixes.lua
  • data.lua — This and the next two files are used to define prototypes.
  • data-updates.lua — The load order of the three data*.lua files is explained on Data-Lifecycle.
  • data-final-fixes.lua
  • control.lua — This file is used for runtime scripting. Runtime scripting is documented on lua-api.factorio.com.

Subfolders

Furthermore, the following folders inside the mod folder are recognized by the game:

  • locale — Can contain up to one subfolder per language, identified with the language code, for example en for English. The subfolder then has to contain at least one *.cfg file which defines the translations for that language.
  • scenarios — Custom scenarios can be placed in subfolders of this folder.
  • tutorials — Custom tutorials can be placed in subfolders of this folder.
  • migrations — Migrations are a way to handle prototype changes and mod data structure changes between mod versions or game versions.

Example

Here is an example directory structure for a mod titled myArmorMod with a version number of 0.3.6:

myArmorMod_0.3.6.zip
|- aFolderName/
  |- control.lua
  |- data.lua
  |- info.json
  |- thumbnail.png

info.json

The info.json file identifies the mod and defines its version. If the game encounters a problem when parsing the file, the error message can be found in the log file. A minimal info.json file can look like this:

   {
     "name": "TestMod",
     "version": "0.0.1",
     "title": "My best test mod",
     "author": "A very great tester",
     "factorio_version": "0.17"
   }

The info.json file supports the following fields:

name

Type: string
Mandatory field. The internal name of mod. The game accepts anything as a mod name, however the mod portal restricts mod names to only consist of alphanumeric characters, dashes and underscores. Note that the mod folder or mod zip file name has to contain the mod name, where the restrictions of the file system apply.

version

Type: string
Mandatory field. Defines the version of the mod in the format "number.number.number" for "main.major.minor", for example "0.6.4". Each number can range from 0 to 65535.

title

Type: string
Mandatory field. The display name of the mod, so don't use someUgly_programmer-name here. Can be overwritten with a locale entry in the mod-name category, using the internal mod name as the key.

author

Type: string
Mandatory field. The author of the mod. Hopefully you.

contact

Type: string
Optional field. How the mod author can be contacted, for example an email address. Or maybe your house's address. Don't get robbed.

homepage

Type: string
Optional field. Where the mod can be found on the internet. Note that the in-game mod browser shows the mod portal link additionally to this field. Please don't put "None" here, it makes the field on the mod portal website look ugly. Just leave the field empty if your mod doesn't have a website/forum thread/discord.

description

Type: string
Optional field. A short description of what your mod does. This is all that people get to see in-game, so better make your mod sound appealing. Can be overwritten with a locale entry in the mod-description category, using the internal mod name as the key.

factorio_version

Type: string
Default: "0.12"
Optional field. The major Factorio version that this mod supports. No you can't have more than one version here. Yes, the field is optional, but we have 0.17, not the default 0.12, so you'll have to add the field anyway. Adding a minor version, e.g. "0.17.67" will make the mod portal reject the mod and the game act weirdly. That means you shouldn't do that; use only main and major version "main.major", for example "0.17".

dependencies

Type: array of #Dependency
Default: ["base"]
Mods that this mod depends on or is incompatible with. If this mod depends on another, the other mod will load first, see Data-Lifecycle. An empty array allows get around the default and have no dependencies at all.

Dependency

Each dependency is a string that consists of up to three parts: "<prefix> internal-mod-name <equality-operator version>", for example "! SomeModEveryoneHates > 6.6.6". The possible prefixes are: ! for incompatibility, ? for an optional dependency, (?) for a hidden optional dependency or no prefix for a hard requirement for the other mod. The equality operator (<, <=, =, >= or >) combined with the version allows to define dependencies that require certain mod versions, but it is not required.