//if (!console) console = { log: function() {} }; var maptypes = {}; function splitArgs(s) { var r = s.split(' '); delete arguments[0]; var obj = {}; var index = 0; $.each(arguments, function(argumentIndex, argument) { if (!argumentIndex) return; var value = r[argumentIndex-1]; obj[argument] = value; }); return obj; } function swtch(value, options, defaultOption) { return (options[value] || defaultOption)(value); } function DynMapType() { } DynMapType.prototype = { onTileUpdated: function(tile, tileName) { var src = this.dynmap.getTileUrl(tileName); tile.attr('src', src); tile.show(); } }; function MinecraftClock(element) { this.element = element; } MinecraftClock.prototype = { element: null, timeout: null, time: null, create: function(element) { if (!element) element = $('
'); this.element = element; return element; }, setTime: function(time) { if (this.timeout != null) { window.clearTimeout(this.timeout); this.timeout = null; } this.time = time; this.element .addClass((time.day <= 4) ? 'day' : 'night') .removeClass((time.day <= 4) ? 'day' : 'night') .text(this.formatTime(time)); if (this.timeout == null) { var me = this; this.timeout = window.setTimeout(function() { me.timeout = null; me.setTime(getMinecraftTime(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); } }; 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) { 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"); } }; function MinecraftCompass(element) { this.element = element; } MinecraftCompass.prototype = { element: null, create: function(element) { if (!element) element = $('
'); this.element = element; return element; }, initialize: function() { this.element.html(" ‏ "); this.element.height(120); } }; function DynMap(options) { var me = this; me.options = options; $.getJSON(me.options.updateUrl + 'configuration', function(configuration) { me.configure(configuration); me.initialize(); }) } DynMap.prototype = { registeredTiles: new Array(), markers: new Array(), chatPopups: new Array(), lasttimestamp: '0', followingPlayer: '', configure: function(configuration) { var me = this; $.extend(me.options, configuration); if (!me.options.maps) me.options.maps = {}; $.each(me.options.shownmaps, function(index, mapentry) { me.options.maps[mapentry.name] = maptypes[mapentry.type](mapentry); }); me.world = me.options.defaultworld; }, initialize: function() { var me = this; var container = $(me.options.container); var mapContainer; (mapContainer = $('
')) .addClass('map') .appendTo(container); var map = this.map = new google.maps.Map(mapContainer.get(0), { zoom: 1, center: new google.maps.LatLng(0, 1), navigationControl: true, navigationControlOptions: { style: google.maps.NavigationControlStyle.DEFAULT }, scaleControl: false, mapTypeControl: false, streetViewControl: false, backgroundColor: 'none' }); google.maps.event.addListener(map, 'dragstart', function(mEvent) { me.followPlayer(''); }); // TODO: Enable hash-links. /*google.maps.event.addListener(map, 'zoom_changed', function() { me.updateLink(); }); google.maps.event.addListener(map, 'center_changed', function() { me.updateLink(); });*/ // The sidebar var sidebar = me.sidebar = $('
') .addClass('sidebar') .appendTo(container); // The world list. var worldlist = me.worldlist = $('
') .addClass('worldlist') .appendTo(sidebar); $.each(me.options.shownworlds, function(index, name) { var worldButton; $('
') .addClass('worldrow') .append(worldButton = $('') .addClass('worldbutton') .addClass('world_' + name) .attr({ type: 'radio', name: 'world', value: name }) .attr('checked', me.options.defaultworld == name ? 'checked' : null) ) .append($('