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

37 lines
970 B
JavaScript
Raw Normal View History

import * as status from "../../net/status.js"
// import {joinGame, createGame} from "../../net/netcode.js"
import { changeScene } from "../scene.js"
2022-07-20 03:50:48 +00:00
import {ID} from "../../util.js"
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, '')
})
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")
net.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})
}