From 060d1092f947acb8a307b47107be3659a3d6b509 Mon Sep 17 00:00:00 2001 From: FrozenCow Date: Tue, 15 Feb 2011 13:50:04 +0100 Subject: [PATCH] Made clock configurable and split clocks from map. --- configuration.txt | 4 ++ web/clock.digital.js | 42 +++++++++++++++++ web/clock.timeofday.js | 59 +++++++++++++++++++++++ web/index.html | 4 +- web/map.js | 104 +---------------------------------------- 5 files changed, 110 insertions(+), 103 deletions(-) create mode 100644 web/clock.digital.js create mode 100644 web/clock.timeofday.js diff --git a/configuration.txt b/configuration.txt index 4060e1ed..abe193ac 100644 --- a/configuration.txt +++ b/configuration.txt @@ -38,6 +38,10 @@ web: showplayerfacesinmenu: true focuschatballoons: false + # The clock that is shown alongside the map. + clock: timeofday + #clock: digital + # The name of the map shown when opening Dynmap's page (must be in menu). defaultmap: defaultmap diff --git a/web/clock.digital.js b/web/clock.digital.js new file mode 100644 index 00000000..c0bf1c83 --- /dev/null +++ b/web/clock.digital.js @@ -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); }; \ No newline at end of file diff --git a/web/clock.timeofday.js b/web/clock.timeofday.js new file mode 100644 index 00000000..93f90038 --- /dev/null +++ b/web/clock.timeofday.js @@ -0,0 +1,59 @@ +function MinecraftTimeOfDay(element,elementsun,elementmoon) { + this.create(element, elementsun, elementmoon); +} +MinecraftTimeOfDay.prototype = { + element: null, + elementsun: null, + elementmoon: null, + create: function(element,elementsun,elementmoon) { + if (!element) element = $('
'); + this.element = element; + + if (!elementsun) elementsun = $('
'); + this.elementsun = elementsun; + this.elementsun.appendTo(this.element); + if (!elementmoon) elementmoon = $('
'); + this.elementmoon = elementmoon; + this.elementmoon.appendTo(this.elementsun); + this.element.height(60); + this.element.addClass('timeofday'); + this.elementsun.height(60); + this.elementsun.addClass('timeofday'); + this.elementsun.addClass('sun'); + this.elementmoon.height(60); + this.elementmoon.addClass('timeofday'); + this.elementmoon.addClass('moon'); + this.elementmoon.html(" ‏ "); + this.elementsun.css("background-position", (-120) + "px " + (-120) + "px"); + this.elementmoon.css("background-position", (-120) + "px " + (-120) + "px"); + + return element; + }, + setTime: function(time) { + var sunangle; + + if(time > 23100 || time < 12900) + { + //day mode + var movedtime = time + 900; + movedtime = (movedtime >= 24000) ? movedtime - 24000 : movedtime; + //Now we have 0 -> 13800 for the day period + //Devide by 13800*2=27600 instead of 24000 to compress day + sunangle = ((movedtime)/27600 * 2 * Math.PI); + } + else + { + //night mode + var movedtime = time - 12900; + //Now we have 0 -> 10200 for the night period + //Devide by 10200*2=20400 instead of 24000 to expand night + sunangle = Math.PI + ((movedtime)/20400 * 2 * Math.PI); + } + + var moonangle = sunangle + Math.PI; + + this.elementsun.css("background-position", (-50 * Math.cos(sunangle)) + "px " + (-50 * Math.sin(sunangle)) + "px"); + this.elementmoon.css("background-position", (-50 * Math.cos(moonangle)) + "px " + (-50 * Math.sin(moonangle)) + "px"); + } +}; +clocks.timeofday = function(element) { return new MinecraftTimeOfDay(element); }; \ No newline at end of file diff --git a/web/index.html b/web/index.html index 78fb8cac..fead257b 100644 --- a/web/index.html +++ b/web/index.html @@ -17,7 +17,9 @@ - + + +