Add variables to pixelmap to be able to copy it
@@ -13,6 +13,10 @@ class PixelMap:
:param mirrored:
"""
self._proto = proto
+ # Used for copying pixelmaps
+ self._in_bits: bool = in_bits
+ self._mirrored: bool = mirrored
+
assert self.width * self.height == (8 if in_bits else 1) * len(
self._proto.data
), f"{self.width * self.height} {(8 if in_bits else 1)*len(self._proto.data)}"
@@ -49,7 +53,7 @@ class PixelMap:
""" Example usage: self._game_info.pathing_grid[Point2((20, 20))] = 255 """
assert 0 <= pos[0] < self.width, f"x is {pos[0]}, self.width is {self.width}"
assert 0 <= pos[1] < self.height, f"y is {pos[1]}, self.height is {self.height}"
- assert 0 <= value < 256, f"value is {value}, it should be between 0 and 255"
+ assert 0 <= value <= 254 * self._in_bits + 1, f"value is {value}, it should be between 0 and {254 * self._in_bits + 1}"
assert isinstance(value, int), f"value is of type {type(value)}, it should be an integer"
self.data_numpy[pos[1], pos[0]] = value
@@ -62,6 +66,9 @@ class PixelMap:
def invert(self):
raise NotImplementedError
+ def copy(self):
+ return PixelMap(self._proto, in_bits=self._in_bits, mirrored=self._mirrored)
+
def flood_fill(self, start_point: Point2, pred: Callable[[int], bool]) -> Set[Point2]:
nodes: Set[Point2] = set()
queue: List[Point2] = [start_point]
