From 582e47990e8ed749a9c13e2342801c97d5e31cbe Mon Sep 17 00:00:00 2001 From: Nils G <nils.gondermann@ruhr-uni-bochum.de> Date: Mon, 27 Apr 2020 12:50:15 +0200 Subject: [PATCH] Do not actually change role when done submitting, instead use 'hidden' flag --- controllers/game.py | 4 ++-- controllers/player.py | 2 +- models/i_players.py | 2 ++ static/game/debug/renderer.js | 12 +++++++++--- views/game/index.html | 2 ++ views/include/websocket.html | 2 ++ 6 files changed, 18 insertions(+), 6 deletions(-) diff --git a/controllers/game.py b/controllers/game.py index db79a05..c714564 100644 --- a/controllers/game.py +++ b/controllers/game.py @@ -78,7 +78,7 @@ def roles(): if not isinstance(definition, dict): return(FAIL(CODE_MISSING)) - if not JSON_CONTAINS(definition, [("role", str), ("prompts", list)]): + if not JSON_CONTAINS(definition, [("role", str), ("role_next", str), ("prompts", list)]): return(FAIL(CODE_MISSING)) for prompt in definition["prompts"]: @@ -90,7 +90,7 @@ def roles(): #Update roles and prompts on server for uid in change: - db(db.Player.id == uid).update(role=change[uid]["role"], prompts=JSON_TO_B64(change[uid]["prompts"]), input_max=len(change[uid]["prompts"]), inputs=JSON_TO_B64([])) + db(db.Player.id == uid).update(role=change[uid]["role"], role_next=change[uid]["role_next"], prompts=JSON_TO_B64(change[uid]["prompts"]), input_max=len(change[uid]["prompts"]), inputs=JSON_TO_B64([]), submit_done=False) #Update roles on clients WEBSOCKET_SEND(room_record, "role", JSON_TO_B64(change)) diff --git a/controllers/player.py b/controllers/player.py index b1d6f0e..e7b1106 100644 --- a/controllers/player.py +++ b/controllers/player.py @@ -93,6 +93,6 @@ def submit(): #Insert new input into table current_inputs.append(new_input) - db(db.Player.id == player_record.id).update(inputs=JSON_TO_B64(current_inputs)) + db(db.Player.id == player_record.id).update(inputs=JSON_TO_B64(current_inputs), submit_done=(len(current_inputs) >= player_record.input_max)) return(SUCCESS()) diff --git a/models/i_players.py b/models/i_players.py index 8931609..b974b60 100644 --- a/models/i_players.py +++ b/models/i_players.py @@ -6,9 +6,11 @@ db.define_table( Field('hashcode', 'string', notnull=True), Field('name', 'string', notnull=True), Field('role', 'string', default="idle"), + Field('role_next', 'string', default="idle"), Field('prompts', 'text', default=base64.standard_b64encode(b'[]'), notnull=True), Field('inputs', 'text', default=base64.standard_b64encode(b'[]'), notnull=True), Field('input_max', 'integer', default=0, notnull=True), + Field('submit_done', 'boolean', default=False), Field('creation', 'datetime', default=request.now, notnull=True) ) diff --git a/static/game/debug/renderer.js b/static/game/debug/renderer.js index 4a5f1e9..a9efc8c 100644 --- a/static/game/debug/renderer.js +++ b/static/game/debug/renderer.js @@ -2,6 +2,10 @@ function render(_role, _roles){ HEADER_SET(ROOM_CODE, "Lynchburg", PLAYER_NAME+":"+_role); + if(submit_done) { + _role = role_next; + } + if(_role in _roles) { renderRole(_roles[_role], _roles["idle"]); return; @@ -128,11 +132,13 @@ function submit(_button) { AJAX_JSON(URL_SUBMIT, submit, function(_code, _data) { switch(_code) { case 200: - case 409: currentPrompt++; - if(prompts[currentPrompt]) { - render(role, roles); + //Fall through: + case 409: + if(!prompts[currentPrompt]) { + submit_done = true; } + render(role, roles); break; case 401: case 410: diff --git a/views/game/index.html b/views/game/index.html index e0872ed..5fb74c7 100644 --- a/views/game/index.html +++ b/views/game/index.html @@ -16,9 +16,11 @@ <script type="text/javascript"> {{ include 'include/consts.js' }} var role = "{{=player_record.role}}"; + var role_next = "{{=player_record.role_next}}"; var roles = JSON.parse(atob('{{=XML(room_record.roles)}}')); var prompts = JSON.parse(atob('{{=XML(player_record.prompts)}}')); var currentPrompt = JSON.parse(atob('{{=XML(player_record.inputs)}}')).length; + var submit_done = {{=str(player_record.submit_done).lower()}}; </script> {{block game_js}}{{end game_js}} diff --git a/views/include/websocket.html b/views/include/websocket.html index a9804e7..6cba455 100644 --- a/views/include/websocket.html +++ b/views/include/websocket.html @@ -28,8 +28,10 @@ role_definition = JSON.parse(atob(data)); if(PLAYER_UID in role_definition) { role = role_definition[PLAYER_UID]["role"]; + role_next = role_definition[PLAYER_UID]["role_next"]; prompts = role_definition[PLAYER_UID]["prompts"]; currentPrompt = 0; + submit_done = false; } break; default: -- GitLab