From: Christian Heller Date: Sun, 6 Dec 2020 18:59:02 +0000 (+0100) Subject: Don't recalculate directions all the time, unnecessarily. X-Git-Url: https://plomlompom.com/repos/todos?a=commitdiff_plain;h=722f6c3effe9aedf6c71678260a6976d30fb21ed;p=plomrogue2 Don't recalculate directions all the time, unnecessarily. --- diff --git a/plomrogue/game.py b/plomrogue/game.py index c495179..a1c2ee6 100755 --- a/plomrogue/game.py +++ b/plomrogue/game.py @@ -180,7 +180,7 @@ class Game(GameBase): def get_string_options(self, string_option_type): if string_option_type == 'direction': - return self.map_geometry.get_directions() + return self.map_geometry.directions elif string_option_type == 'char': return [c for c in string.digits + string.ascii_letters + string.punctuation + ' '] diff --git a/plomrogue/mapping.py b/plomrogue/mapping.py index e806ef7..53e9d29 100644 --- a/plomrogue/mapping.py +++ b/plomrogue/mapping.py @@ -21,6 +21,7 @@ class MapGeometry(): def __init__(self, size): self.size = size self.neighbors_i = {} + self.directions = self.get_directions() def get_directions(self): directions = [] @@ -32,13 +33,13 @@ class MapGeometry(): def get_neighbors_yxyx(self, yxyx): neighbors = {} - for direction in self.get_directions(): + for direction in self.directions: neighbors[direction] = self.move_yxyx(yxyx, direction) return neighbors def get_neighbors_yx(self, pos): neighbors = {} - for direction in self.get_directions(): + for direction in self.directions: neighbors[direction] = self.move_yx(pos, direction) return neighbors