import * as env from "../env.js" import * as status from "./status.js" import {game} from "../game/game.js" import {render} from "../display/draw.js" import { changeScene } from "../interface/scene.js" import { illegalAction } from "../illegalaction.js" export var socket = io.connect(env.IP_ADDRESS); export function joinGame(data){ socket.emit('joinGame', data); } export function initJoin(code){ socket.emit('initJoin', code) } export function createGame(data){ socket.emit('createGame', data); } export function clickCanvas(data) { socket.emit('clickCanvas', data); } function leaveGame(socket){ socket.emit('leaveGame', {}); } socket.on('connect', function(data){ status.connected() }) socket.on('disconnect', function(data){ status.disconnected() }) socket.on('message', function(data) { const mess = document.getElementById("message") mess.textContent = `${data}` }) socket.on('illegalAction', function(data){ let action illegalAction(data) switch (data) { case 1: action = "You must be in game to do this." changeScene("mainmenu"); game.reset(); break; } }) socket.on('metadata', function(data){ console.log(data) }); socket.on('inGame', function(data){ if (!game.status) {changeScene("game")} game.status = true; }) socket.on('sync', function (sync){ game.world = sync.world; render() })