Working map; will explore flipp Y coordinate system
This commit is contained in:
parent
b8f5762c75
commit
7a453312cf
2 changed files with 17 additions and 11 deletions
|
|
@ -626,7 +626,6 @@ class Map:
|
||||||
|
|
||||||
# first pass: read string-grid and parse even (x,y) coordinates into nodes
|
# first pass: read string-grid and parse even (x,y) coordinates into nodes
|
||||||
for iy, line in enumerate(maplines[origo_y:]):
|
for iy, line in enumerate(maplines[origo_y:]):
|
||||||
maxheight = max(maxheight, iy + 1)
|
|
||||||
even_iy = iy % 2 == 0
|
even_iy = iy % 2 == 0
|
||||||
for ix, char in enumerate(line[origo_x:]):
|
for ix, char in enumerate(line[origo_x:]):
|
||||||
|
|
||||||
|
|
@ -635,6 +634,7 @@ class Map:
|
||||||
|
|
||||||
even_ix = ix % 2 == 0
|
even_ix = ix % 2 == 0
|
||||||
maxwidth = max(maxwidth, ix + 1)
|
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)
|
mapnode_or_link_class = self.legend.get(char)
|
||||||
if not mapnode_or_link_class:
|
if not mapnode_or_link_class:
|
||||||
|
|
@ -781,17 +781,16 @@ class Map:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
width, height = self.width, self.height
|
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))
|
ix, iy = max(0, min(x * 2, width)), max(0, min(y * 2, height))
|
||||||
left, right = max(0, ix - dist), min(width, ix + dist)
|
left, right = max(0, ix - dist), min(width, ix + dist + 1)
|
||||||
top, bottom = max(0, iy - dist), min(height, iy + dist)
|
top, bottom = max(0, iy - dist), min(height, iy + dist + 1)
|
||||||
|
|
||||||
output = []
|
output = []
|
||||||
if return_str:
|
if return_str:
|
||||||
for line in self.display_map[top:bottom]:
|
for line in self.display_map[top:bottom]:
|
||||||
output.append("".join(line[left:right]))
|
output.append("".join(line[left:right]))
|
||||||
return "\n".join(output)
|
return "\n".join(output)
|
||||||
else:
|
else:
|
||||||
for line in self.display_amp[top:bottom]:
|
for line in self.display_map[top:bottom]:
|
||||||
output.append(line[left:right])
|
output.append(line[left:right])
|
||||||
return output
|
return output
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ Tests for the Mapsystem
|
||||||
|
|
||||||
from unittest import TestCase, mock
|
from unittest import TestCase, mock
|
||||||
from . import mapsystem
|
from . import mapsystem
|
||||||
|
from parameterized import parameterized
|
||||||
|
|
||||||
|
|
||||||
MAP1 = """
|
MAP1 = """
|
||||||
|
|
@ -48,11 +49,17 @@ class TestMap1(TestCase):
|
||||||
self.assertEqual([node.node_index for node in nodepath], [0, 1, 3])
|
self.assertEqual([node.node_index for node in nodepath], [0, 1, 3])
|
||||||
self.assertEqual(linkpath, ['e', 's'])
|
self.assertEqual(linkpath, ['e', 's'])
|
||||||
|
|
||||||
def test_get_map_region(self):
|
@parameterized.expand([
|
||||||
string = self.map.get_map_region(1, 0, dist=1)
|
(0, 0, "#-\n| ", [["#", "-"], ["|", " "]]),
|
||||||
lst = self.map.get_map_region(1, 0, dist=1, return_str=False)
|
(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)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue