2022-06-20 00:18:47 +00:00
|
|
|
import * as status from "../../net/status.js"
|
2023-04-03 19:26:24 +00:00
|
|
|
import {joinGame, initJoin} from "../../net/netcode.js"
|
2022-06-24 18:42:39 +00:00
|
|
|
import { changeScene } from "../scene.js"
|
2022-07-20 03:50:48 +00:00
|
|
|
|
2022-06-24 19:13:56 +00:00
|
|
|
import {ID} from "../../util.js"
|
2022-06-23 01:14:51 +00:00
|
|
|
|
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 => {
|
2022-07-20 03:50:48 +00:00
|
|
|
changeScene("newgame")
|
2022-06-23 01:14:51 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
ID("gotoJoin").addEventListener("click", e => {
|
2022-07-20 03:50:48 +00:00
|
|
|
if (codeInput.value.length !== 6) return console.log("error")
|
2023-04-03 19:26:24 +00:00
|
|
|
initJoin(codeInput.value)
|
2022-06-23 01:14:51 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
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
|
|
|
}
|