Working map; will explore flipp Y coordinate system

This commit is contained in:
Griatch 2021-06-05 19:57:54 +02:00
parent a0bd55a9d4
commit e8818f6bbb
2 changed files with 17 additions and 11 deletions

View file

@ -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

View file

@ -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)