ozai-webui/templates/create.html

53 lines
2.0 KiB
HTML

<!-- HTML -->
<!DOCTYPE html>
<html>
<head>
<title>Create Game</title>
</head>
<body>
{% if not game_id %}
<form method="POST" action="/create">
<div>Fill inn playernames for wanted players ...</div>
<div>Leave empty for no player ...</div>
<input type="text" name="player1" placeholder="Player 1" required>
<input type="text" name="player2" placeholder="Player 2" required>
<input type="text" name="player3" placeholder="Player 3">
<input type="text" name="player4" placeholder="Player 4">\
<!-- Add more input fields for more players -->
<input type="submit" value="Create Game">
</form>
<button onclick="window.history.back();">Back</button>
<script>
// Select all player input elements
var playerInputs = document.querySelectorAll('input[name^="player"]');
// Attach event listener to each input
playerInputs.forEach(function(input) {
input.addEventListener('change', function() {
var currentValue = this.value;
console.log(currentValue);
var isUnique = Array.from(playerInputs).every(function(otherInput) {
return otherInput === input || otherInput.value !== currentValue;
});
if (!isUnique && currentValue !== "") {
alert('Player names must be unique!');
// append a number to the name
this.value = "";
}
});
});
</script>
{% endif %}
{% if game_id %}
<p>Your game ID is: {{ game_id }}</p>
<!-- button to redirect to /join/gameid -->
<a href="/join_game/{{ game_id }}">Join Game</a>
<script>
// Save game ID in browser session for auto fill in join page
sessionStorage.setItem('game_id', '{{ game_id }}');
alert('Game created with ID: {{ game_id }}');
</script>
{% endif %}
</body>
</html>