X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/copy_structured?a=blobdiff_plain;f=new%2Fplomrogue%2Fmapping.py;h=33a8aa95f0978a17f743d919017d20adf3cf05ad;hb=f196909e2e033278e1492e60024fbc34e58eecb8;hp=bec311b56e5064258ec4a7c3cc85869d0cfa546b;hpb=97049163acc0844e1656df3f761c9ca612afdeb0;p=plomrogue2-experiments diff --git a/new/plomrogue/mapping.py b/new/plomrogue/mapping.py index bec311b..33a8aa9 100644 --- a/new/plomrogue/mapping.py +++ b/new/plomrogue/mapping.py @@ -85,12 +85,33 @@ class MapGeometry(): self.neighbors_to[map_size][pos] = neighbors return neighbors - def pos_in_projection(self, pos, offset, maps_size): - pos_y = pos[1].y + (maps_size.y * pos[0].y) - offset.y - pos_x = pos[1].x + (maps_size.x * pos[0].x) - offset.x - return YX(pos_y, pos_x) - - def absolutize_coordinate(self, map_size, big_yx, little_yx): + def undouble_coordinate(self, maps_size, coordinate): + y = maps_size.y * coordinate[0].y + coordinate[1].y + x = maps_size.x * coordinate[0].x + coordinate[1].x + return YX(y, x) + + def get_view_offset(self, maps_size, center, radius): + yx_to_origin = self.undouble_coordinate(maps_size, center) + return yx_to_origin - YX(radius, radius) + + def pos_in_view(self, pos, offset, maps_size): + return self.undouble_coordinate(maps_size, pos) - offset + + def get_view(self, maps_size, get_map, radius, view_offset): + m = Map(size=YX(radius*2+1, radius*2+1) + for pos in m: + seen_pos = self.correct_double_coordinate(maps_size, (0,0), + pos + view_offset) + seen_map = get_map(seen_pos[0], False) + if seen_map is None: + seen_map = Map(size=maps_size) + m[pos] = seen_map[seen_pos[1]] + return m + + def get_correcting_map_size(self, size, offset): + return size + + def correct_double_coordinate(self, map_size, big_yx, little_yx): def adapt_axis(axis): maps_crossed = little_yx[axis] // map_size[axis] @@ -105,8 +126,9 @@ class MapGeometry(): def move(self, start_pos, direction, map_size): mover = getattr(self, 'move_' + direction) big_yx, little_yx = start_pos - unadapted_target = mover(little_yx) - return self.absolutize_coordinate(map_size, big_yx, unadapted_target) + uncorrected_target = mover(little_yx) + return self.correct_double_coordinate(map_size, big_yx, + uncorrected_target) @@ -161,7 +183,6 @@ class MapGeometryHex(MapGeometryWithLeftRightMoves): return YX(start_pos.y + 1, start_pos.x + 1) - class FovMap(Map): def __init__(self, source_map, center):