From aff42449213ccc179f7d323cd17a96efcf8b430c Mon Sep 17 00:00:00 2001 From: TomH1004 Date: Sat, 20 Sep 2025 15:26:19 +0200 Subject: [PATCH] added in-person support --- experiment-scripts/app.py | 44 ++++ experiment-scripts/index.html | 2 +- experiment-scripts/player-display.html | 302 +++++++++++++++++++++++++ 3 files changed, 347 insertions(+), 1 deletion(-) create mode 100644 experiment-scripts/player-display.html diff --git a/experiment-scripts/app.py b/experiment-scripts/app.py index 345b5cd..ca7d0d8 100644 --- a/experiment-scripts/app.py +++ b/experiment-scripts/app.py @@ -66,6 +66,10 @@ SERVER_PORT = 5000 async def read_index(): return FileResponse('index.html') +@app.get("/display") +async def read_display(): + return FileResponse('player-display.html') + @app.post("/facialexpressions") def read_item(weights: list[float]): msg = ';'.join(str(w) for w in weights) @@ -82,13 +86,53 @@ class Word(BaseModel): class WordList(BaseModel): words: list[str] +# Global state for current word display +current_word_state = { + "word": "", + "timeSeconds": 0.0, + "lastWordStatus": -1, + "startTime": None +} + @app.post("/word") def read_word(word: Word): + import time + + # Only update global state for player display if word is not empty + # (avoid overwriting with empty words sent to "other" player) + if word.word and word.word.strip(): + current_word_state["word"] = word.word + current_word_state["timeSeconds"] = word.timeSeconds + current_word_state["lastWordStatus"] = word.lastWordStatus + current_word_state["startTime"] = time.time() if word.timeSeconds > 0 else None + msg = f"CHARADE:{word.lastWordStatus};{word.timeSeconds};{word.word}" print(msg) sock.sendto(msg.encode('utf-8'), (word.target, 5000)) return { "status": "ok" } +@app.get("/current-word") +def get_current_word(): + import time + + if current_word_state["startTime"] is None: + return { + "word": current_word_state["word"], + "timeRemaining": 0.0, + "lastWordStatus": current_word_state["lastWordStatus"], + "isActive": bool(current_word_state["word"]) + } + + elapsed = time.time() - current_word_state["startTime"] + time_remaining = max(0, current_word_state["timeSeconds"] - elapsed) + + return { + "word": current_word_state["word"], + "timeRemaining": time_remaining, + "lastWordStatus": current_word_state["lastWordStatus"], + "isActive": time_remaining > 0 and bool(current_word_state["word"]) + } + @app.post("/shuffle") def shuffle_words(word_list: WordList): import random diff --git a/experiment-scripts/index.html b/experiment-scripts/index.html index 93e9e86..9b98c0b 100644 --- a/experiment-scripts/index.html +++ b/experiment-scripts/index.html @@ -393,7 +393,7 @@ last = timestamp; runningWordIndex = 0; newWord = true; - lastWordStatus = 1; + lastWordStatus = -1; // First word has no previous word } const elapsed = timestamp - last; last = timestamp; diff --git a/experiment-scripts/player-display.html b/experiment-scripts/player-display.html new file mode 100644 index 0000000..ad9181c --- /dev/null +++ b/experiment-scripts/player-display.html @@ -0,0 +1,302 @@ + + + + + + Charades Player Display + + + +
+ Waiting for game to start... +
+ +
+ Connected +
+ +
+
+ +
+ Waiting for the next word... +
+ +
+
+ +
+ + + + \ No newline at end of file