Skip to content

Commit

Permalink
Many, many stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed May 13, 2012
1 parent 8655bec commit 923d3e7
Show file tree
Hide file tree
Showing 187 changed files with 15,515 additions and 58 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
logs
project/project
project/target
public/trans
target
RUNNING_PID
4 changes: 2 additions & 2 deletions app/Global.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ object Global extends GlobalSettings {

systemEnv = SystemEnv(app)

if (env.isAiServer) println("Running as AI server")
else Cron start env
//if (env.isAiServer) println("Running as AI server")
//else Cron start env
}

override def onRouteRequest(request: RequestHeader): Option[Handler] =
Expand Down
19 changes: 17 additions & 2 deletions app/SystemEnv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,37 @@ import akka.actor._
import play.api.libs.concurrent._
import play.api.Application
import play.api.i18n.Lang
import play.api.i18n.MessagesPlugin

import db._
import ai._
import memo._
import i18n._
import ui._

final class SystemEnv private (application: Application, settings: Settings) {

implicit val app = application

import settings._

lazy val i18nRequestHandler = new I18nRequestHandler(

lazy val i18nMessagesApi = app.plugin[MessagesPlugin]
.err("this plugin was not registered or disabled")
.api

lazy val i18nPool = new I18nPool(
langs = Lang.availables.toSet,
default = Lang("en"))

lazy val translator = new Translator(
api = i18nMessagesApi,
pool = i18nPool)

lazy val i18nKeys = new I18nKeys(translator)

lazy val i18nRequestHandler = new I18nRequestHandler(
pool = i18nPool)

lazy val pgnDump = new PgnDump(userRepo = userRepo, gameRepo = gameRepo)

lazy val gameInfo = GameInfo(pgnDump) _
Expand Down
30 changes: 30 additions & 0 deletions app/assets/javascripts/analyse.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
jQuery(function() {
SetImagePath("/vendor/pgn4web/lichess/64"); // use "" path if images are in the same folder as this javascript file
SetImageType("png");
});

function customFunctionOnPgnGameLoad() {
var $text = $('#ShowPgnText');
var html = '<table><tbody><tr>';
$text.find('span.move').remove();
$text.find('>span').each(function(it) {
if (0 == it%2) {
html += '</tr><tr><th>' + (it/2+1) + '.</th>';
}
html += '<td>' + this.innerHTML + '</td>';
});
html += '</tr></tbody></table>';
$text.html(html).find('tr:empty').remove();

$('div.lichess_goodies a.rotate_board').click(function() {
$('#GameBoard').toggleClass('flip');
$('#player_links div:first').appendTo($('#player_links'));
redrawBoardMarks();
return false;
});
redrawBoardMarks();
}

function redrawBoardMarks() {
jQuery.displayBoardMarks($('#GameBoard'), ! $('#GameBoard').hasClass('flip'));
}
13 changes: 13 additions & 0 deletions app/assets/javascripts/chart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
if (typeof google.visualization == "undefined" ) {
google.load("visualization", "1", {packages:["corechart"]});
}

google.elemToData = function(elem) {
var data = new google.visualization.DataTable();
$.each($(elem).data('columns'), function() {
data.addColumn(this[0], this[1]);
});
data.addRows($(elem).data('rows'));

return data;
}
64 changes: 64 additions & 0 deletions app/assets/javascripts/clock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
$.widget("lichess.clock", {
_create: function() {
var self = this;
this.options.time = parseFloat(this.options.time) * 1000;
$.extend(this.options, {
duration: this.options.time,
state: 'ready'
});
this.element.addClass('clock_enabled');
},
destroy: function() {
this.stop();
$.Widget.prototype.destroy.apply(this);
},
start: function() {
var self = this;
self.options.state = 'running';
self.element.addClass('running');
var end_time = new Date().getTime() + self.options.time;
self.options.interval = setInterval(function() {
if (self.options.state == 'running') {
var current_time = Math.round(end_time - new Date().getTime());
if (current_time <= 0) {
clearInterval(self.options.interval);
current_time = 0;
}

self.options.time = current_time;
self._show();

//If the timer completed, fire the buzzer callback
current_time == 0 && $.isFunction(self.options.buzzer) && self.options.buzzer(self.element);
} else {
clearInterval(self.options.interval);
}
},
1000);
},

setTime: function(time) {
this.options.time = parseFloat(time) * 1000;
this._show();
},

stop: function() {
clearInterval(this.options.interval);
this.options.state = 'stop';
this.element.removeClass('running');
},

_show: function() {
this.element.text(this._formatDate(new Date(this.options.time)));
},

_formatDate: function(date) {
minutes = this._prefixInteger(date.getMinutes(), 2);
seconds = this._prefixInteger(date.getSeconds(), 2);
return minutes + ':' + seconds;
},

_prefixInteger: function (num, length) {
return (num / Math.pow(10, length)).toFixed(length).substr(2);
}
});
Loading

0 comments on commit 923d3e7

Please sign in to comment.