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)[源代码]¶ 基类:
object
-
__init__
(caller, size=2, location=None)[源代码]¶ Initializes the map.
- 参数
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
()[源代码]¶ Create the empty grid for the map based on the configured size
- 返回
list – The created grid, a list of lists.
-
exit_name_as_ordinal
(ex)[源代码]¶ Get the exit name as a compass direction if possible
- 参数
ex (Exit) – The current exit being mapped.
- 返回
string – The exit name as a compass direction or an empty string.
-
update_pos
(room, exit_name)[源代码]¶ Update the position pointer.
- 参数
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.
- 引发
KeyError – If providing a non-compass exit name.
-
has_drawn
(room)[源代码]¶ Checks if the given room has already been drawn or not
- 参数
room (Room) – Room to check.
- 返回
bool – Whether or not the room has been drawn.
-
draw_room_on_map
(room, max_distance)[源代码]¶ Draw the room and its exits on the map recursively
- 参数
room (Room) – The room to draw out.
max_distance (int) – How extensive the map is.
-
draw
(room)[源代码]¶ Draw the map starting from a given room and add it to the cache of mapped rooms
- 参数
room (Room) – The room to render.
-
render_room
(room, x, y, p1='[', p2=']', here=None)[源代码]¶ Draw a given room with ascii characters
- 参数
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)[源代码]¶ 基类:
evennia.commands.default.muxcommand.MuxCommand
Check the local map around you.
Usage: map (optional size)
-
key
= 'map'¶
-
func
()[源代码]¶ 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)[源代码]¶ 基类:
evennia.commands.cmdset.CmdSet
The map command.
-
at_cmdset_creation
()[源代码]¶ 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'¶
-