<spanid="evennia-contrib-mapbuilder"></span><h1>evennia.contrib.mapbuilder<aclass="headerlink"href="#module-evennia.contrib.mapbuilder"title="Permalink to this headline">¶</a></h1>
<p>Evennia World Builder</p>
<p>Contribution - Cloud_Keeper 2016</p>
<p>Build a map from a 2D ASCII map.</p>
<p>This is a command which takes two inputs:</p>
<p>≈≈≈≈≈
≈♣n♣≈ MAP_LEGEND = {(“♣”, “♠”): build_forest,
≈∩▲∩≈ (“∩”, “n”): build_mountains,
≈♠n♠≈ (“▲”): build_temple}
≈≈≈≈≈</p>
<p>A string of ASCII characters representing a map and a dictionary of functions
containing build instructions. The characters of the map are iterated over and
compared to a list of trigger characters. When a match is found the
corresponding function is executed generating the rooms, exits and objects as
defined by the users build instructions. If a character is not a match to
a provided trigger character (including spaces) it is simply skipped and the
process continues.</p>
<p>For instance, the above map represents a temple (▲) amongst mountains (n,∩)
in a forest (♣,♠) on an island surrounded by water (≈). Each character on the
first line is iterated over but as there is no match with our MAP_LEGEND it
is skipped. On the second line it finds “♣” which is a match and so the
<strong>build_forest</strong> function is called. Next the <strong>build_mountains</strong> function is
called and so on until the map is completed. Building instructions are passed
the following arguments:</p>
<blockquote>
<div><p>x - The rooms position on the maps x axis
y - The rooms position on the maps y axis
caller - The account calling the command
iteration - The current iterations number (0, 1 or 2)
room_dict - A dictionary containing room references returned by build</p>
<blockquote>
<div><p>functions where tuple coordinates are the keys (x, y).
ie room_dict[(2, 2)] will return the temple room above.</p>
</div></blockquote>
</div></blockquote>
<p>Building functions should return the room they create. By default these rooms
are used to create exits between valid adjacent rooms to the north, south,
east and west directions. This behaviour can turned off with the use of switch
arguments. In addition to turning off automatic exit generation the switches
allow the map to be iterated over a number of times. This is important for
something like custom exit building. Exits require a reference to both the
exits location and the exits destination. During the first iteration it is
possible that an exit is created pointing towards a destination that
has not yet been created resulting in error. By iterating over the map twice
the rooms can be created on the first iteration and room reliant code can be
be used on the second iteration. The iteration number and a dictionary of
references to rooms previously created is passed to the build commands.</p>
<p>Use by importing and including the command in your default_cmdsets module.
For example:</p>
<blockquote>
<div><p># mygame/commands/default_cmdsets.py</p>
<p>from evennia.contrib import mapbuilder</p>
<p>…</p>
<p>self.add(mapbuilder.CmdMapBuilder())</p>
</div></blockquote>
<p>You then call the command in-game using the path to the MAP and MAP_LEGEND vars
The path you provide is relative to the evennia or mygame folder.</p>
<codeclass="sig-prename descclassname">evennia.contrib.mapbuilder.</code><codeclass="sig-name descname">example1_build_forest</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">x</span></em>, <emclass="sig-param"><spanclass="n">y</span></em>, <emclass="sig-param"><spanclass="o">**</span><spanclass="n">kwargs</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/contrib/mapbuilder.html#example1_build_forest"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.contrib.mapbuilder.example1_build_forest"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-prename descclassname">evennia.contrib.mapbuilder.</code><codeclass="sig-name descname">example1_build_mountains</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">x</span></em>, <emclass="sig-param"><spanclass="n">y</span></em>, <emclass="sig-param"><spanclass="o">**</span><spanclass="n">kwargs</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/contrib/mapbuilder.html#example1_build_mountains"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.contrib.mapbuilder.example1_build_mountains"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-prename descclassname">evennia.contrib.mapbuilder.</code><codeclass="sig-name descname">example1_build_temple</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">x</span></em>, <emclass="sig-param"><spanclass="n">y</span></em>, <emclass="sig-param"><spanclass="o">**</span><spanclass="n">kwargs</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/contrib/mapbuilder.html#example1_build_temple"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.contrib.mapbuilder.example1_build_temple"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-prename descclassname">evennia.contrib.mapbuilder.</code><codeclass="sig-name descname">example2_build_forest</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">x</span></em>, <emclass="sig-param"><spanclass="n">y</span></em>, <emclass="sig-param"><spanclass="o">**</span><spanclass="n">kwargs</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/contrib/mapbuilder.html#example2_build_forest"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.contrib.mapbuilder.example2_build_forest"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-prename descclassname">evennia.contrib.mapbuilder.</code><codeclass="sig-name descname">example2_build_verticle_exit</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">x</span></em>, <emclass="sig-param"><spanclass="n">y</span></em>, <emclass="sig-param"><spanclass="o">**</span><spanclass="n">kwargs</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/contrib/mapbuilder.html#example2_build_verticle_exit"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.contrib.mapbuilder.example2_build_verticle_exit"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-prename descclassname">evennia.contrib.mapbuilder.</code><codeclass="sig-name descname">example2_build_horizontal_exit</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">x</span></em>, <emclass="sig-param"><spanclass="n">y</span></em>, <emclass="sig-param"><spanclass="o">**</span><spanclass="n">kwargs</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/contrib/mapbuilder.html#example2_build_horizontal_exit"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.contrib.mapbuilder.example2_build_horizontal_exit"title="Permalink to this definition">¶</a></dt>
<emclass="property">class </em><codeclass="sig-prename descclassname">evennia.contrib.mapbuilder.</code><codeclass="sig-name descname">CmdMapBuilder</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="o">**</span><spanclass="n">kwargs</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/contrib/mapbuilder.html#CmdMapBuilder"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.contrib.mapbuilder.CmdMapBuilder"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">key</code><emclass="property"> = '@mapbuilder'</em><aclass="headerlink"href="#evennia.contrib.mapbuilder.CmdMapBuilder.key"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">aliases</code><emclass="property"> = ['@buildmap']</em><aclass="headerlink"href="#evennia.contrib.mapbuilder.CmdMapBuilder.aliases"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">locks</code><emclass="property"> = 'cmd:superuser()'</em><aclass="headerlink"href="#evennia.contrib.mapbuilder.CmdMapBuilder.locks"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">help_category</code><emclass="property"> = 'building'</em><aclass="headerlink"href="#evennia.contrib.mapbuilder.CmdMapBuilder.help_category"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">func</code><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/contrib/mapbuilder.html#CmdMapBuilder.func"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.contrib.mapbuilder.CmdMapBuilder.func"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">lock_storage</code><emclass="property"> = 'cmd:superuser()'</em><aclass="headerlink"href="#evennia.contrib.mapbuilder.CmdMapBuilder.lock_storage"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">search_index_entry</code><emclass="property"> = {'aliases': '@buildmap', 'category': 'building', 'key': '@mapbuilder', 'tags': '', 'text': '\n Build a map from a 2D ASCII map.\n\n Usage:\n @mapbuilder[/switch] <path.to.file.MAPNAME><path.to.file.MAP_LEGEND>\n\n Switches:\n one - execute build instructions once without automatic exit creation\n two - execute build instructions twice without automatic exit creation\n\n Example:\n @mapbuilder world.gamemap.MAP world.maplegend.MAP_LEGEND\n @mapbuilder evennia.contrib.mapbuilder.EXAMPLE1_MAP EXAMPLE1_LEGEND\n @mapbuilder/two evennia.contrib.mapbuilder.EXAMPLE2_MAP EXAMPLE2_LEGEND\n (Legend path defaults to map path)\n\n This is a command which takes two inputs:\n A string of ASCII characters representing a map and a dictionary of\n functions containing build instructions. The characters of the map are\n iterated over and compared to a list of trigger characters. When a match\n is found the corresponding function is executed generating the rooms,\n exits and objects as defined by the users build instructions. If a\n character is not a match to a provided trigger character (including spaces)\n it is simply skipped and the process continues. By default exits are\n automatically generated but is turned off by switches which also determines\n how many times the map is iterated over.\n '}</em><aclass="headerlink"href="#evennia.contrib.mapbuilder.CmdMapBuilder.search_index_entry"title="Permalink to this definition">¶</a></dt>