From f1d371c5f2e6e333c58266509acf4fc763d5f295 Mon Sep 17 00:00:00 2001 From: Thomas Rubini <74205383+ThomasRubini@users.noreply.github.com> Date: Tue, 3 Jan 2023 17:00:56 +0100 Subject: [PATCH] refactor 'games_list' in app class --- truthseeker/__init__.py | 3 +++ truthseeker/logic/game_logic.py | 13 ++++++------- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/truthseeker/__init__.py b/truthseeker/__init__.py index 6229d31..6e8411b 100644 --- a/truthseeker/__init__.py +++ b/truthseeker/__init__.py @@ -8,6 +8,9 @@ class TruthSeekerApp(flask.Flask): def __init__(self): super().__init__("truthseeker") + + self.games_list = {} + self.set_app_secret() self.socketio_app = SocketIO(self) diff --git a/truthseeker/logic/game_logic.py b/truthseeker/logic/game_logic.py index b46f2f4..f9755c7 100644 --- a/truthseeker/logic/game_logic.py +++ b/truthseeker/logic/game_logic.py @@ -1,12 +1,11 @@ import string import random from datetime import datetime, timedelta -import truthseeker +from truthseeker import APP # Map of all actively running games # games_list["game.game_id"]-> game info linked to that id -games_list = {} def random_string(length: int) ->str: """ @@ -87,13 +86,13 @@ def create_game(owner): game.owner = owner game.members.append(Member(owner)) game.game_id = random_string(6) - games_list[game.game_id] = game + APP.games_list[game.game_id] = game #TODO ADD A WEBSOCKET IF THE GAME IS KNOWN TO BE MULTIPLAYER return game def get_game(game_id): - if game_id in games_list: - return games_list[game_id] + if game_id in APP.games_list: + return APP.games_list[game_id] else: return None @@ -107,7 +106,7 @@ def get_game_info(game_id): : return : The Game Object linked to the game_id : return type : Game """ - if game_id in games_list: - return games_list[game_id] + if game_id in APP.games_list: + return APP.games_list[game_id] else: return None \ No newline at end of file