evennia.contrib.grid.ingame_map_display.ingame_map_display¶
Basic Map - helpme 2022
This adds an ascii map to a given room which can be viewed with the map command. You can easily alter it to add special characters, room colors etc. The map shown is dynamically generated on use, and supports all compass directions and up/down. Other directions are ignored.
If you don’t expect the map to be updated frequently, you could choose to save the calculated map as a .ndb value on the room and render that instead of running mapping calculations anew each time.
An example map:
- -[-]-
- -[-]–[-]–[-]–[-]
- | | | | | | -[-]–[-] [-] | / | | | /| -[-]–[-]
Installation:
Adding the MapDisplayCmdSet to the default character cmdset will add the map command.
Specifically, in mygame/commands/default_cmdsets.py:
… from evennia.contrib.grid.ingame_map_display import MapDisplayCmdSet # <—
- class CharacterCmdset(default_cmds.Character_CmdSet):
… def at_cmdset_creation(self):
… self.add(MapDisplayCmdSet) # <—
Then reload to make the new commands available.
Additional Settings:
In order to change your default map size, you can add to mygame/server/settings.py:
BASIC_MAP_SIZE = 5
This changes the default map width/height. 2-5 for most clients is sensible.
If you don’t want the player to be able to specify the size of the map, ignore any arguments passed into the Map command.
-
class
evennia.contrib.grid.ingame_map_display.ingame_map_display.
Map
(caller, size=2, location=None)[source]¶ Bases:
object
-
__init__
(caller, size=2, location=None)[source]¶ Initializes the map.
- Parameters
caller (object) – Any object, though generally a puppeted character.
size (int) – The seed size of the map, which will be multiplied to get the final grid size.
location (object) – The location at the map’s center (will default to caller.location if none provided).
-
create_grid
()[source]¶ Create the empty grid for the map based on the configured size
- Returns
list – The created grid, a list of lists.
-
exit_name_as_ordinal
(ex)[source]¶ Get the exit name as a compass direction if possible
- Parameters
ex (Exit) – The current exit being mapped.
- Returns
string – The exit name as a compass direction or an empty string.
-
update_pos
(room, exit_name)[source]¶ Update the position pointer.
- Parameters
room (Room) – The current location.
exit_name (str) – The name of the exit to to use in this room. This must be a valid compass direction, or an error will be raised.
- Raises
KeyError – If providing a non-compass exit name.
-
has_drawn
(room)[source]¶ Checks if the given room has already been drawn or not
- Parameters
room (Room) – Room to check.
- Returns
bool – Whether or not the room has been drawn.
-
draw_room_on_map
(room, max_distance)[source]¶ Draw the room and its exits on the map recursively
- Parameters
room (Room) – The room to draw out.
max_distance (int) – How extensive the map is.
-
draw_exits
(room)[source]¶ Draw a given room’s exit paths
- Parameters
room (Room) – The room to draw exits of.
-
draw
(room)[source]¶ Draw the map starting from a given room and add it to the cache of mapped rooms
- Parameters
room (Room) – The room to render.
-
render_room
(room, x, y, p1='[', p2=']', here=None)[source]¶ Draw a given room with ascii characters
- Parameters
room (Room) – The room to render.
x (int) – The x-value of the room on the grid (horizontally, east/west).
y (int) – The y-value of the room on the grid (vertically, north/south).
p1 (str) – The first character of the 3-character room depiction.
p2 (str) – The last character of the 3-character room depiction.
here (str) – Defaults to none, a special character depicting the room.
-
-
class
evennia.contrib.grid.ingame_map_display.ingame_map_display.
CmdMap
(**kwargs)[source]¶ Bases:
evennia.commands.default.muxcommand.MuxCommand
Check the local map around you.
Usage: map (optional size)
-
key
= 'map'¶
-
func
()[source]¶ This is the hook function that actually does all the work. It is called by the cmdhandler right after self.parser() finishes, and so has access to all the variables defined therein.
-
aliases
= []¶
-
help_category
= 'general'¶
-
lock_storage
= 'cmd:all();'¶
-
search_index_entry
= {'aliases': '', 'category': 'general', 'key': 'map', 'no_prefix': ' ', 'tags': '', 'text': '\n Check the local map around you.\n\n Usage: map (optional size)\n '}¶
-
-
class
evennia.contrib.grid.ingame_map_display.ingame_map_display.
MapDisplayCmdSet
(cmdsetobj=None, key=None)[source]¶ Bases:
evennia.commands.cmdset.CmdSet
The map command.
-
at_cmdset_creation
()[source]¶ Hook method - this should be overloaded in the inheriting class, and should take care of populating the cmdset by use of self.add().
-
path
= 'evennia.contrib.grid.ingame_map_display.ingame_map_display.MapDisplayCmdSet'¶
-