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

@ -385,25 +385,6 @@
</div> </div>
{% endfor %} {% endfor %}
</div> </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 src="/socket.io.js"></script>
<script> <script>
@ -414,35 +395,22 @@
game_id = '{{ game_id }}'; game_id = '{{ game_id }}';
player_name = '{{ player_name }}'; player_name = '{{ player_name }}';
console.log('{{ gamestate.game_end }}');
// if gamestatus ended then redirect to the enscreen // if gamestatus ended then redirect to the enscreen
if ('{{ gamestate.game_end }}') { // {% if gamestate.game_end %}
window.location.href = '/gametitle/{{ game_id }}'; window.location.href = '/gametitle/{{ game_id }}';
} // {% else %}
// if local_game is tru change player (comments are not ignored by jinja)
// if local_game is tru change player (comments are not ignored by jinja) //{% if local_game %}
//{% if local_game %} //{% for player, data in gamestate.players.items() %}
current_player = '{{ gamestate.current_player }}'; //{% if not data.ready %}
if (player_name != current_player) { window.location.href = '/game/{{ game_id }}/player/{{player}}/local/True';
window.location.href = '/game/{{ game_id }}/player/' + current_player + '/local/True'; //{% elif player_name != gamestate.current_player %}
} window.location.href = '/game/{{ game_id }}/player/{{ gamestate.current_player }}/local/True';
//{% endif %}
//if the market only contains the start tile, //{% endfor %}
market = JSON.parse('{{ gamestate.market | tojson }}'); //{% endif %}
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';
}
}
//{% endif %} //{% endif %}
// Define the dragstart event handler // Define the dragstart event handler

View File

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