140 lines
3.2 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Games</title>
<!-- TODO: Add script and style to static(didn't wanna do that fuck) -->
<style>
/* change font to roboto */
body {
font-family: 'Roboto', sans-serif;
/* Gray to darker gray full-page gradient */
}
a {
text-decoration: none;
color: black;
}
.underline {
display: inline-block;
position: relative;
}
.underline::after {
content: '';
position: absolute;
width: 100%;
transform: scaleX(0);
height: 2px;
bottom: 0;
left: 0;
background-color: gray;
transform-origin: bottom right;
transition: transform 0.25s ease-out;
}
.underline:hover::after {
transform: scaleX(1);
transform-origin: bottom left;
}
#header {
width: 100%;
background: linear-gradient(180deg, #ECECEC 0%, #D9D9D9 100%);
text-align: center;
margin-bottom: 10px;
padding: 5px;
}
.content{
display:flex;
flex-wrap: wrap;
justify-content: space-evenly;
}
.games {
background: white;
border-radius: 10px;
border: 1px solid black;
padding: 10px;
margin:10px;
color: black;
text-align: center;
flex-shrink: calc(100% / 3 - 20px);
}
.zoom {
transition: transform .5s; /* Animation */
}
.zoom:hover {
transform: scale(1.1); /* (150% zoom - Note: if the zoom is too large, it will go outside of the viewport) */
}
</style>
<script>
// Create a game and return its json
function createGame() {
let game = prompt("What game are we playing?")
let players = Number(prompt("How many players?"))
let data = {name: game, players: players}
fetch(`/new/${game}/${players}`, {
method: 'POST',
})
.then(response => response.json())
.then(data => {
console.log('Success:', data);
document.getElementById("create").innerHTML = "Game created!";
document.getElementById("create").onclick = redirect(data.id);
// make a href to the game
})
}
function redirect(game_id) {
window.location.replace(`/games/${game_id}`)
}
</script>
</head>
<body>
<div id = "header">
<h1>Game Lobby</h1>
<p>Create a game or join one(programmatically)!</p>
</div>
<div class="content">
<!-- List all active games if there is a game -->
<!-- Given a list of dictionaries passed by flask -->
{% if games %}
<table>
{% for game in games %}
<!-- <li>
<a href="/games/{{ game['id'] }}">{{ game['game'] }}</a>
</li> -->
<a href="/games/{{game['id']}}">
<div class="games zoom underline">
<h4> {{game['game']}} </h4>
<!-- horizontal line -->
<hr>
<p>{{game['in']|length}}/{{game['players']}} players </p>
<p> {{game['status']}} </p>
</div>
</a>
{% endfor %}
</table>
{% else %}
<h1>No one's playing...</h1>
<h2 onclick="createGame()", id="create"> Create one?</h2>
{% endif %}
</div>
</body>
</html>