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

39 lines
928 B
JavaScript
Raw Normal View History

import * as status from "../../net/status.js"
import {joinGame, createGame} from "/scripts/net/netcode.js"
import { changeScene } from "/scripts/interface/scene.js"
2022-06-23 19:27:36 +00:00
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")
2022-06-23 19:27:36 +00:00
ID("gotoCreate").addEventListener("click", e => {
joinType.style.display = "none"
createGameMenu.style.display = ""
2022-06-23 19:27:36 +00:00
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})
}