Made clock configurable and split clocks from map.

This commit is contained in:
FrozenCow 2011-02-15 13:50:04 +01:00
parent fe2cd9e206
commit 57d74ec3cb
5 changed files with 110 additions and 103 deletions

42
web/clock.digital.js Normal file
View file

@ -0,0 +1,42 @@
function MinecraftDigitalClock(element) {
this.create(element);
}
MinecraftDigitalClock.prototype = {
element: null,
timeout: null,
time: null,
create: function(element) {
this.element = element;
$(element).addClass('clock');
},
setTime: function(time) {
if (this.timeout != null) {
window.clearTimeout(this.timeout);
this.timeout = null;
}
this.time = getMinecraftTime(time);
this.element
.addClass(this.time.day ? 'day' : 'night')
.removeClass(this.time.night ? 'day' : 'night')
.text(this.formatTime(this.time));
if (this.timeout == null) {
var me = this;
this.timeout = window.setTimeout(function() {
me.timeout = null;
me.setTime(me.time.servertime+(1000/60));
}, 700);
}
},
formatTime: function(time) {
var formatDigits = function(n, digits) {
var s = n.toString();
while (s.length < digits) {
s = '0' + s;
}
return s;
}
return formatDigits(time.hours, 2) + ':' + formatDigits(time.minutes, 2);
}
};
clocks.digital = function(element) { return new MinecraftDigitalClock(element); };