34 lines
853 B
JavaScript
34 lines
853 B
JavaScript
import * as status from "../../net/status.js"
|
|
import {joinGame, initJoin} from "../../net/netcode.js"
|
|
import { changeScene } from "../scene.js"
|
|
|
|
import {ID} from "../../util.js"
|
|
|
|
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 => {
|
|
changeScene("newgame")
|
|
})
|
|
|
|
ID("gotoJoin").addEventListener("click", e => {
|
|
if (codeInput.value.length !== 6) return console.log("error")
|
|
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})
|
|
|
|
}
|