2022-06-20 00:18:47 +00:00
|
|
|
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"
|
2022-06-20 00:59:51 +00:00
|
|
|
import { changeScene } from "/scripts/interface/scene.js"
|
2022-06-20 02:39:31 +00:00
|
|
|
import { illegalAction } from "/scripts/interface/common/illegalaction.js"
|
|
|
|
|
2022-06-20 00:18:47 +00:00
|
|
|
export var socket = io.connect(env.IP_ADDRESS);
|
|
|
|
|
|
|
|
export function joinGame(data){
|
|
|
|
socket.emit('joinGame', data);
|
|
|
|
}
|
|
|
|
|
2022-06-23 01:14:51 +00:00
|
|
|
export function createGame(data){
|
|
|
|
socket.emit('createGame', data);
|
|
|
|
}
|
|
|
|
|
2022-06-20 00:18:47 +00:00
|
|
|
export function clickCanvas(data) {
|
|
|
|
socket.emit('clickCanvas', data);
|
|
|
|
}
|
|
|
|
|
|
|
|
function leaveGame(socket){
|
|
|
|
socket.emit('leaveGame', {});
|
|
|
|
}
|
|
|
|
|
|
|
|
socket.on('connect', function(data){
|
|
|
|
status.connected()
|
|
|
|
})
|
2022-06-24 15:24:22 +00:00
|
|
|
|
2022-06-20 00:18:47 +00:00
|
|
|
socket.on('disconnect', function(data){
|
|
|
|
status.disconnected()
|
|
|
|
})
|
|
|
|
|
2022-06-23 01:14:51 +00:00
|
|
|
socket.on('message', function(data) {
|
|
|
|
const mess = document.getElementById("message")
|
2022-06-23 05:44:57 +00:00
|
|
|
mess.textContent = `${data}`
|
2022-06-23 01:14:51 +00:00
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
2022-06-20 00:18:47 +00:00
|
|
|
socket.on('illegalAction', function(data){
|
|
|
|
let action
|
2022-06-20 02:39:31 +00:00
|
|
|
illegalAction(data)
|
2022-06-20 00:18:47 +00:00
|
|
|
switch (data) {
|
|
|
|
case 1:
|
|
|
|
action = "You must be in game to do this."
|
2022-06-20 00:59:51 +00:00
|
|
|
changeScene("mainmenu");
|
|
|
|
game.reset();
|
2022-06-20 02:39:31 +00:00
|
|
|
break;
|
2022-06-20 00:18:47 +00:00
|
|
|
|
|
|
|
}
|
2022-06-20 02:39:31 +00:00
|
|
|
|
2022-06-20 00:18:47 +00:00
|
|
|
})
|
|
|
|
|
2022-06-22 01:51:09 +00:00
|
|
|
socket.on('metadata', function(data){
|
2022-06-20 00:18:47 +00:00
|
|
|
console.log(data)
|
2022-06-20 02:39:31 +00:00
|
|
|
|
2022-06-20 00:18:47 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
socket.on('inGame', function(data){
|
2022-06-20 00:59:51 +00:00
|
|
|
if (!game.status) {changeScene("game")}
|
2022-06-20 00:18:47 +00:00
|
|
|
game.status = true;
|
|
|
|
})
|
|
|
|
|
|
|
|
socket.on('sync', function (sync){
|
|
|
|
game.world = sync.world;
|
2022-06-23 05:44:57 +00:00
|
|
|
console.log(game.world)
|
2022-06-20 00:18:47 +00:00
|
|
|
render()
|
|
|
|
})
|