AddonStructure

From Wesnoth


In order to create custom content for Wesnoth, you need to set up a folder in userdata/data/add-ons/. If you have not found your userdata directory yet, read EditingWesnoth and come back here. This page will explain the basic directory structure of an add-on and where stuff goes.

Several pages on this wiki will assume you have done so and refer to relative paths in such.

The Main File

For this example, we will assume you are creating an add-on called A Simple Addon.

  • Create the empty directory userdata/data/add-ons/A_Simple_Addon.

Important: Remember to use underscores in all directory and file names instead of spaces. Failure to do so will result in your content not working properly.

  • Create a file called _main.cfg inside the A_Simple_Addon folder.

The _main.cfg file will instruct the game on how to load your content. Here is shown a very simple example of the file.

#textdomain wesnoth-A_Simple_Addon
[textdomain]
    name="wesnoth-A_Simple_Addon"
    path="data/add-ons/A_Simple_Addon/translations"
[/textdomain]

#ifdef MULTIPLAYER
[binary_path]
    path=data/add-ons/A_Simple_Addon
[/binary_path]

{~add-ons/A_Simple_Addon/scenarios}
#endif

The [textdomain] WML tag specifies where the game should look for translations to the strings in the add-on. The textdomain should be the add-on's directory name prefixed with "wesnoth-", to ensure that it does not conflict with other textdomains that might be specified on a given system and is compatible with WesCamp.

Note: A textdomain is only required if your add-on contains text meant to be translated. In the case of, for example, a music pack, no textdomain is needed.

All tags save for [campaign] and [textdomain] must be enclosed in an #ifdef preprocessor conditional - including those substituted through inclusion (see PreprocessorRef for more information). This is to make sure your content only loads at the correct time and does not conflict with other add-ons. In the example above, the scenarios will be loaded when you enter multiplayer mode. In a campaign, you can set up a specific flag to allow your content to only load when that campaign is played.

Note: Only code must be included from this file. You do not need to include binary content (such as sounds, images, or music). Those may be referred to simply by path relative to the one specified in [binary_path]. Also, including the units directory cannot be done by a simple path inclusion; it also must be wrapped in a [+units][/units] (the + is very important!) tag pair, as such:

[+units]
    {~add-ons/A_Simple_Addon/units}
[/units]

The Directory Structure

What to create next depend on what type of content you are creating. For example, campaigns or map packs will have scenarios and maps directories, while a music pack would have only music. Here we will assume you are creating a campaign or single-scenario add-on.

Create the following directories:

  • userdata/data/add-ons/A_Simple_Addon/scenarios
  • userdata/data/add-ons/A_Simple_Addon/maps

All map files used in scenarios go in maps (see BuildingMaps. All configuration (‘.cfg’) files for scenarios go in scenarios (see BuildingScenarios).

If you have additional custom content such as images or units, create the respective following:

  • userdata/data/add-ons/A_Simple_Addon/macros
  • userdata/data/add-ons/A_Simple_Addon/units
  • userdata/data/add-ons/A_Simple_Addon/images
  • userdata/data/add-ons/A_Simple_Addon/music
  • userdata/data/add-ons/A_Simple_Addon/sounds

Important: You may name the directories containing code (such as scenarios and macros) anything you like, but the three binary content directories (images, music, and sounds) must be named as such and be relative to your [binary_path]. This is because when trying to resolve an image path, Wesnoth will look under images/, and likewise for sounds and music, in [binary_path].

If you set up a textdomain, create a translations directory, even if it remains empty. Failure to do so generates a warning in stderr. This path must be the same as specified in the [textdomain] tag.

  • userdata/data/add-ons/A_Simple_Addon/translations

See also

This page was last modified on 16 March 2014, at 17:45.