Active clues

This commit is contained in:
Dane Johnson 2023-02-14 11:45:14 -06:00
parent 0a96d571bd
commit a310b74e9f
2 changed files with 17 additions and 5 deletions

View File

@ -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)

View File

@ -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: