incremental wip
This commit is contained in:
parent
1ab065e0e5
commit
c7774e2964
@ -15,24 +15,58 @@ var PlayerOverlay = L.LayerGroup.extend({
|
||||
this.layerMgr = layerMgr;
|
||||
this.wsChannel = wsChannel;
|
||||
|
||||
this.currentObjects = []; //{obj:{}, marker: {}}
|
||||
this.currentObjects = {}; // name => marker
|
||||
this.players = [];
|
||||
|
||||
this.reDraw = this.reDraw.bind(this);
|
||||
this.onMapMove = debounce(this.onMapMove.bind(this), 50);
|
||||
this.onMinetestUpdate = this.onMinetestUpdate.bind(this);
|
||||
|
||||
//update players all the time
|
||||
this.wsChannel.addListener("minetest-info", function(info){
|
||||
this.players = info.players || [];
|
||||
}.bind(this));
|
||||
},
|
||||
|
||||
onMinetestUpdate: function(info){
|
||||
//TODO incremental update
|
||||
var self = this;
|
||||
|
||||
this.players.forEach(function(player){
|
||||
if (self.currentObjects[player.name]){
|
||||
//marker exists
|
||||
} else {
|
||||
//marker does not exist
|
||||
}
|
||||
});
|
||||
|
||||
Object.keys(self.currentObjects).forEach(function(existingName){
|
||||
var playerIsActive = this.players.find(function(p){
|
||||
return p.name == existingName;
|
||||
});
|
||||
|
||||
if (!playerIsActive){
|
||||
//player
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
reDraw: function(){
|
||||
//TODO full update
|
||||
var self = this;
|
||||
this.currentObjects = {};
|
||||
this.clearLayers();
|
||||
|
||||
var mapLayer = this.layerMgr.getCurrentLayer()
|
||||
//TODO
|
||||
|
||||
this.players.forEach(function(player){
|
||||
//TODO: filter layer
|
||||
|
||||
var marker = L.marker([travelnet.z, travelnet.x], {icon: TravelnetIcon});
|
||||
marker.bindPopup(player.name).addTo(self);
|
||||
|
||||
self.currentObjects[player.name] = marker;
|
||||
});
|
||||
|
||||
},
|
||||
|
||||
onAdd: function(map) {
|
||||
|
Loading…
Reference in New Issue
Block a user