diff --git a/web/compass.png b/web/compass.png new file mode 100644 index 00000000..129353a2 Binary files /dev/null and b/web/compass.png differ diff --git a/web/map.js b/web/map.js index eceee495..ab51debd 100644 --- a/web/map.js +++ b/web/map.js @@ -72,24 +72,57 @@ MinecraftClock.prototype = { function MinecraftTimeOfDay(element) { this.element = element; } MinecraftTimeOfDay.prototype = { element: null, + elementsun: null, + elementmoon: null, create: function(element) { if (!element) element = $('
'); this.element = element; return element; }, + initialize: function(elementsun, elementmoon) { + 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"); + }, setTime: function(time) { - this.element - .removeClass('time1') - .removeClass('time2') - .removeClass('time3') - .removeClass('time4') - .removeClass('time5') - .removeClass('time6') - .removeClass('time7') - .removeClass('time8') - .addClass('time' + time.day) - .html(" ") - .height(60); + 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"); } }; @@ -117,7 +150,6 @@ function DynMap(options) { } DynMap.prototype = { registeredTiles: new Array(), - clock: null, markers: new Array(), chatPopups: new Array(), lasttimestamp: '0', @@ -248,19 +280,12 @@ DynMap.prototype = { .addClass('playerlist') .appendTo(sidebar); - // The Clock - var clock = me.clock = new MinecraftClock( - $('') - .addClass('clock') - .appendTo(sidebar) - ); - // The TimeOfDay var timeofday = me.timeofday = new MinecraftTimeOfDay( $('') - .addClass('timeofday') - .appendTo(sidebar) + .appendTo(sidebar) ); + timeofday.initialize(); // The Compass var compass = me.compass = new MinecraftCompass( @@ -295,8 +320,7 @@ DynMap.prototype = { me.alertbox.hide(); me.lasttimestamp = update.timestamp; - me.clock.setTime(getMinecraftTime(update.servertime)); - me.timeofday.setTime(me.clock.time); + me.timeofday.setTime(update.servertime); var typeVisibleMap = {}; var newmarkers = {}; diff --git a/web/minecraft.js b/web/minecraft.js index 29c45f37..19f58009 100644 --- a/web/minecraft.js +++ b/web/minecraft.js @@ -77,40 +77,3 @@ function getMinecraftHead(player,size,completed) { completed(resizeImage(head,size)); } } - -function getMinecraftTime(servertime) { - servertime = parseInt(servertime); - var hours = (parseInt(servertime / 1000)+8) % 24; - var minutes = parseInt(((servertime / 1000) % 1) * 60); - var seconds = parseInt(((((servertime / 1000) % 1) * 60) % 1) * 60); - - var daytime = 0; - if(hours >= 6 && hours <= 7) - daytime = 1; - if(hours >= 8 && hours <= 9) - daytime = 2; - if(hours >= 10 && hours <= 17) - daytime = 3; - if(hours >= 18 && hours <= 19) - daytime = 4; - if(hours >= 20 && hours <= 21) - daytime = 5; - if(hours >= 22 && hours <= 23) - daytime = 6; - if(hours >= 0 && hours <= 3) - daytime = 7; - if(hours >= 4 && hours <= 5) - daytime = 8; - - return { - servertime: servertime, - days: parseInt((servertime+8000) / 24000), - - // Assuming it is day at 8:00 - hours: hours, - minutes: minutes, - seconds: seconds, - - day: daytime, - }; -} diff --git a/web/moon.png b/web/moon.png new file mode 100644 index 00000000..10c82046 Binary files /dev/null and b/web/moon.png differ diff --git a/web/style.css b/web/style.css index d62a9538..388c4c86 100644 --- a/web/style.css +++ b/web/style.css @@ -82,15 +82,12 @@ a, a:visited, label { background-image: url(compass.png); } -.timeofday { background-repeat: no-repeat; } -.timeofday.time1 { background-image: url(time1.png); } -.timeofday.time2 { background-image: url(time2.png); } -.timeofday.time3 { background-image: url(time3.png); } -.timeofday.time4 { background-image: url(time4.png); } -.timeofday.time5 { background-image: url(time5.png); } -.timeofday.time6 { background-image: url(time6.png); } -.timeofday.time7 { background-image: url(time7.png); } -.timeofday.time8 { background-image: url(time8.png); } +.timeofday { + background-repeat: no-repeat; +} + +.timeofday.sun { background-image: url(sun.png); } +.timeofday.moon { background-image: url(moon.png); } .alertbox { padding: 5px; diff --git a/web/sun.png b/web/sun.png new file mode 100644 index 00000000..11ce6cb1 Binary files /dev/null and b/web/sun.png differ