Pick phase waiting screen updates using AJAX.

pull/11/head
Daniel Perelman 8 years ago
parent cd6ab95923
commit 79d4a98628

@ -8,8 +8,7 @@
<a href="{% url 'game' access_code=access_code player_secret=player_secret %}" class="button" id="button-refresh">Refresh</a>
</div>
<script>
var status = "{{ status|escapejs }}";
var statusObj = JSON.parse(status);
var statusObj = JSON.parse("{{ status|escapejs }}");
function handleNewStatus(oldStatus, newStatus) {
{% block game_handle_new_status %}
return false;
@ -17,12 +16,12 @@
}
setInterval(function() {
$.get("{% url 'status' access_code=access_code player_secret=player_secret %}", function(data, textStatus, jqXHR) {
if(jqXHR.responseText != status) {
if(!handleNewStatus(statusObj, JSON.parse(data))) {
if(JSON.stringify(data) != JSON.stringify(statusObj)) {
if(!handleNewStatus(statusObj, data)) {
document.getElementById("button-refresh").click();
}
}
});
}, "json");
}, 5000);
</script>
{% endblock %}

@ -10,16 +10,43 @@
{% endif %}
This will be vote #{{ vote_num }} of 5 for this mission.
{% if chosen %}
<p>Your leader, <b class="role">{{ leader.name }}</b>, is choosing {{ team_size }} players for mission {{ round_num }}: </p>
<p>Your leader, <b class="role">{{ leader.name }}</b>, is choosing {{ team_size }} players for mission {{ round_num }}: </p>
<ul id="chosen-for-mission">
{% for chosen_player in chosen %}
<li>{{ chosen_player.name }}</li>
{% endfor %}
{% endif %}
</ul>
<p id="you-chosen">
{% if player in chosen %}
<p>You have been chosen!</p>
{% else %}
<p>Please wait while your leader, {{ leader.name }}, chooses a team of {{ team_size }} players for mission {{ round_num }}.</p>
You have been chosen!
{% endif %}
</p>
</div>
{% endblock %}
{% block game_handle_new_status %}
if(oldStatus.game_phase == newStatus.game_phase
&& oldStatus.round_num == newStatus.round_num
&& oldStatus.vote_num == newStatus.vote_num) {
if(JSON.stringify(oldStatus.chosen)
!= JSON.stringify(newStatus.chosen)) {
chosen_list = document.getElementById('chosen-for-mission');
$(chosen_list).empty();
newStatus.chosen.forEach(function(name) {
var el = document.createElement('li');
el.innerText = name;
chosen_list.appendChild(el);
});
statusObj.chosen = newStatus.chosen;
}
if(statusObj.you_chosen != newStatus.you_chosen) {
$('#you-chosen').text(newStatus.you_chosen
? "You have been chosen!"
: "");
statusObj.you_chosen = newStatus.you_chosen;
}
return true;
} else {
return false;
}
{% endblock %}

@ -103,6 +103,7 @@ def game_status_string(game, player):
if game.game_phase == Game.GAME_PHASE_PICK:
chosen = vote_round.chosen.order_by('order').all()
game_status_object['chosen'] = [p.name for p in chosen]
game_status_object['you_chosen'] = player in chosen
elif game.game_phase == Game.GAME_PHASE_VOTE:
votes_cast = PlayerVote.objects.filter(vote_round=vote_round).count()
game_status_object['missing_votes_count'] = num_players - votes_cast

Loading…
Cancel
Save