MultiplayerMinesweeper/www/scripts/interface/mainmenu/menu.js
Alexander Bass fe794b69a9 Before starting work on only sending changes in world
Doing this to allow for stupidly big worlds (also better network usage)
2022-06-24 08:10:06 -04:00

42 lines
1.1 KiB
JavaScript

import * as status from "../../net/status.js"
import {joinGame, createGame} from "/scripts/net/netcode.js"
import { changeScene } from "/scripts/interface/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})
}