From 2be0cd36711e07fce859418017af851650cd1c22 Mon Sep 17 00:00:00 2001 From: FrozenCow Date: Mon, 21 Mar 2011 20:46:53 +0100 Subject: [PATCH] Added initial work for 'componentizing' client-side. --- configuration.txt | 5 ++++- web/js/map.js | 43 +++++++++++++++++++++++++++++++++++++------ 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/configuration.txt b/configuration.txt index 99724ad3..8e471c81 100644 --- a/configuration.txt +++ b/configuration.txt @@ -80,6 +80,10 @@ web: quitmessage: "%playername% quit" spammessage: "You may only chat once every %interval% seconds." + components: + - type: testcomponent + - type: testcomponent + defaultworld: world worlds: - title: World @@ -121,7 +125,6 @@ web: # title: Cave # name: cave # prefix: ct - # Enables debugging. #debuggers: # - class: org.dynmap.debug.LogDebugger diff --git a/web/js/map.js b/web/js/map.js index 82e65cbb..815b43d1 100644 --- a/web/js/map.js +++ b/web/js/map.js @@ -1,9 +1,29 @@ "use strict"; //if (!console) console = { log: function() {} }; +var componentconstructors = {}; var maptypes = {}; var clocks = {}; +componentconstructors['testcomponent'] = function(dynmap, configuration) { + return { + dynmap: dynmap, + initialize: function() { + console.log('initialize'); + $(dynmap).bind('worldchanged', function() { console.log('worldchanged'); }); + $(dynmap).bind('mapchanged', function() { console.log('mapchanged'); }); + $(dynmap).bind('zoomchanged', function() { console.log('zoomchanged'); }); + $(dynmap).bind('worldupdating', function() { console.log('worldupdating'); }); + $(dynmap).bind('worldupdate', function() { console.log('worldupdate'); }); + $(dynmap).bind('worldupdated', function() { console.log('worldupdated'); }); + $(dynmap).bind('worldupdatefailed', function() { console.log('worldupdatefailed'); }); + $(dynmap).bind('playeradded', function() { console.log('playeradded'); }); + $(dynmap).bind('playerremoved', function() { console.log('playerremoved'); }); + $(dynmap).bind('playerupdated', function() { console.log('playerupdated'); }); + } + }; +}; + function splitArgs(s) { var r = s.split(' '); delete arguments[0]; @@ -54,6 +74,7 @@ function DynMap(options) { }); } DynMap.prototype = { + components: [], worlds: {}, registeredTiles: [], players: {}, @@ -107,18 +128,21 @@ DynMap.prototype = { map.zoom_changed = function() { me.maptype.updateTileSize(me.map.zoom); + $(me).trigger('zoomchanged'); }; google.maps.event.addListener(map, 'dragstart', function(mEvent) { me.followPlayer(null); }); // TODO: Enable hash-links. - /*google.maps.event.addListener(map, 'zoom_changed', function() { + /* + google.maps.event.addListener(map, 'zoom_changed', function() { me.updateLink(); }); google.maps.event.addListener(map, 'center_changed', function() { me.updateLink(); - });*/ + }); + */ // Sidebar var sidebar = me.sidebar = $('
') @@ -286,6 +310,13 @@ DynMap.prototype = { me.selectMap(me.defaultworld.defaultmap); + $.each(me.options.components, function(index, configuration) { + me.components.push(componentconstructors[configuration.type](me, configuration)); + }); + $.each(me.components, function(index, component) { + component.initialize(); + }); + setTimeout(function() { me.update(); }, me.options.updaterate); }, selectMap: function(map, completed) { @@ -302,11 +333,11 @@ DynMap.prototype = { me.maptype.updateTileSize(me.map.zoom); window.setTimeout(function() { me.map.setMapTypeId(map.world.name + '.' + map.name); + if (worldChanged) { + $(me).trigger('worldchanged'); + } + $(me).trigger('mapchanged'); if (completed) { - if (worldChanged) { - $(me).trigger('worldchanged'); - } - $(me).trigger('mapchanged'); completed(); } }, 1);