refactor 'games_list' in app class
This commit is contained in:
parent
9156793852
commit
f1d371c5f2
@ -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)
|
||||
|
||||
|
||||
@ -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
|
||||
Loading…
Reference in New Issue
Block a user