2022-06-20 00:18:47 +00:00
|
|
|
import * as status from "../../net/status.js"
|
2022-06-23 01:14:51 +00:00
|
|
|
import {joinGame, createGame} from "/scripts/net/netcode.js"
|
2022-06-20 00:18:47 +00:00
|
|
|
import { changeScene } from "/scripts/interface/scene.js"
|
2022-06-23 19:27:36 +00:00
|
|
|
import * as createMenu from "./create.js"
|
2022-06-20 00:18:47 +00:00
|
|
|
|
2022-06-23 01:14:51 +00:00
|
|
|
function ID(id) {
|
|
|
|
return document.getElementById(id)
|
|
|
|
}
|
|
|
|
|
|
|
|
const joinType = ID("joinType")
|
|
|
|
const joinGameMenu = ID("joinGame")
|
|
|
|
const createGameMenu = ID("createGame")
|
2022-06-24 12:10:06 +00:00
|
|
|
const codeInput = ID("joinGameCode")
|
|
|
|
|
|
|
|
codeInput.addEventListener("input", e => {
|
|
|
|
e.target.value = e.target.value.toUpperCase().replace(/[^0-9a-z]/gi, '')
|
|
|
|
})
|
2022-06-23 01:14:51 +00:00
|
|
|
|
2022-06-23 19:27:36 +00:00
|
|
|
|
2022-06-23 01:14:51 +00:00
|
|
|
ID("gotoCreate").addEventListener("click", e => {
|
|
|
|
joinType.style.display = "none"
|
|
|
|
createGameMenu.style.display = ""
|
2022-06-23 19:27:36 +00:00
|
|
|
createMenu.init()
|
2022-06-23 01:14:51 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
ID("gotoJoin").addEventListener("click", e => {
|
|
|
|
joinType.style.display = "none"
|
|
|
|
joinGameMenu.style.display = "";
|
|
|
|
})
|
|
|
|
|
|
|
|
ID("joinGameButton").addEventListener("click", e => {
|
|
|
|
join(e)
|
2022-06-20 00:18:47 +00:00
|
|
|
});
|
|
|
|
|
2022-06-23 01:14:51 +00:00
|
|
|
function join(event) {
|
|
|
|
const roomCode = ID("joinGameCode").value
|
|
|
|
const name = ID("joinGameUsername").value
|
2022-06-23 05:44:57 +00:00
|
|
|
if (roomCode == '' || name == '' || status.get() == 'disconnected') return
|
2022-06-23 01:14:51 +00:00
|
|
|
joinGame({room: roomCode, name: name})
|
2022-06-20 00:59:51 +00:00
|
|
|
|
2022-06-20 00:18:47 +00:00
|
|
|
}
|