tuxman/client/js/main.js

59 lines
2.3 KiB
JavaScript
Raw Normal View History

2023-06-17 00:38:55 +00:00
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import { Game } from "./net/game.js";
import { InitialState, onLogic } from "./logic/logic.js";
import { startGraphicsUpdater } from "./renderer.js";
import { GameKeyMap, Key } from "./types.js";
const join = document.getElementById("join");
const lobby = document.getElementById("lobby");
lobby.style.display = "none";
join.onsubmit = function (event) {
return __awaiter(this, void 0, void 0, function* () {
event.preventDefault();
2023-06-17 05:18:16 +00:00
const room_code = document.getElementById("room_code").value;
const player_name = document.getElementById("player_name").value;
2023-06-17 00:38:55 +00:00
if (room_code == '') {
alert('Please enter a room code');
return;
}
if (player_name == '') {
alert('Please enter a player name');
return;
}
join.style.display = "none";
startGame(room_code, player_name);
});
};
const updateGraphics = startGraphicsUpdater();
const onLoad = (startData) => {
if (startData.data.started) {
alert('Room has already started');
return false;
2023-06-14 01:18:01 +00:00
}
2023-06-17 00:38:55 +00:00
let players = Object.values(startData.data.players).filter(p => { return p !== null && p.name !== undefined; });
if (players.length >= 4) {
alert('Room is full');
return false;
2023-06-14 01:18:01 +00:00
}
2023-06-17 00:38:55 +00:00
lobby.style.display = "";
return true;
};
const onFrame = (data, frame) => {
updateGraphics(data ? data.data : InitialState, frame);
};
const startGame = (code, name) => {
const game = new Game(3000);
game.start(code, GameKeyMap, onLoad, onFrame, onLogic, {
start: false,
key: Key.NOTHING,
name
});
};
//# sourceMappingURL=main.js.map