MultiplayerMinesweeper/client/scripts/interface/mainmenu/menu.js

34 lines
853 B
JavaScript
Raw Permalink Normal View History

import * as status from "../../net/status.js"
2023-04-03 19:26:24 +00:00
import {joinGame, initJoin} from "../../net/netcode.js"
import { changeScene } from "../scene.js"
2022-07-20 03:50:48 +00:00
import {ID} from "../../util.js"
const codeInput = ID("joinGameCode")
codeInput.addEventListener("input", e => {
e.target.value = e.target.value.toUpperCase().replace(/[^0-9a-z]/gi, '')
})
2022-06-23 19:27:36 +00:00
ID("gotoCreate").addEventListener("click", e => {
2022-07-20 03:50:48 +00:00
changeScene("newgame")
})
ID("gotoJoin").addEventListener("click", e => {
2022-07-20 03:50:48 +00:00
if (codeInput.value.length !== 6) return console.log("error")
2023-04-03 19:26:24 +00:00
initJoin(codeInput.value)
})
ID("joinGameButton").addEventListener("click", e => {
join(e)
});
function join(event) {
const roomCode = ID("joinGameCode").value
const name = ID("joinGameUsername").value
if (roomCode == '' || name == '' || status.get() == 'disconnected') return
joinGame({room: roomCode, name: name})
}