|
|
|
@ -2,7 +2,7 @@ |
|
|
|
|
|
|
|
|
|
{% block content %} |
|
|
|
|
<header> |
|
|
|
|
<div class="phase">{{ status.phase }} phase of turn #{{ status.turn }}</div> |
|
|
|
|
<div class="phase"><span class="status-phase">{{ status.phase }}</span> phase of turn #<span class="status-turn">{{ status.turn }}</span></div> |
|
|
|
|
<div class="fear_summary"> |
|
|
|
|
<span class="available_fear_cards">{{ status.available_fear_cards }}</span> |
|
|
|
|
😱🎴; |
|
|
|
@ -32,7 +32,7 @@ |
|
|
|
|
<div class="player player-{{ player.order }}"> |
|
|
|
|
<label for="player-{{ player.order }}-visible"> |
|
|
|
|
<div class="player-summary"> |
|
|
|
|
{% if player.ready %}🏁{% else %}⏳{% endif %} |
|
|
|
|
<span class="player-{{ player.order }}-ready">{% if player.ready %}🏁{% else %}⏳{% endif %}</span> |
|
|
|
|
(<span class="player-total-fear player-{{ player.order }}-total-fear">{{ player.total_fear }}</span> 😱) |
|
|
|
|
{{ player.name }} ({{ player.get_spirit_name }}) |
|
|
|
|
</div> |
|
|
|
@ -90,32 +90,117 @@ |
|
|
|
|
</div> |
|
|
|
|
{% endfor %} |
|
|
|
|
</div> |
|
|
|
|
<input type="submit" name="update" value="Update fear"> |
|
|
|
|
<input type="submit" name="advance" value="Advance to next phase"{% if not all_ready %} disabled{% endif %}> |
|
|
|
|
<input type="submit" name="revert" value="Revert to previous phase"> |
|
|
|
|
<input type="submit" name="update" class="update-button" value="Update fear"> |
|
|
|
|
<input type="submit" name="advance" class="advance-button" value="Advance to next phase"{% if not all_ready %} disabled{% endif %}> |
|
|
|
|
<input type="submit" name="revert" class="revert-button" value="Revert to previous phase"> |
|
|
|
|
</form> |
|
|
|
|
{% block game_refresh %} |
|
|
|
|
{% if not results_only %} |
|
|
|
|
<div class="button-container"> |
|
|
|
|
<a href="{% url 'game' access_code=access_code %}" class="button" id="button-refresh">Refresh</a> |
|
|
|
|
</div> |
|
|
|
|
<script> |
|
|
|
|
var statusObj = JSON.parse("{{ status_json|escapejs }}"); |
|
|
|
|
function handleNewStatus(oldStatus, newStatus) { |
|
|
|
|
{% block game_handle_new_status %} |
|
|
|
|
{% endif %} |
|
|
|
|
{% endblock %} |
|
|
|
|
{% endblock %} |
|
|
|
|
{% block header_script %} |
|
|
|
|
{% if not results_only %} |
|
|
|
|
<script> |
|
|
|
|
var statusObj = JSON.parse("{{ status_json|escapejs }}"); |
|
|
|
|
function handleNewStatus(oldStatus, newStatus) { |
|
|
|
|
{% block game_handle_new_status %} |
|
|
|
|
if(oldStatus.hash == newStatus.hash) return true; |
|
|
|
|
if(oldStatus.phase_id != newStatus.phase_id |
|
|
|
|
|| oldStatus.turn != newStatus.turn) { |
|
|
|
|
// Reload for new phase. |
|
|
|
|
return false; |
|
|
|
|
{% endblock %} |
|
|
|
|
} |
|
|
|
|
setInterval(function() { |
|
|
|
|
$.get("{% url 'status' access_code=access_code hash=status.hash %}", function(data, textStatus, jqXHR) { |
|
|
|
|
if(JSON.stringify(data) != JSON.stringify(statusObj)) { |
|
|
|
|
if(!handleNewStatus(statusObj, data)) { |
|
|
|
|
document.getElementById("button-refresh").click(); |
|
|
|
|
|
|
|
|
|
let form = document.forms[0]; |
|
|
|
|
for(let key in newStatus) { |
|
|
|
|
if(key == "hash" || key == "phase_id" || key == "total_fear") { |
|
|
|
|
// ignored |
|
|
|
|
} else if(key == "all_ready") { |
|
|
|
|
let all_ready = newStatus[key] |
|
|
|
|
for(let el of document.getElementsByClassName("advance-button")) { |
|
|
|
|
el.disabled = !all_ready; |
|
|
|
|
} |
|
|
|
|
} else if(key == "players") { |
|
|
|
|
// TODO |
|
|
|
|
let players = newStatus[key]; |
|
|
|
|
for(let ord in players) { |
|
|
|
|
let prefix = "player-" + ord + "-"; |
|
|
|
|
let player = players[ord]; |
|
|
|
|
for(let pkey in player) { |
|
|
|
|
if(pkey == "ready") { |
|
|
|
|
let ready = player[pkey]; |
|
|
|
|
for(let el of document.getElementsByClassName(prefix + "ready")) { |
|
|
|
|
el.innerText = ready ? "🏁" : "⏳"; |
|
|
|
|
} |
|
|
|
|
document.getElementById(prefix + "ready-orig").value = ready; |
|
|
|
|
document.getElementById(prefix + "ready").checked = ready; |
|
|
|
|
} else if(pkey == "total_fear") { |
|
|
|
|
let total_fear = player[pkey]; |
|
|
|
|
for(let el of document.getElementsByClassName(prefix + "total-fear")) { |
|
|
|
|
el.innerText = total_fear; |
|
|
|
|
} |
|
|
|
|
} else if(pkey == "fear") { |
|
|
|
|
let fear = player[pkey]; |
|
|
|
|
for(let effect_num in fear) { |
|
|
|
|
let fprefix = prefix + "effect-" + effect_num + "-"; |
|
|
|
|
let effect = fear[effect_num]; |
|
|
|
|
for(let ekey in effect) { |
|
|
|
|
let value = effect[ekey]; |
|
|
|
|
let eclass = ekey == "pure_fear" ? "fear" : ekey; |
|
|
|
|
let eprefix = fprefix + eclass; |
|
|
|
|
form.elements[eprefix].value = value; |
|
|
|
|
form.elements[eprefix + "-orig"].value = value; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
alert("Unknown player status key: " + pkey + "=" + player[pkey]); |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}, "json"); |
|
|
|
|
}, 5000); |
|
|
|
|
</script> |
|
|
|
|
} else { |
|
|
|
|
var matching_elements = document.getElementsByClassName("status-" |
|
|
|
|
+ key); |
|
|
|
|
if(matching_elements.length == 0) { |
|
|
|
|
matching_elements = document.getElementsByClassName(key); |
|
|
|
|
} |
|
|
|
|
if(matching_elements.length == 0) { |
|
|
|
|
alert("Unknown status key: " + key + "=" + newStatus[key]); |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let value = newStatus[key]; |
|
|
|
|
for(let el of matching_elements) { |
|
|
|
|
el.innerText = value; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return true; |
|
|
|
|
{% endblock %} |
|
|
|
|
} |
|
|
|
|
setInterval(function() { |
|
|
|
|
fetch(new Request("{% url 'status' access_code=access_code %}" |
|
|
|
|
+ statusObj.hash + "/")) |
|
|
|
|
.then(response => { |
|
|
|
|
if(response.status === 304) { |
|
|
|
|
// TODO Just skip the next step? |
|
|
|
|
return statusObj; |
|
|
|
|
} else { |
|
|
|
|
return response.json(); |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
.then(data => { |
|
|
|
|
if(!handleNewStatus(statusObj, data)) { |
|
|
|
|
document.getElementById("button-refresh").click(); |
|
|
|
|
} else { |
|
|
|
|
statusObj = data; |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
}, 5000); |
|
|
|
|
</script> |
|
|
|
|
{% endif %} |
|
|
|
|
{% endblock %} |
|
|
|
|
{% endblock %} |
|
|
|
|