player redirect fixes

This commit is contained in:
Adrian Gunnar Lauterer 2024-03-30 18:05:22 +01:00
parent bb4a86c29d
commit dcc5cac9e3
Signed by: adriangl
GPG Key ID: D33368A59745C2F0
2 changed files with 46 additions and 61 deletions

View File

@ -386,25 +386,6 @@
{% endfor %}
</div>
{% if player_name %}
<!-- form for submitting a move, a move is a selection of marcet or factory, what color, and what patternline or floor it goes to. -->
<!-- button to go to next player -->
{% if local_game %}
{% set current_index = gamestate.player_names.index(player_name) %}
{% set next_index = current_index + 1 if current_index + 1 < gamestate.player_names|length else 0 %}
<a href="/game/{{ game_id }}/player/{{ gamestate.player_names[next_index] }}/local/True">Next Player</a>
{% endif %}
{% endif %}
<script src="/socket.io.js"></script>
<script>
console.log('Game ID: {{ game_id }}');
@ -414,35 +395,22 @@
game_id = '{{ game_id }}';
player_name = '{{ player_name }}';
console.log('{{ gamestate.game_end }}');
// if gamestatus ended then redirect to the enscreen
if ('{{ gamestate.game_end }}') {
// {% if gamestate.game_end %}
window.location.href = '/gametitle/{{ game_id }}';
}
// if local_game is tru change player (comments are not ignored by jinja)
//{% if local_game %}
current_player = '{{ gamestate.current_player }}';
if (player_name != current_player) {
window.location.href = '/game/{{ game_id }}/player/' + current_player + '/local/True';
}
//if the market only contains the start tile,
market = JSON.parse('{{ gamestate.market | tojson }}');
if (market['start'] == 1 && market['blue'] == 0 && market['yellow'] == 0 && market['red'] == 0 && market['black'] == 0 && market['white'] == 0) {
//if all the factories do not contain any tiles, switch to the next player
factories = JSON.parse('{{ gamestate.factories | tojson }}');
factory_tile_count = 0;
for (var i = 0; i < factories.length; i++) {
for (var color in factories[i]) {
factory_tile_count += factories[i][color];
}
}
if (factory_tile_count == 0) {
next_player = '{{ gamestate.player_names[(gamestate.player_names.index(gamestate.current_player) + 1) % gamestate.player_names|length] }}';
window.location.href = '/game/{{ game_id }}/player/' + next_player + '/local/True';
}
}
// {% else %}
// if local_game is tru change player (comments are not ignored by jinja)
//{% if local_game %}
//{% for player, data in gamestate.players.items() %}
//{% if not data.ready %}
window.location.href = '/game/{{ game_id }}/player/{{player}}/local/True';
//{% elif player_name != gamestate.current_player %}
window.location.href = '/game/{{ game_id }}/player/{{ gamestate.current_player }}/local/True';
//{% endif %}
//{% endfor %}
//{% endif %}
//{% endif %}
// Define the dragstart event handler

View File

@ -10,33 +10,42 @@
margin-top: 20%;
color: white;
}
#losers-podium {
display: none;
font-size: 1.5em;
text-align: center;
color: white;
}
body {
background-color: #2C3235;
}
.flex {
display: flex;
justify-content:space-between;
align-items:center;
flex-direction: column;
height: 70vh;
}
</style>
<script src="https://cdn.jsdelivr.net/npm/canvas-confetti@1.3.2"></script>
</head>
<body>
<div id="win-screen"></div>
<div class="flex">
<div id="win-screen"></div>
<div id="losers-podium"></div>
</div>
<script>
var gamestate = JSON.parse('{{ gamestate | tojson }}');
var winnerpoints = 0
var winner = null;
console.log(gamestate.players)
//for each player in the gamestate object not a list
var players = [];
for (player in gamestate.players) {
console.log(gamestate.players[player])
//if the player's points are greater than the winnerpoints
if (gamestate.players[player]['points'] > winnerpoints) {
//set the winnerpoints to the player's points
winnerpoints = gamestate.players[player]['points'];
//set the winner to the player
winner = gamestate.players[player];
winner['name'] = player;
}
gamestate.players[player]['name'] = player;
players.push(gamestate.players[player]);
}
var winnerName = winner['name'];
players.sort((a, b) => b.points - a.points);
var winner = players.shift();
var winnerName = winner.name;
var winnerpoints = winner.points;
function showWinScreen() {
// Display confetti
@ -50,6 +59,14 @@
var winScreen = document.getElementById('win-screen');
winScreen.innerHTML = "<strong>" + winnerName + "</strong> wins!" + "<br>" + "with <strong>" + winnerpoints + "</strong> points";
winScreen.style.display = 'block';
// Display losers
var losersPodium = document.getElementById('losers-podium');
losersPodium.innerHTML = "<strong>Losers:</strong><br>";
players.forEach(player => {
losersPodium.innerHTML += player.name + ": " + player.points + " points<br>";
});
losersPodium.style.display = 'block';
}
showWinScreen();