From e8818f6bbb4f6e08e3b8fa8ac6a31540d544dd83 Mon Sep 17 00:00:00 2001 From: Griatch Date: Sat, 5 Jun 2021 19:57:54 +0200 Subject: [PATCH] Working map; will explore flipp Y coordinate system --- evennia/contrib/map_and_pathfind/mapsystem.py | 11 +++++------ evennia/contrib/map_and_pathfind/tests.py | 17 ++++++++++++----- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/evennia/contrib/map_and_pathfind/mapsystem.py b/evennia/contrib/map_and_pathfind/mapsystem.py index d3d437d2fb..719e7ae0aa 100644 --- a/evennia/contrib/map_and_pathfind/mapsystem.py +++ b/evennia/contrib/map_and_pathfind/mapsystem.py @@ -626,7 +626,6 @@ class Map: # first pass: read string-grid and parse even (x,y) coordinates into nodes for iy, line in enumerate(maplines[origo_y:]): - maxheight = max(maxheight, iy + 1) even_iy = iy % 2 == 0 for ix, char in enumerate(line[origo_x:]): @@ -635,6 +634,7 @@ class Map: even_ix = ix % 2 == 0 maxwidth = max(maxwidth, ix + 1) + maxheight = max(maxheight, iy + 1) # only increase if there's something on the line mapnode_or_link_class = self.legend.get(char) if not mapnode_or_link_class: @@ -781,17 +781,16 @@ class Map: """ width, height = self.width, self.height - # convert to string-map coordinates + # convert to string-map coordinates. Remember that y grid grows downwards ix, iy = max(0, min(x * 2, width)), max(0, min(y * 2, height)) - left, right = max(0, ix - dist), min(width, ix + dist) - top, bottom = max(0, iy - dist), min(height, iy + dist) - + left, right = max(0, ix - dist), min(width, ix + dist + 1) + top, bottom = max(0, iy - dist), min(height, iy + dist + 1) 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]: + for line in self.display_map[top:bottom]: output.append(line[left:right]) return output diff --git a/evennia/contrib/map_and_pathfind/tests.py b/evennia/contrib/map_and_pathfind/tests.py index 4598cfd323..fdbcb2c661 100644 --- a/evennia/contrib/map_and_pathfind/tests.py +++ b/evennia/contrib/map_and_pathfind/tests.py @@ -6,6 +6,7 @@ Tests for the Mapsystem from unittest import TestCase, mock from . import mapsystem +from parameterized import parameterized MAP1 = """ @@ -48,11 +49,17 @@ class TestMap1(TestCase): 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) + @parameterized.expand([ + (0, 0, "#-\n| ", [["#", "-"], ["|", " "]]), + (1, 0, "-#\n |", [["-", "#"], [" ", "|"]]), + (0, 1, "| \n#-", [["|", " "], ["#", "-"]]), + (1, 1, " |\n-#", [[" ", "|"], ["-", "#"]]), - self.assertEqual(string, "|\n#-") - self.assertEqual(lst, [["|"], ['#', '-']]) + ]) + def test_get_map_region(self, x, y, expectstr, expectlst): + string = self.map.get_map_region(x, y, dist=1) + lst = self.map.get_map_region(x, y, dist=1, return_str=False) + self.assertEqual(string, expectstr) + self.assertEqual(lst, expectlst)