webclient/js/GUI/Screen/Hall.js

51 lines
1.3 KiB
JavaScript

import * as Dom from UnitJS.Dom;
import I18n;
import * as Players from GUI.Screen.Hall.Players;
import * as Games from GUI.Screen.Hall.Games;
import Messaging;
import opponent from Room;
import Session;
import StatusHandler;
return {
init: init
};
function init() {
Messaging.addEventListener(["Okaeri"], function(o) {
refresh();
});
Messaging.addEventListener(["Welcome"], function(o) {
refresh();
});
Messaging.addEventListener(["LogIn"], function(o) {
refresh();
});
Messaging.addEventListener(["LogOut"], function(o) {
// Just in case there was a game proposal from that player, in which case the game proposal's ID is the player's ID
Games.table.remove(o.from);
refresh();
});
Messaging.addEventListener(["Relay", "Invitation"], function(o) {
StatusHandler.set("🎴");
Games.table.insert(o.from, {vs: opponent(o.from), yourTurn: true});
Games.refresh();
});
Messaging.addEventListener(["Relay", "Answer"], function(o) {
Games.table.remove(o.from);
Games.refresh();
});
Messaging.addEventListener(["Game"], function(o) {
var sessionKey = Session.getKey();
Games.table.insert(o.state.gameID, {
vs: opponent(o.state.public.nextPlayer[sessionKey]),
yourTurn: o.state.public.playing == sessionKey
});
Games.refresh();
});
}
function refresh() {
Players.refresh();
Games.refresh();
}