init.lua

World initialization for the editor. All world entities are loaded via this file. In a game, world entities are loaded on demand using their register.lua files. See Defining Units for more details.

This file also defines the editor categories for world elements like terrains or immovables so that they will be added to their respective editor tools (Place Terrain, Place Immovable etc.).

Returns a table with 4 keys:

  • critters: A table of editor categories for placing animals in the editor

  • immovables: A table of editor categories for placing immovables in the editor

  • resources: A list of all resources: { "resource_coal", "resource_gold", ... }

  • terrains: A table of editor categories for placing terrains in the editor

For making the editor category names translatable, we also need to push/pop the correct textdomain.

An editor category has the following table entries:

name

Mandatory. A string containing the internal name of this editor category for reference by UI code, e.g.:

name = "summer",
descname

Mandatory. The translatable display name, e.g.:

descname = _("Summer"),
picture

Mandatory. An image to represent this category in the editor tool’s tab, e.g.:

picture = "world/pics/editor_terrain_category_green.png",
items_per_row

Mandatory. How many items will be displayed in each row by the tool, e.g.:

items_per_row = 6,

Example:

push_textdomain("world")

local result = {
   -- Items shown in the place critter tool. Each subtable is a tab in the tool.
   critters = {
      {
         name = "critters_herbivores",
         descname = _("Herbivores"),
         picture = "world/critters/sheep/menu.png",
         items_per_row = 10,
         items = {
            "bunny",
            "sheep",
         }
      },
      {
         name = "critters_carnivores",
         descname = _("Carnivores"),
         picture = "world/critters/fox/menu.png",
         items_per_row = 10,
         items = {
            "marten",
            "badger",
            "lynx",
            "fox",
            "wolf",
            "brownbear",
         }
      },
      ...
   },

   -- Items shown in the place immovable tool. Each subtable is a tab in the tool.
   immovables = {
      {
         name = "immovables_miscellaneous",
         ...
      },
      ...
   },

   -- Items shown in the set resources tool.
   resources = {
      "resource_coal",
      "resource_gold",
      "resource_iron",
      "resource_stones",
      "resource_water",
      "resource_fish",
   },

   -- Items shown in the place terrain tool. Each subtable is a tab in the tool.
   terrains = {
      {
         name = "terrains_summer",
         ...
      },
      ...
   }
}
pop_textdomain()
return result