mirror of
https://github.com/evennia/evennia.git
synced 2026-03-25 09:16:32 +01:00
Add xymap options
This commit is contained in:
parent
0686414d0f
commit
25781b27d7
3 changed files with 54 additions and 26 deletions
|
|
@ -28,7 +28,8 @@ PARENT = {
|
|||
"key": "An empty room",
|
||||
"prototype_key": "xyzmap_room_map1",
|
||||
"typeclass": "evennia.contrib.xyzgrid.xyzroom.XYZRoom",
|
||||
"desc": "An empty room."
|
||||
"desc": "An empty room.",
|
||||
"options": {}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -259,7 +260,11 @@ XYMAP_DATA_MAP2 = {
|
|||
"map": MAP2,
|
||||
"zcoord": "the small cave",
|
||||
"legend": LEGEND_MAP2,
|
||||
"prototypes": PROTOTYPES_MAP2
|
||||
"prototypes": PROTOTYPES_MAP2,
|
||||
"options": {
|
||||
"map_visual_range": 1,
|
||||
"map_mode": 'scan'
|
||||
}
|
||||
}
|
||||
|
||||
# This is read by the parser
|
||||
|
|
|
|||
|
|
@ -117,7 +117,7 @@ _CACHE_DIR = settings.CACHE_DIR
|
|||
_LOADED_PROTOTYPES = None
|
||||
|
||||
MAP_DATA_KEYS = [
|
||||
"zcoord", "map", "legend", "prototypes"
|
||||
"zcoord", "map", "legend", "prototypes", "options"
|
||||
]
|
||||
|
||||
# these are all symbols used for x,y coordinate spots
|
||||
|
|
@ -239,6 +239,7 @@ class XYMap:
|
|||
self.map_module_or_dict = map_module_or_dict
|
||||
|
||||
self.prototypes = None
|
||||
self.options = None
|
||||
|
||||
# transitional mapping
|
||||
self.symbol_map = None
|
||||
|
|
@ -300,6 +301,7 @@ class XYMap:
|
|||
"zcoord": <int or str>, # optional
|
||||
"legend": <dict>, # optional
|
||||
"prototypes": <dict> # optional
|
||||
"options": <dict> # optional
|
||||
}
|
||||
|
||||
"""
|
||||
|
|
@ -308,7 +310,7 @@ class XYMap:
|
|||
|
||||
mapdata = {}
|
||||
if isinstance(map_module_or_dict, dict):
|
||||
# map-=structure provided directly
|
||||
# map-structure provided directly
|
||||
mapdata = map_module_or_dict
|
||||
else:
|
||||
# read from contents of module
|
||||
|
|
@ -350,6 +352,7 @@ class XYMap:
|
|||
self.Z = mapdata.get('zcoord', self.Z)
|
||||
self.mapstring = mapdata['map']
|
||||
self.prototypes = mapdata.get('prototypes', {})
|
||||
self.options = mapdata.get('options', {})
|
||||
|
||||
# merge the custom legend onto the default legend to allow easily
|
||||
# overriding only parts of it
|
||||
|
|
|
|||
|
|
@ -251,9 +251,10 @@ class XYZRoom(DefaultRoom):
|
|||
map_display = True
|
||||
map_mode = 'nodes' # or 'scan'
|
||||
map_visual_range = 2
|
||||
map_character_symbol = "@"
|
||||
map_character_symbol = "|g@|n"
|
||||
map_align = 'c'
|
||||
map_area_client = True
|
||||
map_target_path_style = "|y{display_symbol}|n"
|
||||
map_fill_all = True
|
||||
|
||||
def __str__(self):
|
||||
return repr(self)
|
||||
|
|
@ -262,13 +263,6 @@ class XYZRoom(DefaultRoom):
|
|||
x, y, z = self.xyz
|
||||
return f"<XYZRoom '{self.db_key}', XYZ=({x},{y},{z})>"
|
||||
|
||||
@property
|
||||
def xyzgrid(self):
|
||||
global GET_XYZGRID
|
||||
if not GET_XYZGRID:
|
||||
from evennia.contrib.xyzgrid.xyzgrid import get_xyzgrid as GET_XYZGRID
|
||||
return GET_XYZGRID()
|
||||
|
||||
@property
|
||||
def xyz(self):
|
||||
if not hasattr(self, "_xyz"):
|
||||
|
|
@ -284,6 +278,21 @@ class XYZRoom(DefaultRoom):
|
|||
|
||||
return self._xyz
|
||||
|
||||
@property
|
||||
def xyzgrid(self):
|
||||
global GET_XYZGRID
|
||||
if not GET_XYZGRID:
|
||||
from evennia.contrib.xyzgrid.xyzgrid import get_xyzgrid as GET_XYZGRID
|
||||
return GET_XYZGRID()
|
||||
|
||||
@property
|
||||
def xymap(self):
|
||||
if not hasattr(self, "_xymap"):
|
||||
xyzgrid = self.xyzgrid
|
||||
_, _, Z = self.xyz
|
||||
self._xymap = xyzgrid.get_map(Z)
|
||||
return self._xymap
|
||||
|
||||
@classmethod
|
||||
def create(cls, key, account=None, xyz=(0, 0, 'map'), **kwargs):
|
||||
"""
|
||||
|
|
@ -401,19 +410,30 @@ class XYZRoom(DefaultRoom):
|
|||
# normal get_appearance of a room
|
||||
room_desc = super().return_appearance(looker, **kwargs)
|
||||
|
||||
if kwargs.get('map_display', self.map_display):
|
||||
# show the near-area map.
|
||||
# get current xymap
|
||||
xyz = self.xyz
|
||||
xymap = self.xyzgrid.get_map(xyz[2])
|
||||
|
||||
if xymap and kwargs.get('map_display', xymap.options.get("map_display", self.map_display)):
|
||||
|
||||
# show the near-area map.
|
||||
map_character_symbol = kwargs.get(
|
||||
'map_character_symbol',
|
||||
xymap.options.get("map_character_symbol", self.map_character_symbol))
|
||||
map_visual_range = kwargs.get(
|
||||
"map_visual_range", xymap.options.get("map_visual_range", self.map_visual_range))
|
||||
map_mode = kwargs.get(
|
||||
"map_mode", xymap.options.get("map_mode", self.map_mode))
|
||||
map_align = kwargs.get(
|
||||
"map_align", xymap.options.get("map_align", self.map_align))
|
||||
map_target_path_style = kwargs.get(
|
||||
"map_target_path_style",
|
||||
xymap.options.get("map_target_path_style", self.map_target_path_style))
|
||||
map_area_client = kwargs.get(
|
||||
"map_fill_all", xymap.options.get("map_fill_all", self.map_fill_all))
|
||||
|
||||
character_symbol = kwargs.get('map_character_symbol', self.map_character_symbol)
|
||||
visual_range = kwargs.get("visual_range", self.map_visual_range)
|
||||
map_mode = kwargs.get("map_mode", self.map_mode)
|
||||
map_align = kwargs.get("map_align", self.map_align)
|
||||
map_area_client = kwargs.get("fill_width", self.map_area_client)
|
||||
client_width, _ = looker.sessions.get()[0].get_client_size()
|
||||
|
||||
# get current xymap
|
||||
xyz = self.xyz
|
||||
xymap = self.xyzgrid.get_map(xyz[2])
|
||||
map_width = xymap.max_x
|
||||
|
||||
if map_area_client:
|
||||
|
|
@ -437,11 +457,11 @@ class XYZRoom(DefaultRoom):
|
|||
# get visual range display from map
|
||||
map_display = xymap.get_visual_range(
|
||||
(xyz[0], xyz[1]),
|
||||
dist=visual_range,
|
||||
dist=map_visual_range,
|
||||
mode=map_mode,
|
||||
target=target_xy,
|
||||
target_path_style="|y{display_symbol}|n",
|
||||
character=f"|g{character_symbol}|n",
|
||||
target_path_style=map_target_path_style,
|
||||
character=map_character_symbol,
|
||||
max_size=(display_width, None),
|
||||
indent=map_indent
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue