Only switch to game view when response is recieved from server.

This commit is contained in:
Alexander Bass 2022-06-19 20:59:51 -04:00
parent c406819dce
commit 90f73caefe
5 changed files with 15 additions and 10 deletions

View file

@ -126,6 +126,7 @@ io.on('connection', function(client) {
client.illegalAction = function(action) {
client.emit('illegalAction', action)
}
log.log('User connected', 'FgGreen');

View file

@ -1,9 +1,12 @@
class Game {
constructor(tileSize, gridSize, world) {
constructor(tileSize, gridSize, world, status) {
this.tileSize = tileSize;
this.gridSize = gridSize;
this.world = world;
this.status = "none";
this.status = status;
}
reset() {
game = new Game(24, [18, 18], null, false);
}
}

View file

@ -12,5 +12,5 @@ function submit(event) {
if (room == '' || name == '' || status.get() == 'disconnected') return
joinGame({room: room, name: name})
event.preventDefault();
changeScene("game")
}

View file

@ -2,6 +2,7 @@ import * as env from "/scripts/env.js"
import * as status from "/scripts/net/status.js"
import {game} from "/scripts/game/game.js"
import {render} from "/scripts/display/draw.js"
import { changeScene } from "/scripts/interface/scene.js"
export var socket = io.connect(env.IP_ADDRESS);
export function joinGame(data){
@ -28,6 +29,8 @@ socket.on('illegalAction', function(data){
switch (data) {
case 1:
action = "You must be in game to do this."
changeScene("mainmenu");
game.reset();
break;
case 20:
action = "That name is already taken."
@ -48,7 +51,7 @@ socket.on('playerList', function(data){
});
socket.on('inGame', function(data){
if (!game.status) {changeScene()}
if (!game.status) {changeScene("game")}
game.status = true;
})
@ -58,6 +61,6 @@ socket.on('sync', function (sync){
})
window.onbeforeunload = function(){
socket.disconnect();
game.world = []
}

View file

@ -1,6 +1,4 @@
import { render } from './display/draw.js';
import { game } from './game/game.js'
import * as menu from './interface/mainmenu/menu.js'
import * as net from "/scripts/net/netcode.js"
var button
import './game/game.js'
import './interface/mainmenu/menu.js'
import "/scripts/net/netcode.js"