fix: matchmaking support start stop, multi connection

This commit is contained in:
2023-12-23 16:47:22 +01:00
parent 6c39a13aca
commit c02c49215d
5 changed files with 92 additions and 32 deletions

View File

@ -1,11 +1,7 @@
import { client, navigateTo } from "../index.js";
import { clear, fill_errors } from "../utils/formUtils.js";
import AbstractView from "./abstracts/AbstractView.js";
function game_found(game_id)
{
navigateTo(`/games/${game_id}`)
}
export default class extends AbstractView {
constructor(params)
{
@ -21,28 +17,36 @@ export default class extends AbstractView {
}
else
{
await this.matchmaking();
let nb_players = document.getElementById("nb_players-input").value
await client.matchmaking.start(this.display_data, this.ondisconnect, nb_players);
document.getElementById("button").value = "Stop matchmaking"
}
}
async matchmaking()
ondisconnect()
{
let nb_players = document.getElementById("nb_players-input").value
document.getElementById("button").value = "Find a game"
}
client.matchmaking.start(game_found, nb_players);
display_data(data)
{
clear("innerText", ["detail"]);
fill_errors(data, "innerText");
}
async postInit()
{
document.getElementById("button").onclick = this.matchmaking
document.getElementById("button").onclick = this.press_button.bind(this)
}
async getHtml() {
return `
<h1>Select mode<h1>
<h1>Select mode</h1>
<input type="number" value="2" id="nb_players-input">
<input type="button" value="Find a game" id="button">
<span id="detail"></span>
`;
}