Make the JoinLobby modal nicer
This commit is contained in:
parent
bcc0664342
commit
c340755ba2
2 changed files with 20 additions and 12 deletions
|
|
@ -1,22 +1,24 @@
|
|||
<script lang="ts">
|
||||
import { isHost, myName, gameCode, players, state } from "../../stores";
|
||||
import { onDestroy, createEventDispatcher, onMount } from "svelte";
|
||||
import { isHost, myName, gameCode, players } from "../../stores";
|
||||
import SciFiButton from "../SciFi-Button.svelte";
|
||||
import { ILobbyInfo, Status } from "common";
|
||||
import { onDestroy, onMount } from "svelte";
|
||||
import BaseModal from "./BaseModal.svelte";
|
||||
import { socket } from "../../main";
|
||||
|
||||
const emit = createEventDispatcher();
|
||||
|
||||
export let open: boolean = false;
|
||||
export let joining: boolean = false;
|
||||
export let joining: boolean;
|
||||
|
||||
let errorMessage: string|null = null;
|
||||
|
||||
function handleLobbyConnection(data: ILobbyInfo) {
|
||||
if (data.status == Status.Success) {
|
||||
console.log(`Succesfully joined lobby`);
|
||||
console.debug(`Succesfully joined lobby`);
|
||||
gameCode.set(data.game_code);
|
||||
players.set(data.players);
|
||||
state.set(`multiplayer-lobby`);
|
||||
emit(`joined`);
|
||||
} else {
|
||||
console.error(data);
|
||||
errorMessage = data.message;
|
||||
|
|
@ -24,20 +26,17 @@ function handleLobbyConnection(data: ILobbyInfo) {
|
|||
};
|
||||
|
||||
onMount(() => {
|
||||
if (joining) {
|
||||
socket.on(`res:lobby.players.join`, handleLobbyConnection);
|
||||
} else {
|
||||
socket.on(`res:lobby.create`, handleLobbyConnection);
|
||||
};
|
||||
socket.on(`res:lobby.players.join`, handleLobbyConnection);
|
||||
socket.on(`res:lobby.create`, handleLobbyConnection);
|
||||
});
|
||||
|
||||
function connectToLobby() {
|
||||
errorMessage = null;
|
||||
isHost.set(joining);
|
||||
isHost.set(!joining);
|
||||
|
||||
// Emit the correct event for the modal type
|
||||
if (joining) {
|
||||
socket.emit(`req:lobby.players.create`, {
|
||||
socket.emit(`req:lobby.players.join`, {
|
||||
name: $myName,
|
||||
game_code: $gameCode,
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue