2020-01-13 18:05:11 +01:00
|
|
|
import Games;
|
2020-01-11 19:46:41 +01:00
|
|
|
import * as ConnectedForm from GUI.ConnectedForm;
|
|
|
|
import * as ListSelector from GUI.ListSelector;
|
2020-01-13 18:05:11 +01:00
|
|
|
import * as GamesGUI from GUI.Screen.Hall.Games;
|
2020-01-11 19:46:41 +01:00
|
|
|
import I18n;
|
|
|
|
import Messaging;
|
2020-01-14 09:55:04 +01:00
|
|
|
import players from Room;
|
2020-01-11 19:46:41 +01:00
|
|
|
import * as Dom from UnitJS.Dom;
|
|
|
|
|
|
|
|
var form = ConnectedForm.get('room');
|
|
|
|
var list = ListSelector.make('players', showPlayer);
|
|
|
|
var them = null;
|
|
|
|
initDOM();
|
|
|
|
|
|
|
|
return {
|
|
|
|
refresh: refresh
|
|
|
|
};
|
|
|
|
|
|
|
|
function initDOM() {
|
|
|
|
form.root.getElementsByTagName('label')[0].textContent = I18n.get('startGameWith');
|
|
|
|
form.root.invite.value = I18n.get('invite');
|
|
|
|
form.root.addEventListener('submit', function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
Messaging.send({tag: "Invitation", to: them});
|
2020-01-14 09:55:04 +01:00
|
|
|
Games.proposal(them, false);
|
2020-01-13 18:05:11 +01:00
|
|
|
GamesGUI.refresh();
|
2020-01-11 19:46:41 +01:00
|
|
|
});
|
|
|
|
form.root.them.addEventListener("input", function() {refresh();});
|
|
|
|
}
|
|
|
|
|
|
|
|
function showPlayer(player) {
|
|
|
|
return Dom.make('li', {
|
2020-01-13 23:08:20 +01:00
|
|
|
textContent: player.value,
|
|
|
|
onClick: function() {form.root.them.value = player.value; refresh();},
|
2020-01-11 19:46:41 +01:00
|
|
|
class: 'clickable'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function refresh() {
|
|
|
|
var name = form.root.them.value;
|
|
|
|
them = null;
|
2020-01-13 08:39:32 +01:00
|
|
|
var filtered = players.getAll(
|
2020-01-13 23:08:20 +01:00
|
|
|
function(player) {return player.value.match(name);}
|
2020-01-11 19:46:41 +01:00
|
|
|
);
|
|
|
|
list.refresh(filtered);
|
|
|
|
var exact = filtered.find(exactMatch(name));
|
|
|
|
if(exact != undefined) {
|
|
|
|
them = exact.key;
|
|
|
|
} else if(filtered.length == 1) {
|
|
|
|
them = filtered[0].key;
|
|
|
|
} else if(filtered.length == 0) {
|
|
|
|
list.message.textContent = I18n.get(
|
|
|
|
name.length > 0 ? "notFound" : "alone"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
form.enable(them != undefined);
|
|
|
|
}
|
|
|
|
|
|
|
|
function exactMatch(name) {
|
|
|
|
return function(player) {
|
2020-01-13 23:08:20 +01:00
|
|
|
return player.value === name;
|
2020-01-11 19:46:41 +01:00
|
|
|
};
|
|
|
|
}
|