experimental lobby

This commit is contained in:
Thibault Duplessis 2013-06-07 00:51:57 +02:00
parent ad72f00262
commit ebb8199646
8 changed files with 164 additions and 205 deletions

View file

@ -7,7 +7,7 @@ import controllers.routes
trait AssetHelper {
val assetVersion = 39
val assetVersion = 40
def cssTag(name: String) = css("stylesheets/" + name)

View file

@ -42,20 +42,13 @@ underchat = underchat.some) {
<div class="clearfix lichess_homepage">
<div class="lichess_board_wrap lichess_player_white">
@board.white()
<div class="hooks_wrap">
<div id="hooks_wrap">
<a class="filter" href="@routes.Setup.filterForm()">
<span class="s16 ddown">@trans.filterGames()</span>
<span class="number">(0)</span>
</a>
<div class="filter"></div>
<div class="hooks">
<table class="some"><tbody></tbody></table>
<table class="empty">
<tr class="create_game">
<td>@trans.noGameAvailableRightNowCreateOne()</td>
</tr>
</table>
</div>
<div id="hooks"></div>
</div>
</div>
@lobby.buttons()

View file

@ -16,7 +16,6 @@ private[i18n] case class JsDump(
} void
private val messages = List(
keys.unlimited,
keys.standard,
keys.rated,
keys.casual,

View file

@ -45,14 +45,12 @@ case class Hook(
"variant" -> realVariant.toString,
"mode" -> realMode.toString,
"color" -> color,
"clock" -> clockOrUnlimited,
"clock" -> clockOption ?? { c renderClock(c.limit, c.increment) },
"speed" -> chess.Speed(clockOption).id,
"emin" -> realEloRange.map(_.min),
"emax" -> realEloRange.map(_.max),
"engine" -> engine)
def clockOrUnlimited = clockOption.fold("Unlimited")(c renderClock(c.limit, c.increment))
private def clockOption = (time filter (_ hasClock)) |@| increment apply Clock.apply
private def renderClock(time: Int, inc: Int) = "%d + %d".format(time / 60, inc)

BIN
public/images/play128.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

View file

@ -160,12 +160,14 @@ var lichess_sri = Math.random().toString(36).substring(5); // 8 chars
}
if (m.v > self.version + 1) {
self.debug("event gap detected from " + self.version + " to " + m.v);
// TODO uncomment
return;
}
self.version = m.v;
}
if (m.t) {
if (m.t == "resync") {
// TODO uncomment
location.reload();
return;
}
@ -320,6 +322,12 @@ var lichess_sri = Math.random().toString(36).substring(5); // 8 chars
},
onProduction: /.+\.lichess\.org/.test(document.domain)
};
if (!lichess.onProduction) {
// $.cookie('surl', null);
// lichess.socketDefaults.options.baseUrls = [
// 'socket.en.lichess.org'
// ];
}
// lichess.socketDefaults.options.debug = !lichess.onProduction;
// lichess.socketDefaults.options.debug = true;
@ -1882,27 +1890,34 @@ var lichess_sri = Math.random().toString(36).substring(5); // 8 chars
});
$.lichessOpeningPreventClicks = function() {
$('div.lichess_overboard, div.hooks_wrap').hide();
$('div.lichess_overboard, #hooks_wrap').hide();
};
// hooks
$(function() {
var $wrap = $('div.hooks_wrap');
var $wrap = $('#hooks_wrap');
if (!$wrap.length) return;
if (!strongSocket.available) return;
$('div.lichess_board').animate({opacity: 0.5}, 2000);
var $timeline = $("#timeline");
var $bot = $("div.lichess_bot");
var $newposts = $("div.new_posts");
var $newpostsinner = $newposts.find('.undertable_inner').scrollTop(999999);
var $hooks = $wrap.find('div.hooks');
var $hooksTable = $hooks.find("table.some");
var $hooksTableEmpty = $hooks.find("table.empty");
var $hooks = $wrap.find('#hooks');
var $userTag = $('#user_tag');
var isRegistered = $userTag.length > 0
var myElo = isRegistered ? parseInt($userTag.data('elo')) : null;
var pool = [];
var slots = [];
for (i = 1; i <= 16; i++) {
slots.push('<div id="slot' + i + '" style="top:' + (Math.floor((i - 1) / 4) * 128) + 'px;left:' + (((i - 1) % 4) * 128) + 'px;"></div>');
}
$hooks.html(slots.join(''));
$wrap.find('a.filter').click(function() {
var $a = $(this);
var $div = $wrap.find('div.filter');
@ -1929,7 +1944,7 @@ var lichess_sri = Math.random().toString(36).substring(5); // 8 chars
type: 'post',
success: function(filter) {
lichess_preload.filter = filter;
updateHookTable();
drawHooks();
}
});
}, 500));
@ -2029,90 +2044,93 @@ var lichess_sri = Math.random().toString(36).substring(5); // 8 chars
}
function removeHook(id) {
$("#" + id).find('td.action').addClass('empty').html("").end().fadeOut(800, function() {
$(this).remove();
updateHookTable();
});
pool = _.filter(pool, function(h) { return h.id != id; });
drawHooks();
}
function addHooks(hooks) {
var html = "";
for (i in hooks) html += $hooksTable.find('tbody').append(renderHook(hooks[i]));
updateHookTable();
_.each(hooks, function(h) { hooks.push(h); });
drawHooks();
}
function addHook(hook) {
$hooksTable.find('tbody').append(renderHook(hook));
updateHookTable();
pool.push(hook);
drawHooks();
}
function updateHookTable() {
function drawHooks() {
var filter = lichess_preload.filter;
var seen = [];
$hooksTable.find('tr.hook').each(function() {
var hook = $(this).data('hook');
var hidden = 0;
_.each(pool, function(hook) {
var hide = (filter.variant != null && filter.variant != hook.variant) ||
(filter.mode != null && filter.mode != hook.mode) ||
(filter.speed != null && filter.speed != hook.speed) ||
(filter.eloDiff > 0 && (!hook.elo || hook.elo > (myElo + filter.eloDiff) || hook.elo < (myElo - filter.eloDiff)));
var hash = hook.mode + hook.variant + hook.color + hook.clock
$(this).toggleClass('none', (hide || _.contains(seen, hash)) && (hook.action != 'cancel'));
var hash = hook.mode + hook.variant + hook.color + hook.clock;
if (hide || _.contains(seen, hash)) {
$('#'+hook.id).remove();
hidden++;
} else if (!$('#'+hook.id).length) {
$(_.shuffle($hooks.find('>div:empty'))[0]).html($(renderHook(hook)).fadeIn(500));
}
seen.push(hash);
});
$hooks.find('div.hook').each(function() {
var id = $(this).attr('id');
if (!_.find(pool, function(h) { return h.id == id; })) {
$(this).remove();
}
});
var nbVisibleHooks = $hooksTable.find('tr.hook:not(.none)').length;
$hooksTable.toggleClass("none", nbVisibleHooks == 0);
$hooksTableEmpty.toggleClass("none", nbVisibleHooks != 0);
console.debug(pool.length, hidden);
console.debug(_.pluck(pool, 'id'));
$wrap
.toggleClass("large", nbVisibleHooks > 6)
.find('a.filter')
.toggleClass('on', filter.mode != null || filter.variant != null || filter.speed != null || filter.eloDiff > 0)
.find('span.number').text('(' + $hooksTable.find('tr.hook.none').length + ')');
.find('span.number').text('(' + hidden + ')');
}
function renderHook(hook) {
if (!isRegistered && hook.mode == "Rated") return "";
hook.action = hook.uid == lichess_sri ? "cancel" : "join";
if (hook.emin && hook.action == "join" && (myElo < parseInt(hook.emin) || myElo > parseInt(hook.emax))) return "";
var html = "",
isEngine, engineMark, userClass, mode;
html += '<tr id="' + hook.id + '" class="hook' + (hook.action == 'join' ? ' joinable' : '') + '">';
html += '<td class="color"><span class="' + hook.color + '"></span></td>';
isEngine = hook.engine && hook.action == 'join';
engineMark = isEngine ? '<span class="engine_mark"></span>' : '';
userClass = isEngine ? "user_link engine" : "user_link";
var html = '<div id="' + hook.id + '" class="hook ' + hook.action + '">';
// html += '<td class="color"><span class="' + hook.color + '"></span></td>';
var isEngine = hook.engine && hook.action == 'join';
var userClass = isEngine ? "engine" : "";
if (hook.elo) {
html += '<td><a class="' + userClass + '" href="/@/' + hook.username + '">' + hook.username.substr(0, 14) + '<br />' + '(' + hook.elo + ')' + engineMark + '</a></td>';
html += '<a class="opponent">' + hook.username.substr(0, 14) + '</a>';
html += '<span class="elo">' + hook.elo + '</span>';
html += isEngine ? '<span class="engine_mark"></span>' : '';
} else {
html += '<td>' + hook.username + '</td>';
html += '<span class="opponent anon">Anonymous</span>';
html += '<span class="elo nope">?</span>';
}
html += '</td>';
if (isRegistered) {
mode = $.trans(hook.mode);
if (hook.emin && (hook.emin > 800 || hook.emax < 2500)) {
mode += "<span class='elorange'>" + hook.emin + ' - ' + hook.emax + '</span>';
}
var mode = $.trans(hook.mode);
} else {
mode = "";
var mode = "";
}
if (hook.clock && hook.clock != "Unlimited") {
var clock = hook.clock.replace(/\s/g, '').replace(/\+/,'<span>+</span>');
html += '<span class="clock">' + clock + '</span>';
}
else {
html += '<span class="clock">-</span>';
}
html += '<span class="mode">' + mode + '</span>';
if (hook.action == "cancel") {
html += '<a class="action socket-link" data-msg="cancel"><span></span></a>';
} else {
html += '<a class="action socket-link" data-msg="join" data-data="' + hook.id + '"><span></span></a>';
}
if (hook.variant == 'Chess960') {
html += '<td><a href="http://en.wikipedia.org/wiki/Chess960"><strong>960</strong></a> ' + mode + '</td>';
} else {
html += '<td>' + mode + '</td>';
html += '<a class="chess960" href="http://en.wikipedia.org/wiki/Chess960">960</a>';
}
html += '<td>' + $.trans(hook.clock) + '</td>';
html += '<td class="action">';
if (hook.action == "cancel") {
html += '<a class="cancel socket-link" data-msg="cancel"></a>';
} else {
html += '<a class="join socket-link" data-msg="join" data-data="' + hook.id + '"></a>';
}
html += '</td>';
html += '</tr>';
html += '</div>';
var $hook = $(html).data('hook', hook);
if (hook.variant == "Chess960") {
if (hook.variant == "Chess960" && !$.cookie('c960')) {
$hook.find('a.join').click(function() {
if ($.cookie('c960') == 1) return true;
var c = confirm("This is a Chess960 game!\n\nThe starting position of the pieces on the players' home ranks is randomized.\nRead more: http://wikipedia.org/wiki/Chess960\n\nDo you want to play Chess960?");
if (c) $.cookie('c960', 1);
return c;
@ -2121,8 +2139,9 @@ var lichess_sri = Math.random().toString(36).substring(5); // 8 chars
return $hook;
}
$hooks.on('click', 'table.empty tr', function() {
$('#start_buttons a.config_hook').click();
$hooks.on('click', 'div.hook', function() {
var $a = $(this).find('a.action');
lichess.socket.send($a.data('msg'), $a.data('data'));
});
});

View file

@ -908,7 +908,7 @@ div.engine_warning {
margin-bottom: 15px;
}
/* soft inactive gradient */
#top, div.lichess_chat_top, #friend_box .title, div.undertable_top, .button, .button:visited, .ui-state-default, div.content_box_top, div.hooks tr, #translation_call, div.notification, div.locale_menu a, table.slist thead {
#top, div.lichess_chat_top, #friend_box .title, div.undertable_top, .button, .button:visited, .ui-state-default, div.content_box_top, #hooks tr, #translation_call, div.notification, div.locale_menu a, table.slist thead {
color: #666;
background: #fafafa;
background: -moz-linear-gradient(center top, #fafafa, #e0e0e0) repeat scroll 0 0 #fafafa;
@ -918,7 +918,7 @@ div.engine_warning {
background: -o-linear-gradient(top, #fafafa, #e0e0e0) repeat scroll 0 0 #fafafa;
}
/* active gradient */
#top a.signin, #top a.goto_nav.active, .button.active, .button.active:hover, .ui-state-active, .ui-widget-header, div.pagination span.current, #top span.new_messages, div.hooks td.action:hover, div.hooks table.empty tr:hover, div.progressbar.flashy div, .button.strong:hover, div.locale_menu a.active, #import_game .progression {
#top a.signin, #top a.goto_nav.active, .button.active, .button.active:hover, .ui-state-active, .ui-widget-header, div.pagination span.current, #top span.new_messages, #hooks td.action:hover, #hooks table.empty tr:hover, div.progressbar.flashy div, .button.strong:hover, div.locale_menu a.active, #import_game .progression {
color: #fff;
background: #d85000;
background: -moz-linear-gradient(center top, #f49c00, #d85000) repeat scroll 0 0 #d85000;
@ -928,7 +928,7 @@ div.engine_warning {
background: -o-linear-gradient(top, #f49c00, #d85000) repeat scroll 0 0 #d85000;
}
/* strong inactive gradient */
div.hooks td.action, .button:hover, .button.strong {
#hooks td.action, .button:hover, .button.strong {
background: #ffffff;
background: -moz-linear-gradient(center top, #ffffff, #c0c0c0) repeat scroll 0 0 #ffffff;
background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#ffffff), to(#c0c0c0));
@ -1275,62 +1275,44 @@ div.game_config div.color_submits button.black span {
div.game_config div.color_submits button.random span {
background-position: 0 -102px;
}
div.hooks_wrap {
#hooks_wrap {
position: absolute;
width: 384px;
height: 384px;
top: 51px;
left: 52px;
padding: 12px;
border-radius: 3px 0 3px 3px;
box-shadow: 0 0 20px #444;
background: rgba(245, 245, 245, 0.8);
background: -moz-linear-gradient(top, rgba(212, 212, 212, 0.9) 0%, rgba(240, 240, 240, 0.5) 100%);
background: -webkit-linear-gradient(top, rgba(212, 212, 212, 0.9) 0%, rgba(240, 240, 240, 0.5) 100%);
background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(rgba(212, 212, 212, 0.9)), to(rgba(240, 240, 240, 0.5)));
background: -ms-linear-gradient(top, rgba(212, 212, 212, 0.9) 0%, rgba(240, 240, 240, 0.5) 100%);
background: -o-linear-gradient(top, rgba(212, 212, 212, 0.9) 0%, rgba(240, 240, 240, 0.5) 100%);
}
div.hooks_wrap.large {
width: 512px;
height: 512px;
top: -13px;
top: 0;
left: 0;
}
div.hooks_wrap.hidden {
display: none;
}
div.hooks_wrap a.filter {
#hooks_wrap a.filter {
position: absolute;
top: -21px;
right: -1px;
height: 20px;
line-height: 20px;
padding: 0 2px 0 10px;
background: rgba(212, 212, 212, 0.9);
border: 1px solid #888;
color: #333;
border-bottom: 0;
display: block;
border-radius: 3px 3px 0 0;
text-decoration: none;
}
div.hooks_wrap a.filter:hover, div.hooks_wrap a.filter.active {
#hooks_wrap a.filter:hover, #hooks_wrap a.filter.active {
background: #fff;
}
div.hooks_wrap a.filter span.number {
#hooks_wrap a.filter span.number {
display: none;
}
div.hooks_wrap a.filter.on {
#hooks_wrap a.filter.on {
padding: 0 10px 0 2px;
}
div.hooks_wrap a.filter.on span.s16 {
#hooks_wrap a.filter.on span.s16 {
padding: 0 0 0 20px;
background-position: left -112px;
}
div.hooks_wrap a.filter.on span.number {
#hooks_wrap a.filter.on span.number {
display: inline;
}
div.hooks_wrap div.filter {
#hooks_wrap div.filter {
position: absolute;
z-index: 99;
display: none;
top: 0px;
right: 0px;
@ -1342,104 +1324,95 @@ div.hooks_wrap div.filter {
background: #fff;
border-radius: 0 0 0 3px;
}
div.hooks_wrap div.filter select {
#hooks_wrap div.filter select {
width: 100%;
margin-bottom: 12px;
padding: 6px;
}
div.hooks_wrap div.filter .actions {
#hooks_wrap div.filter .actions {
text-align: right;
}
div.hooks_wrap div.filter .actions button {
#hooks_wrap div.filter .actions button {
padding: 6px;
margin-left: 12px;
}
div.hooks {
border: 1px solid #bababa;
border-top: 0;
max-height: 514px;
overflow: auto;
#hooks_wrap #hooks {
width: 512px;
height: 512px;
position: relative;
}
div.hooks table {
width: 100%;
max-height: 424px;
overflow: hidden;
text-align: left;
border-collapse: collapse;
#hooks > div {
position: absolute;
width: 128px;
height: 128px;
background: none;
border-top: 1px solid #bababa;
}
div.hooks table.empty {
margin-top: 152px;
}
div.hooks td {
padding: 0 8px 0 12px;
height: 64px;
margin: 0;
}
div.hooks a {
color: #666;
}
div.hooks tr:last-child td {
border-bottom: none;
}
div.hooks table.empty tr {
#hooks div.hook {
display: none;
position: relative;
width: 120px;
height: 120px;
margin: 4px;
border-radius: 3px;
cursor: pointer;
color: #444;
text-align: center;
cursor: pointer;
background: #d0d0d0 url(../images/play128.png);
box-shadow:0 0 5px #333;
}
div.hooks table.empty td {
padding: 0;
height: 80px;
#hooks div.hook.cancel {
background-position: 0 -128px;
}
div.hooks td.color {
width: 24px;
padding-right: 0;
#hooks div.hook:hover {
background-color: #f0f0f0;
}
div.hooks td.color span {
height: 24px;
width: 24px;
#hooks div.hook a {
color: #444;
}
#hooks a.action {
display: none;
}
#hooks div.hook .opponent, #hooks div.hook a.user_link {
border-radius: 3px 3px 0 0;
display: block;
background: url(../images/sprite_color_24.png) no-repeat;
height: 20px;
line-height: 20px;
padding: 5px 0;
background: #666;
color: #eee;
overflow: hidden;
text-decoration: none;
}
div.hooks td.color span.black {
background-position: 0 -24px;
#hooks .clearfix {
width: 100%;
height: 30px;
}
div.hooks td.color span.random {
background-position: 0 -49px;
}
div.hooks span.elorange {
#hooks .elo, #hooks .clock {
display: block;
font-style: italic;
color: #999;
width: 60px;
height: 20px;
padding: 5px 0;
font-size: 1.25em;
font-weight: bold;
}
div.hooks a.user_link.engine {
color: #cc7070;
#hooks .elo {
float: right;
color: #bbb;
background: #666;
}
div.hooks td.action {
cursor: pointer;
border-left: 1px solid #cacaca;
width: 63px;
padding: 0;
#hooks .clock {
float: left;
color: #555;
}
div.hooks td.action.empty {
cursor: default;
background: none;
#hooks .clock > span {
color: #909090;
}
div.hooks a.cancel, div.hooks a.join {
height: 32px;
width: 31px;
#hooks .mode {
margin-top: 40px;
}
#hooks .mode, #hooks .chess960 {
font-size: 1.25em;
display: block;
padding: 12px 14px;
}
div.hooks a.cancel {
background: url(../images/close24.png) +16px no-repeat;
}
div.hooks a.join {
background: url(../images/play32.png) +16px no-repeat;
}
div.hooks a.user_link {
background: transparent;
padding-left: 0;
}
#featured_game div.vstext {
margin-top: 0.7em;

View file

@ -49,9 +49,6 @@ body.dark div.lichess_table .lichess_button,
body.dark div.lichess_chat form input,
body.dark div.lichess_board_wrap,
body.dark #translation_call,
body.dark div.hooks,
body.dark div.hooks table,
body.dark div.hooks td.action,
body.dark div.footer_wrap,
body.dark div.game_config .optional_config,
body.dark .ui-state-default,
@ -156,8 +153,8 @@ body.dark #top a.bgpicker:hover,
body.dark a#sound_state:hover,
body.dark #top .dropdown,
body.dark #GameText a:hover,
body.dark div.hooks_wrap a.filter:hover,
body.dark div.hooks_wrap a.filter.active,
body.dark #hooks_wrap a.filter:hover,
body.dark #hooks_wrap a.filter.active,
body.dark div.content_box_inter a.intertab:hover,
body.dark #top .shown a.toggle {
background: #000;
@ -187,21 +184,7 @@ body.dark .user_link.black {
background-position: 0 -272px;
}
body.dark div.hooks_wrap {
box-shadow: 0 0 20px #444;
background: rgba(10,10,10,0.8);
background: -moz-linear-gradient(top, rgba(33,33,33,0.9) 0%, rgba(15,15,15,0.5) 100%);
background: -webkit-linear-gradient(top, rgba(33,33,33,0.9) 0%,rgba(15,15,15,0.5) 100%);
background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(rgba(33,33,33,0.9)), to(rgba(15,15,15,0.5)));
background: -ms-linear-gradient(top, rgba(33,33,33,0.9) 0%,rgba(15,15,15,0.5) 100%);
background: -o-linear-gradient(top, rgba(33,33,33,0.9) 0%,rgba(15,15,15,0.5) 100%);
}
body.dark div.hooks_wrap a.filter {
background-color: rgba(10,10,10,0.8);
border-color: #444;
color: #e0e0e0;
}
body.dark div.hooks_wrap div.filter {
body.dark #hooks_wrap div.filter {
background-color: black;
border-color: #505050;
}
@ -276,7 +259,8 @@ body.dark #lichess_message div.thread_message div.thread_message_body,
body.dark #GameText a.move,
body.dark form.translation_form div.message label,
body.dark div.content_box h1,
body.dark div.hooks a
body.dark #hooks a,
body.dark #hooks_wrap a.filter
{
color: #b0b0b0;
}
@ -323,7 +307,6 @@ body.dark .button,
body.dark .button:visited,
body.dark .ui-state-default,
body.dark div.content_box_top,
body.dark div.hooks tr,
body.dark #translation_call,
body.dark div.notification,
body.dark div.locale_menu a,
@ -338,7 +321,6 @@ body.dark table.slist thead
background: -o-linear-gradient(top , #3a3a3a, #202020) repeat scroll 0 0 #3a3a3a;
}
/* strong inactive gradient */
body.dark div.hooks td.action,
body.dark .button.strong,
body.dark .button:hover
{
@ -357,8 +339,6 @@ body.dark .ui-state-active,
body.dark .ui-widget-header,
body.dark div.pagination span.current,
body.dark #top span.new_messages,
body.dark div.hooks td.action:hover,
body.dark div.hooks table.empty tr:hover,
body.dark .button.strong:hover,
body.dark div.progressbar.flashy div,
body.dark div.locale_menu a.active,
@ -382,9 +362,6 @@ body.dark #top a.goto_nav.current {
background: -ms-linear-gradient(top , #808080, #606060) repeat scroll 0 0 #606060;
background: -o-linear-gradient(top , #808080, #606060) repeat scroll 0 0 #606060;
}
body.dark div.hooks td.action.empty {
background: none;
}
body.dark .s16.ddown {
background-position: right -368px;
}