From a310b74e9f76e51c1b78f5fe23a9ff45b312ae18 Mon Sep 17 00:00:00 2001 From: Dane Johnson Date: Tue, 14 Feb 2023 11:45:14 -0600 Subject: [PATCH] Active clues --- venture/app.py | 15 +++++++++++++++ venture/game.py | 7 ++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/venture/app.py b/venture/app.py index 450b558..200429e 100644 --- a/venture/app.py +++ b/venture/app.py @@ -50,6 +50,21 @@ def on_host_start(): emit('categories', session.game.categories, to=session.game.display) +@socketio.on('activate-clue') +def on_activate_clue(data): + name = data['name'] + value = data['value'] + clues = session.game.categories.get(name) + if clues: + match = None + for clue in clues: + if clue['value'] == value: + match = clue + break + if match: + emit('active-clue', match, to=session.room) + + def main(): socketio.run(app, host='0.0.0.0', debug=True) diff --git a/venture/game.py b/venture/game.py index 57ebd67..44a6ce4 100644 --- a/venture/game.py +++ b/venture/game.py @@ -40,19 +40,16 @@ class Category: self.questions = [] -Clue = namedtuple('Class', ['value', 'question', 'answer']) - - def check_and_build_category(j): if not j or not j['title'] or not j['clues_count'] or j['clues_count'] < 5: return None name = j['title'] - all_clues = [Clue(c['value'], c['question'], c['answer']) + all_clues = [{key: c[key] for key in ['value', 'question', 'answer']} for c in j['clues']] clues = [] for value in [200, 400, 600, 800, 1000]: for clue in all_clues: - if clue.value == value: + if clue['value'] == value: clues.append(clue) break if len(clues) == 5: