From b0292c05b24f08f556b45198f65e49de7a83a574 Mon Sep 17 00:00:00 2001 From: nicomarg Date: Wed, 11 Nov 2020 23:48:46 +0100 Subject: [PATCH] The settings menu refreshes texture pack when exited --- dungeonbattle/enums.py | 3 +++ dungeonbattle/game.py | 8 ++++---- dungeonbattle/menus.py | 3 ++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/dungeonbattle/enums.py b/dungeonbattle/enums.py index d74efbc..9bc9aed 100644 --- a/dungeonbattle/enums.py +++ b/dungeonbattle/enums.py @@ -3,6 +3,9 @@ from typing import Optional from dungeonbattle.settings import Settings +class DisplayActions(Enum): + REFRESH = auto() + UPDATE = auto() class GameMode(Enum): MAINMENU = auto() diff --git a/dungeonbattle/game.py b/dungeonbattle/game.py index 3f75960..39e7b48 100644 --- a/dungeonbattle/game.py +++ b/dungeonbattle/game.py @@ -2,7 +2,7 @@ from random import randint from typing import Any, Optional from .entities.player import Player -from .enums import GameMode, KeyValues +from .enums import GameMode, KeyValues, DisplayActions from .interfaces import Map from .settings import Settings from . import menus @@ -12,7 +12,7 @@ from typing import Callable class Game: map: Map player: Player - display_refresh: Callable[[], None] + display_actions: Callable[[DisplayActions], None] def __init__(self) -> None: """ @@ -51,7 +51,7 @@ class Game: while True: # pragma no cover screen.clear() screen.refresh() - self.display_refresh() + self.display_actions(DisplayActions.REFRESH) key = screen.getkey() self.handle_key_pressed( KeyValues.translate_key(key, self.settings), key) @@ -68,7 +68,7 @@ class Game: self.main_menu.handle_key_pressed(key, self) elif self.state == GameMode.SETTINGS: self.settings_menu.handle_key_pressed(key, raw_key, self) - self.display_refresh() + self.display_actions(DisplayActions.REFRESH) def handle_key_pressed_play(self, key: KeyValues) -> None: """ diff --git a/dungeonbattle/menus.py b/dungeonbattle/menus.py index 74827c6..f6d7058 100644 --- a/dungeonbattle/menus.py +++ b/dungeonbattle/menus.py @@ -3,7 +3,7 @@ from enum import Enum from typing import Any, Optional from .display.texturepack import TexturePack -from .enums import GameMode, KeyValues +from .enums import GameMode, KeyValues, DisplayActions from .settings import Settings @@ -82,6 +82,7 @@ class SettingsMenu(Menu): if key == KeyValues.SPACE or \ key == KeyValues.ENTER and \ self.position == len(self.values) - 1: + game.display_actions(DisplayActions.UPDATE) game.state = GameMode.MAINMENU if key == KeyValues.DOWN: self.go_down()