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

42 lines
1 KiB
JavaScript

import * as status from "../../net/status.js"
// import {joinGame, createGame} from "../../net/netcode.js"
import { changeScene } from "../scene.js"
import * as createMenu from "./create.js"
function ID(id) {
return document.getElementById(id)
}
const joinType = ID("joinType")
const joinGameMenu = ID("joinGame")
const createGameMenu = ID("createGame")
const codeInput = ID("joinGameCode")
codeInput.addEventListener("input", e => {
e.target.value = e.target.value.toUpperCase().replace(/[^0-9a-z]/gi, '')
})
ID("gotoCreate").addEventListener("click", e => {
joinType.style.display = "none"
createGameMenu.style.display = ""
createMenu.init()
})
ID("gotoJoin").addEventListener("click", e => {
joinType.style.display = "none"
joinGameMenu.style.display = "";
})
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})
}