ft_transcendence/frontend/static/js/views/MatchMakingView.js

54 lines
1.2 KiB
JavaScript
Raw Normal View History

2023-12-12 06:06:13 -05:00
import { client, navigateTo } from "../index.js";
import AbstractView from "./abstracts/AbstractView.js";
2023-12-11 07:40:01 -05:00
2023-12-12 06:06:13 -05:00
function game_found(game_id)
{
navigateTo(`/games/${game_id}`)
}
2023-12-11 07:40:01 -05:00
export default class extends AbstractView {
constructor(params)
{
super(params, "Matchmaking");
}
async press_button()
{
if (client.matchmaking.searching)
{
client.matchmaking.stop();
document.getElementById("button").value = "Find a game"
}
else
{
await this.matchmaking();
document.getElementById("button").value = "Stop matchmaking"
}
}
async matchmaking()
{
let nb_players = document.getElementById("nb_players-input").value
client.matchmaking.start(game_found, nb_players);
2023-12-11 07:40:01 -05:00
}
2023-12-12 06:06:13 -05:00
async postInit()
{
document.getElementById("button").onclick = this.matchmaking
2023-12-12 06:06:13 -05:00
}
2023-12-11 07:40:01 -05:00
async getHtml() {
return `
<h1>Select mode<h1>
<input type="number" value="2" id="nb_players-input">
<input type="button" value="Find a game" id="button">
2023-12-11 07:40:01 -05:00
`;
}
2023-12-12 06:06:13 -05:00
async leavePage()
{
await client.matchmaking.stop();
}
}