Create a more semantic Size.numpy_shape property
This commit is contained in:
parent
84f7bdb947
commit
cf31bcc272
2 changed files with 13 additions and 3 deletions
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
import math
|
import math
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import Any, Iterator, Optional, overload
|
from typing import Any, Iterator, Optional, overload, Tuple
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True)
|
@dataclass(frozen=True)
|
||||||
|
@ -114,6 +114,11 @@ class Size:
|
||||||
width: int = 0
|
width: int = 0
|
||||||
height: int = 0
|
height: int = 0
|
||||||
|
|
||||||
|
@property
|
||||||
|
def numpy_shape(self) -> Tuple[int, int]:
|
||||||
|
'''Return a tuple suitable for passing into numpy array initializers for specifying the shape of the array.'''
|
||||||
|
return (self.width, self.height)
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
yield self.width
|
yield self.width
|
||||||
yield self.height
|
yield self.height
|
||||||
|
|
|
@ -19,11 +19,13 @@ from .tile import Empty, Shroud
|
||||||
|
|
||||||
|
|
||||||
class Map:
|
class Map:
|
||||||
|
'''A level map'''
|
||||||
|
|
||||||
def __init__(self, config: Configuration, generator: MapGenerator):
|
def __init__(self, config: Configuration, generator: MapGenerator):
|
||||||
self.configuration = config
|
self.configuration = config
|
||||||
|
|
||||||
map_size = config.map_size
|
map_size = config.map_size
|
||||||
shape = tuple(map_size)
|
shape = map_size.numpy_shape
|
||||||
|
|
||||||
self.tiles = np.full(shape, fill_value=Empty, order='F')
|
self.tiles = np.full(shape, fill_value=Empty, order='F')
|
||||||
generator.generate(self.tiles)
|
generator.generate(self.tiles)
|
||||||
|
@ -60,11 +62,14 @@ class Map:
|
||||||
'''Return True if the tile at the given point is walkable'''
|
'''Return True if the tile at the given point is walkable'''
|
||||||
return self.tile_is_in_bounds(point) and self.tiles[point.x, point.y]['walkable']
|
return self.tile_is_in_bounds(point) and self.tiles[point.x, point.y]['walkable']
|
||||||
|
|
||||||
|
def point_is_explored(self, point: Point) -> bool:
|
||||||
|
return self.tile_is_in_bounds(point) and self.explored[point.x, point.y]
|
||||||
|
|
||||||
def highlight_points(self, points: Iterable[Point]):
|
def highlight_points(self, points: Iterable[Point]):
|
||||||
'''Update the highlight graph with the list of points to highlight.'''
|
'''Update the highlight graph with the list of points to highlight.'''
|
||||||
self.highlighted.fill(False)
|
self.highlighted.fill(False)
|
||||||
|
|
||||||
for pt in points if points:
|
for pt in points:
|
||||||
self.highlighted[pt.x, pt.y] = True
|
self.highlighted[pt.x, pt.y] = True
|
||||||
|
|
||||||
def print_to_console(self, console: tcod.Console, bounds: Rect) -> None:
|
def print_to_console(self, console: tcod.Console, bounds: Rect) -> None:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue