Made clock and timeofday interchangable.

This commit is contained in:
FrozenCow 2011-02-14 00:01:20 +01:00
parent 42391cc4d5
commit 49d45c653d

View File

@ -28,32 +28,33 @@ DynMapType.prototype = {
} }
}; };
function MinecraftClock(element) { this.element = element; } function MinecraftClock(element) {
this.create(element);
}
MinecraftClock.prototype = { MinecraftClock.prototype = {
element: null, element: null,
timeout: null, timeout: null,
time: null, time: null,
create: function(element) { create: function(element) {
if (!element) element = $('<div/>');
this.element = element; this.element = element;
return element; $(element).addClass('clock');
}, },
setTime: function(time) { setTime: function(time) {
if (this.timeout != null) { if (this.timeout != null) {
window.clearTimeout(this.timeout); window.clearTimeout(this.timeout);
this.timeout = null; this.timeout = null;
} }
this.time = time; this.time = getMinecraftTime(time);
this.element this.element
.addClass((time.day <= 4) ? 'day' : 'night') .addClass(this.time.day ? 'day' : 'night')
.removeClass((time.day <= 4) ? 'day' : 'night') .removeClass(this.time.night ? 'day' : 'night')
.text(this.formatTime(time)); .text(this.formatTime(this.time));
if (this.timeout == null) { if (this.timeout == null) {
var me = this; var me = this;
this.timeout = window.setTimeout(function() { this.timeout = window.setTimeout(function() {
me.timeout = null; me.timeout = null;
me.setTime(getMinecraftTime(me.time.servertime+(1000/60))); me.setTime(me.time.servertime+(1000/60));
}, 700); }, 700);
} }
}, },
@ -69,17 +70,17 @@ MinecraftClock.prototype = {
} }
}; };
function MinecraftTimeOfDay(element) { this.element = element; } function MinecraftTimeOfDay(element,elementsun,elementmoon) {
this.create(element, elementsun, elementmoon);
}
MinecraftTimeOfDay.prototype = { MinecraftTimeOfDay.prototype = {
element: null, element: null,
elementsun: null, elementsun: null,
elementmoon: null, elementmoon: null,
create: function(element) { create: function(element,elementsun,elementmoon) {
if (!element) element = $('<div/>'); if (!element) element = $('<div/>');
this.element = element; this.element = element;
return element;
},
initialize: function(elementsun, elementmoon) {
if (!elementsun) elementsun = $('<div/>'); if (!elementsun) elementsun = $('<div/>');
this.elementsun = elementsun; this.elementsun = elementsun;
this.elementsun.appendTo(this.element); this.elementsun.appendTo(this.element);
@ -97,6 +98,8 @@ MinecraftTimeOfDay.prototype = {
this.elementmoon.html("&nbsp;&rlm;&nbsp;"); this.elementmoon.html("&nbsp;&rlm;&nbsp;");
this.elementsun.css("background-position", (-120) + "px " + (-120) + "px"); this.elementsun.css("background-position", (-120) + "px " + (-120) + "px");
this.elementmoon.css("background-position", (-120) + "px " + (-120) + "px"); this.elementmoon.css("background-position", (-120) + "px " + (-120) + "px");
return element;
}, },
setTime: function(time) { setTime: function(time) {
var sunangle; var sunangle;
@ -280,12 +283,11 @@ DynMap.prototype = {
.addClass('playerlist') .addClass('playerlist')
.appendTo(sidebar); .appendTo(sidebar);
// The TimeOfDay // The clock
var timeofday = me.timeofday = new MinecraftTimeOfDay( var clock = me.clock = new MinecraftTimeOfDay(
$('<div/>') $('<div/>')
.appendTo(sidebar) .appendTo(sidebar)
); );
timeofday.initialize();
// The Compass // The Compass
var compass = me.compass = new MinecraftCompass( var compass = me.compass = new MinecraftCompass(
@ -320,7 +322,7 @@ DynMap.prototype = {
me.alertbox.hide(); me.alertbox.hide();
me.lasttimestamp = update.timestamp; me.lasttimestamp = update.timestamp;
me.timeofday.setTime(update.servertime); me.clock.setTime(update.servertime);
var typeVisibleMap = {}; var typeVisibleMap = {};
var newmarkers = {}; var newmarkers = {};