mirror of
https://github.com/evennia/evennia.git
synced 2026-03-27 02:06:32 +01:00
Tested first unittests with map and pathfinding
This commit is contained in:
parent
4be7e52c56
commit
a0bd55a9d4
2 changed files with 26 additions and 4 deletions
|
|
@ -760,7 +760,7 @@ class Map:
|
|||
|
||||
return nodepath, linkpath
|
||||
|
||||
def get_map_region(self, x, y, dist=2):
|
||||
def get_map_region(self, x, y, dist=2, return_str=True):
|
||||
"""
|
||||
Display the map centered on a point and everything around it within a certain distance.
|
||||
|
||||
|
|
@ -770,6 +770,14 @@ class Map:
|
|||
dist (int): Number of gridpoints distance to show.
|
||||
A value of 2 will show adjacent nodes, a value
|
||||
of 1 will only show links from current node.
|
||||
return_str (bool, optional): Return result as an
|
||||
already formatted string.
|
||||
|
||||
Returns:
|
||||
str or list: Depending on value of `return_str`. If a list,
|
||||
this is 2D list of lines, [[str,str,str,...], [...]] where
|
||||
each element is a single character in the display grid. To
|
||||
extract a coordinate from it, use listing[iy][ix]
|
||||
|
||||
"""
|
||||
width, height = self.width, self.height
|
||||
|
|
@ -779,6 +787,11 @@ class Map:
|
|||
top, bottom = max(0, iy - dist), min(height, iy + dist)
|
||||
|
||||
output = []
|
||||
for line in self.display_map[top:bottom]:
|
||||
output.append("".join(line[left:right]))
|
||||
return "\n".join(output)
|
||||
if return_str:
|
||||
for line in self.display_map[top:bottom]:
|
||||
output.append("".join(line[left:right]))
|
||||
return "\n".join(output)
|
||||
else:
|
||||
for line in self.display_amp[top:bottom]:
|
||||
output.append(line[left:right])
|
||||
return output
|
||||
|
|
|
|||
|
|
@ -47,3 +47,12 @@ class TestMap1(TestCase):
|
|||
nodepath, linkpath = self.map.get_shortest_path((0, 0), (1, 1))
|
||||
self.assertEqual([node.node_index for node in nodepath], [0, 1, 3])
|
||||
self.assertEqual(linkpath, ['e', 's'])
|
||||
|
||||
def test_get_map_region(self):
|
||||
string = self.map.get_map_region(1, 0, dist=1)
|
||||
lst = self.map.get_map_region(1, 0, dist=1, return_str=False)
|
||||
|
||||
self.assertEqual(string, "|\n#-")
|
||||
self.assertEqual(lst, [["|"], ['#', '-']])
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue