Difference between revisions of "AddonStructure"

From The Battle for Wesnoth Wiki
(Created page with "In order to create custom content for Wesnoth, you need to set up a folder in <i>userdata</i>/data/add-ons/. If you have not found your userdata directory yet, read EditingW...")
 
(The Main File: Use syntax highlighting)
 
(14 intermediate revisions by 4 users not shown)
Line 1: Line 1:
 +
{{Translations}}
 +
{{Create}}
 +
 
In order to create custom content for Wesnoth, you need to set up a folder in <i>userdata</i>/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.
 
In order to create custom content for Wesnoth, you need to set up a folder in <i>userdata</i>/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.
  
Line 5: Line 8:
 
== The Main File ==
 
== The Main File ==
  
For this example, we will assume your are creating an add-on called <b>Valen</b>.
+
For this example, we will assume you are creating an add-on called <b>A Simple Addon</b>.
  
*Create the empty directory <b><i>userdata</i>/data/add-ons/Valen</b>.
+
*Create the empty directory <b><i>userdata</i>/data/add-ons/A_Simple_Addon</b>.
*Create a file called <b>_main.cfg</b> inside the Valen folder.
 
  
The _main.cfg file will instruct the game on how to load your content. This example simply shows a very simple example of the file.
+
<b>Important:</b> 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.
  
#textdomain wesnoth-valen
+
*Create a file called <b>_main.cfg</b> inside the A_Simple_Addon folder.
[textdomain]
 
    name="wesnoth-valen"
 
[/textdomain]
 
 
[binary_path]
 
    path=data/add-ons/Valen
 
[/binary_path]
 
 
{~add-ons/Valen/scenarios}
 
  
There are many other things you can put in your _main.cfg, such as a [campaign] tag if you're creating a campaign and want it to appear in the campaign list, or even nothing if you're distributing a resource pack. The important thing to remember is that this file is the "glue" that holds custom content together. The game looks at this file, and only this file, and follows the instructions within for loading whatever code you have created.  
+
The _main.cfg file will instruct the game on how to load your content. Here is shown a very simple example of the file.
  
<b>Note:</b> Only <b>code</b> must be included from this file. You <b>do not</b> need to include resources such as sounds, images, or music. Those may be referred to simply by path as long as [binary_path] is set up.
+
<syntaxhighlight lang=wml>
 +
#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
 +
</syntaxhighlight>
 +
 
 +
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 <b>"wesnoth-"</b>, to ensure that it does not conflict with other textdomains that might be specified on a given system and is compatible with [[WesCamp]].
 +
 
 +
<b>Note:</b> 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] <b>must</b> be enclosed in an <b>#ifdef</b> 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.
 +
 
 +
<b>Note:</b> Only <b>code</b> must be included from this file. You <b>do not</b> 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 <b>units</b> directory cannot be done by a simple path inclusion; it also must be wrapped in a <b>[units][/units]</b> tag pair, as such:
 +
 
 +
<syntaxhighlight lang=wml>
 +
[units]
 +
    {~add-ons/A_Simple_Addon/units}
 +
[/units]
 +
</syntaxhighlight>
  
 
== The Directory Structure ==
 
== The Directory Structure ==
Line 33: Line 54:
 
Create the following directories:
 
Create the following directories:
  
*<b><i>userdata</i>/data/add-ons/Valen/scenarios</b>
+
*<b><i>userdata</i>/data/add-ons/A_Simple_Addon/scenarios</b>
*<b><i>userdata</i>/data/add-ons/Valen/maps</b>
+
*<b><i>userdata</i>/data/add-ons/A_Simple_Addon/maps</b>
  
 
All map files used in scenarios go in <b>maps</b> (see [[BuildingMaps]]. All configuration (‘.cfg’) files for scenarios go in <b>scenarios</b> (see [[BuildingScenarios]]).  
 
All map files used in scenarios go in <b>maps</b> (see [[BuildingMaps]]. All configuration (‘.cfg’) files for scenarios go in <b>scenarios</b> (see [[BuildingScenarios]]).  
  
If you have additional custom content such as custom images or units, create the respective following:
+
If you have additional custom content such as images or units, create the respective following:
 +
 
 +
*<b><i>userdata</i>/data/add-ons/A_Simple_Addon/macros</b>
 +
*<b><i>userdata</i>/data/add-ons/A_Simple_Addon/units</b>
 +
*<b><i>userdata</i>/data/add-ons/A_Simple_Addon/images</b>
 +
*<b><i>userdata</i>/data/add-ons/A_Simple_Addon/music</b>
 +
*<b><i>userdata</i>/data/add-ons/A_Simple_Addon/sounds</b>
  
*<b><i>userdata</i>/data/add-ons/Valen/macros</b>
+
<b>Important:</b> You may name the directories containing code (such as <b>scenarios</b> and <b>macros</b>) anything you like, but the three binary content directories (<b>images</b>, <b>music</b>, and <b>sounds</b>) <b>must</b> 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].
*<b><i>userdata</i>/data/add-ons/Valen/units</b>
 
*<b><i>userdata</i>/data/add-ons/Valen/images</b>
 
*<b><i>userdata</i>/data/add-ons/Valen/sounds</b>
 
*<b><i>userdata</i>/data/add-ons/Valen/music</b>
 
  
It is also a good idea, if you set up a textdomain, to create this directory, even if it remains empty. Failure to do so generates a warning internally.
+
If you set up a textdomain, create a <b>translations</b> directory, even if it remains empty. Failure to do so generates a warning in stderr. This path <b>must</b> be the same as specified in the [textdomain] tag.
  
*<b><i>userdata</i>/data/add-ons/Valen/translations</b>
+
*<b><i>userdata</i>/data/add-ons/A_Simple_Addon/translations</b>
  
 
==See also==
 
==See also==

Latest revision as of 04:38, 25 August 2019


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] 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 edited on 25 August 2019, at 04:38.