Ran formatting on code
This commit is contained in:
parent
83154de19e
commit
353e4c0aa7
20 changed files with 296 additions and 327 deletions
|
|
@ -61,21 +61,21 @@ from django.conf import settings
|
|||
from evennia import CmdSet
|
||||
from evennia.commands.default.muxcommand import MuxCommand
|
||||
|
||||
_BASIC_MAP_SIZE = settings.BASIC_MAP_SIZE if hasattr(settings, 'BASIC_MAP_SIZE') else 2
|
||||
_MAX_MAP_SIZE = settings.BASIC_MAP_SIZE if hasattr(settings, 'MAX_MAP_SIZE') else 10
|
||||
_BASIC_MAP_SIZE = settings.BASIC_MAP_SIZE if hasattr(settings, "BASIC_MAP_SIZE") else 2
|
||||
_MAX_MAP_SIZE = settings.BASIC_MAP_SIZE if hasattr(settings, "MAX_MAP_SIZE") else 10
|
||||
|
||||
# _COMPASS_DIRECTIONS specifies which way to move the pointer on the x/y axes and what characters to use to depict the exits on the map.
|
||||
_COMPASS_DIRECTIONS = {
|
||||
'north': (0, -3, ' | '),
|
||||
'south': (0, 3, ' | '),
|
||||
'east': (3, 0, '-'),
|
||||
'west': (-3, 0, '-'),
|
||||
'northeast': (3, -3, '/'),
|
||||
'northwest': (-3, -3, '\\'),
|
||||
'southeast': (3, 3, '\\'),
|
||||
'southwest': (-3, 3, '/'),
|
||||
'up': (0, 0, '^'),
|
||||
'down': (0, 0, 'v')
|
||||
"north": (0, -3, " | "),
|
||||
"south": (0, 3, " | "),
|
||||
"east": (3, 0, "-"),
|
||||
"west": (-3, 0, "-"),
|
||||
"northeast": (3, -3, "/"),
|
||||
"northwest": (-3, -3, "\\"),
|
||||
"southeast": (3, 3, "\\"),
|
||||
"southwest": (-3, 3, "/"),
|
||||
"up": (0, 0, "^"),
|
||||
"down": (0, 0, "v"),
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -91,7 +91,7 @@ class Map(object):
|
|||
"""
|
||||
self.start_time = time.time()
|
||||
self.caller = caller
|
||||
self.max_width = int(size * 2 + 1) * 5 # This must be an odd number
|
||||
self.max_width = int(size * 2 + 1) * 5 # This must be an odd number
|
||||
self.max_length = int(size * 2 + 1) * 3 # This must be an odd number
|
||||
self.has_mapped = {}
|
||||
self.curX = None
|
||||
|
|
@ -109,8 +109,8 @@ class Map(object):
|
|||
board = []
|
||||
for row in range(self.max_length):
|
||||
board.append([])
|
||||
for column in range(int(self.max_width/5)):
|
||||
board[row].extend([' ', ' ', ' '])
|
||||
for column in range(int(self.max_width / 5)):
|
||||
board[row].extend([" ", " ", " "])
|
||||
return board
|
||||
|
||||
def exit_name_as_ordinal(self, ex):
|
||||
|
|
@ -124,11 +124,13 @@ class Map(object):
|
|||
"""
|
||||
exit_name = ex.name
|
||||
if exit_name not in _COMPASS_DIRECTIONS:
|
||||
compass_aliases = [direction in ex.aliases.all() for direction in _COMPASS_DIRECTIONS.keys()]
|
||||
compass_aliases = [
|
||||
direction in ex.aliases.all() for direction in _COMPASS_DIRECTIONS.keys()
|
||||
]
|
||||
if compass_aliases[0]:
|
||||
exit_name = compass_aliases[0]
|
||||
if exit_name not in _COMPASS_DIRECTIONS:
|
||||
return ''
|
||||
return ""
|
||||
return exit_name
|
||||
|
||||
def update_pos(self, room, exit_name):
|
||||
|
|
@ -179,7 +181,7 @@ class Map(object):
|
|||
# Additionally, if the name of the exit is not ordinal but an alias of it is, use that.
|
||||
for ex in [x for x in room.exits if x.access(self.caller, "traverse")]:
|
||||
ex_name = self.exit_name_as_ordinal(ex)
|
||||
if not ex_name or ex_name in ['up', 'down']:
|
||||
if not ex_name or ex_name in ["up", "down"]:
|
||||
continue
|
||||
if self.has_drawn(ex.destination):
|
||||
continue
|
||||
|
|
@ -201,20 +203,20 @@ class Map(object):
|
|||
continue
|
||||
|
||||
ex_character = _COMPASS_DIRECTIONS[ex_name][2]
|
||||
delta_x = int(_COMPASS_DIRECTIONS[ex_name][1]/3)
|
||||
delta_y = int(_COMPASS_DIRECTIONS[ex_name][0]/3)
|
||||
delta_x = int(_COMPASS_DIRECTIONS[ex_name][1] / 3)
|
||||
delta_y = int(_COMPASS_DIRECTIONS[ex_name][0] / 3)
|
||||
|
||||
# Make modifications if the exit has BOTH up and down exits
|
||||
if ex_name == 'up':
|
||||
if 'v' in self.grid[x][y]:
|
||||
self.render_room(room, x, y, p1='^', p2='v')
|
||||
if ex_name == "up":
|
||||
if "v" in self.grid[x][y]:
|
||||
self.render_room(room, x, y, p1="^", p2="v")
|
||||
else:
|
||||
self.render_room(room, x, y, here='^')
|
||||
elif ex_name == 'down':
|
||||
if '^' in self.grid[x][y]:
|
||||
self.render_room(room, x, y, p1='^', p2='v')
|
||||
self.render_room(room, x, y, here="^")
|
||||
elif ex_name == "down":
|
||||
if "^" in self.grid[x][y]:
|
||||
self.render_room(room, x, y, p1="^", p2="v")
|
||||
else:
|
||||
self.render_room(room, x, y, here='v')
|
||||
self.render_room(room, x, y, here="v")
|
||||
else:
|
||||
self.grid[x + delta_x][y + delta_y] = ex_character
|
||||
|
||||
|
|
@ -234,7 +236,7 @@ class Map(object):
|
|||
self.has_mapped[room] = [self.curX, self.curY]
|
||||
self.render_room(room, self.curX, self.curY)
|
||||
|
||||
def render_room(self, room, x, y, p1='[', p2=']', here=None):
|
||||
def render_room(self, room, x, y, p1="[", p2="]", here=None):
|
||||
"""
|
||||
Draw a given room with ascii characters
|
||||
|
||||
|
|
@ -253,7 +255,7 @@ class Map(object):
|
|||
you[0] = f"{p1}|n"
|
||||
you[1] = f"{here if here else you[1]}"
|
||||
if room == self.caller.location:
|
||||
you[1] = '|[x|co|n' # Highlight the location you are currently in
|
||||
you[1] = "|[x|co|n" # Highlight the location you are currently in
|
||||
you[2] = f"{p2}|n"
|
||||
|
||||
self.grid[x][y] = "".join(you)
|
||||
|
|
@ -300,6 +302,7 @@ class CmdMap(MuxCommand):
|
|||
|
||||
Usage: map (optional size)
|
||||
"""
|
||||
|
||||
key = "map"
|
||||
|
||||
def func(self):
|
||||
|
|
|
|||
|
|
@ -17,19 +17,32 @@ class TestIngameMap(BaseEvenniaCommandTest):
|
|||
Expected output:
|
||||
[ ]--[ ]
|
||||
"""
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.west_room = create_object(rooms.Room, key="Room 1")
|
||||
self.east_room = create_object(rooms.Room, key="Room 2")
|
||||
create_object(exits.Exit, key="east", aliases=["e"], location=self.west_room, destination=self.east_room)
|
||||
create_object(exits.Exit, key="west", aliases=["w"], location=self.east_room, destination=self.west_room)
|
||||
create_object(
|
||||
exits.Exit,
|
||||
key="east",
|
||||
aliases=["e"],
|
||||
location=self.west_room,
|
||||
destination=self.east_room,
|
||||
)
|
||||
create_object(
|
||||
exits.Exit,
|
||||
key="west",
|
||||
aliases=["w"],
|
||||
location=self.east_room,
|
||||
destination=self.west_room,
|
||||
)
|
||||
|
||||
def test_west_room_map_room(self):
|
||||
self.char1.location = self.west_room
|
||||
map_here = ingame_map_display.Map(self.char1).show_map()
|
||||
self.assertEqual(map_here.strip(), '[|n|[x|co|n]|n--[|n ]|n')
|
||||
self.assertEqual(map_here.strip(), "[|n|[x|co|n]|n--[|n ]|n")
|
||||
|
||||
def test_east_room_map_room(self):
|
||||
self.char1.location = self.east_room
|
||||
map_here = ingame_map_display.Map(self.char1).show_map()
|
||||
self.assertEqual(map_here.strip(), '[|n ]|n--[|n|[x|co|n]|n')
|
||||
self.assertEqual(map_here.strip(), "[|n ]|n--[|n|[x|co|n]|n")
|
||||
|
|
|
|||
|
|
@ -1421,16 +1421,19 @@ class TestBuildExampleGrid(BaseEvenniaTest):
|
|||
mock_room_callbacks = mock.MagicMock()
|
||||
mock_exit_callbacks = mock.MagicMock()
|
||||
|
||||
|
||||
class TestXyzRoom(xyzroom.XYZRoom):
|
||||
def at_object_creation(self):
|
||||
mock_room_callbacks.at_object_creation()
|
||||
def at_object_creation(self):
|
||||
mock_room_callbacks.at_object_creation()
|
||||
|
||||
|
||||
class TestXyzExit(xyzroom.XYZExit):
|
||||
def at_object_creation(self):
|
||||
mock_exit_callbacks.at_object_creation()
|
||||
def at_object_creation(self):
|
||||
mock_exit_callbacks.at_object_creation()
|
||||
|
||||
|
||||
MAP_DATA = {
|
||||
"map": """
|
||||
"map": """
|
||||
|
||||
+ 0 1
|
||||
|
||||
|
|
@ -1439,35 +1442,37 @@ MAP_DATA = {
|
|||
+ 0 1
|
||||
|
||||
""",
|
||||
"zcoord": "map1",
|
||||
"prototypes": {
|
||||
("*", "*"): {
|
||||
"key": "room",
|
||||
"desc": "A room.",
|
||||
"prototype_parent": "xyz_room",
|
||||
},
|
||||
("*", "*", "*"): {
|
||||
"desc": "A passage.",
|
||||
"prototype_parent": "xyz_exit",
|
||||
}
|
||||
},
|
||||
"options": {
|
||||
"map_visual_range": 1,
|
||||
"map_mode": "scan",
|
||||
}
|
||||
"zcoord": "map1",
|
||||
"prototypes": {
|
||||
("*", "*"): {
|
||||
"key": "room",
|
||||
"desc": "A room.",
|
||||
"prototype_parent": "xyz_room",
|
||||
},
|
||||
("*", "*", "*"): {
|
||||
"desc": "A passage.",
|
||||
"prototype_parent": "xyz_exit",
|
||||
},
|
||||
},
|
||||
"options": {
|
||||
"map_visual_range": 1,
|
||||
"map_mode": "scan",
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
class TestCallbacks(BaseEvenniaTest):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
mock_room_callbacks.reset_mock()
|
||||
mock_exit_callbacks.reset_mock()
|
||||
|
||||
|
||||
def setup_grid(self, map_data):
|
||||
self.grid, err = xyzgrid.XYZGrid.create("testgrid")
|
||||
|
||||
def _log(msg):
|
||||
print(msg)
|
||||
print(msg)
|
||||
|
||||
self.grid.log = _log
|
||||
|
||||
self.map_data = map_data
|
||||
|
|
@ -1489,5 +1494,9 @@ class TestCallbacks(BaseEvenniaTest):
|
|||
self.grid.spawn()
|
||||
|
||||
# Two rooms and 2 exits, Each one should have gotten one `at_object_creation` callback.
|
||||
self.assertEqual(mock_room_callbacks.at_object_creation.mock_calls, [mock.call(), mock.call()])
|
||||
self.assertEqual(mock_exit_callbacks.at_object_creation.mock_calls, [mock.call(), mock.call()])
|
||||
self.assertEqual(
|
||||
mock_room_callbacks.at_object_creation.mock_calls, [mock.call(), mock.call()]
|
||||
)
|
||||
self.assertEqual(
|
||||
mock_exit_callbacks.at_object_creation.mock_calls, [mock.call(), mock.call()]
|
||||
)
|
||||
|
|
|
|||
|
|
@ -321,7 +321,9 @@ class MapNode:
|
|||
# with proper coordinates etc
|
||||
typeclass = self.prototype.get("typeclass")
|
||||
if typeclass is None:
|
||||
raise MapError(f"The prototype {self.prototype} for this node has no 'typeclass' key.", self)
|
||||
raise MapError(
|
||||
f"The prototype {self.prototype} for this node has no 'typeclass' key.", self
|
||||
)
|
||||
self.log(f" spawning room at xyz={xyz} ({typeclass})")
|
||||
Typeclass = class_from_module(typeclass)
|
||||
nodeobj, err = Typeclass.create(self.prototype.get("key", "An empty room"), xyz=xyz)
|
||||
|
|
@ -405,7 +407,10 @@ class MapNode:
|
|||
prot = maplinks[key.lower()][3].prototype
|
||||
typeclass = prot.get("typeclass")
|
||||
if typeclass is None:
|
||||
raise MapError(f"The prototype {self.prototype} for this node has no 'typeclass' key.", self)
|
||||
raise MapError(
|
||||
f"The prototype {self.prototype} for this node has no 'typeclass' key.",
|
||||
self,
|
||||
)
|
||||
self.log(f" spawning/updating exit xyz={xyz}, direction={key} ({typeclass})")
|
||||
|
||||
Typeclass = class_from_module(typeclass)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue