webclient/js/GUI/Screen/Hall.js

57 lines
1.3 KiB
JavaScript
Raw Permalink Normal View History

import * as Dom from UnitJS.Dom;
import Games;
import I18n;
import register from GUI.Screen;
import * as Players from GUI.Screen.Hall.Players;
import * as GamesGUI from GUI.Screen.Hall.Games;
import Messaging;
import StatusHandler;
return {
init: init
};
function init() {
register('hall');
Players.init();
GamesGUI.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.metadata.remove(o.from);
refresh();
});
Messaging.addEventListener(["Relay", "Invitation"], function(o) {
StatusHandler.set("🎴");
Games.proposal(o.from, true);
GamesGUI.refresh();
});
Messaging.addEventListener(["Relay", "Answer"], function(o) {
var gameEntry = Games.metadata.get(o.from);
if(gameEntry != undefined) {
if(!o.message.accept) {
gameEntry.answer = false;
} else {
Games.metadata.remove(o.from);
}
GamesGUI.refresh();
}
});
Messaging.addEventListener(["Game"], function(o) {
GamesGUI.refresh();
});
}
function refresh() {
Players.refresh();
GamesGUI.refresh();
}