2011-03-31 12:44:42 +02:00
|
|
|
componentconstructors['playermarkers'] = function(dynmap, configuration) {
|
2011-03-31 12:54:32 +02:00
|
|
|
var me = this;
|
|
|
|
$(dynmap).bind('playeradded', function(event, player) {
|
|
|
|
// Create the player-marker.
|
2011-07-16 23:53:15 +02:00
|
|
|
var markerPosition = dynmap.getProjection().fromLocationToLatLng(player.location);
|
|
|
|
player.marker = new L.CustomMarker(markerPosition, { elementCreator: function() {
|
|
|
|
var div = document.createElement('div');
|
2011-03-31 12:54:32 +02:00
|
|
|
var playerImage;
|
2011-07-31 19:41:01 +02:00
|
|
|
|
|
|
|
var markerPosition = dynmap.getProjection().fromLocationToLatLng(player.location);
|
|
|
|
player.marker.setLatLng(markerPosition);
|
2011-08-02 01:31:04 +02:00
|
|
|
|
|
|
|
// Only show player faces if canvas supported
|
|
|
|
if(dynmap.canvassupport == false)
|
|
|
|
configuration.showplayerfaces = false;
|
2011-07-31 19:41:01 +02:00
|
|
|
|
2011-03-31 12:54:32 +02:00
|
|
|
$(div)
|
|
|
|
.addClass('Marker')
|
|
|
|
.addClass('playerMarker')
|
|
|
|
.append(playerImage = $('<img/>')
|
|
|
|
.attr({ src: 'images/player.png' }))
|
|
|
|
.append($('<span/>')
|
2011-07-22 09:34:35 +02:00
|
|
|
.addClass(configuration.smallplayerfaces?'playerNameSm':'playerName')
|
2011-03-31 12:54:32 +02:00
|
|
|
.text(player.name));
|
2011-08-02 01:31:04 +02:00
|
|
|
|
2011-03-31 12:54:32 +02:00
|
|
|
if (configuration.showplayerfaces) {
|
2011-07-22 09:34:35 +02:00
|
|
|
if(configuration.smallplayerfaces) {
|
|
|
|
getMinecraftHead(player.account, 16, function(head) {
|
|
|
|
$(head)
|
|
|
|
.addClass('playericon')
|
2011-03-31 12:54:32 +02:00
|
|
|
.prependTo(div);
|
2011-07-22 09:34:35 +02:00
|
|
|
playerImage.remove();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
getMinecraftHead(player.account, 32, function(head) {
|
|
|
|
$(head)
|
|
|
|
.addClass('playericon')
|
|
|
|
.prependTo(div);
|
|
|
|
playerImage.remove();
|
|
|
|
});
|
|
|
|
}
|
2011-03-31 12:54:32 +02:00
|
|
|
}
|
2011-05-18 16:38:50 +02:00
|
|
|
if (configuration.showplayerhealth) {
|
2011-05-25 06:28:01 +02:00
|
|
|
if(!configuration.showplayerfaces) /* Need 32 high */
|
|
|
|
playerImage.css('margin-bottom','16px');
|
|
|
|
|
2011-05-22 16:09:50 +02:00
|
|
|
player.healthContainer = $('<div/>')
|
|
|
|
.addClass('healthContainer')
|
2011-05-18 16:38:50 +02:00
|
|
|
.appendTo(div);
|
2011-05-22 16:09:50 +02:00
|
|
|
if (player.health !== undefined && player.armor !== undefined) {
|
|
|
|
player.healthBar = $('<div/>')
|
|
|
|
.addClass('playerHealth')
|
|
|
|
.css('width', (player.health/2*5) + 'px');
|
|
|
|
player.armorBar = $('<div/>')
|
|
|
|
.addClass('playerArmor')
|
|
|
|
.css('width', (player.armor/2*5) + 'px');
|
|
|
|
|
|
|
|
$('<div/>')
|
|
|
|
.addClass('playerHealthBackground')
|
|
|
|
.append(player.healthBar)
|
|
|
|
.appendTo(player.healthContainer);
|
|
|
|
$('<div/>')
|
|
|
|
.addClass('playerArmorBackground')
|
|
|
|
.append(player.armorBar)
|
|
|
|
.appendTo(player.healthContainer);
|
|
|
|
} else {
|
|
|
|
player.healthContainer.css('display','none');
|
|
|
|
}
|
2011-05-18 16:38:50 +02:00
|
|
|
}
|
2011-07-31 19:41:01 +02:00
|
|
|
|
2011-07-16 23:53:15 +02:00
|
|
|
return div;
|
|
|
|
}});
|
2011-07-31 19:41:01 +02:00
|
|
|
if(dynmap.world === player.location.world)
|
2011-08-26 00:31:34 +02:00
|
|
|
dynmap.playermarkergroup.addLayer(player.marker);
|
2011-03-31 12:54:32 +02:00
|
|
|
});
|
|
|
|
$(dynmap).bind('playerremoved', function(event, player) {
|
|
|
|
// Remove the marker.
|
2011-07-31 19:41:01 +02:00
|
|
|
if(dynmap.map.hasLayer(player.marker))
|
2011-08-26 00:31:34 +02:00
|
|
|
dynmap.playermarkergroup.removeLayer(player.marker);
|
2011-03-31 12:54:32 +02:00
|
|
|
});
|
|
|
|
$(dynmap).bind('playerupdated', function(event, player) {
|
2011-07-31 19:41:01 +02:00
|
|
|
if(dynmap.world === player.location.world) {
|
|
|
|
// Add if needed
|
|
|
|
if(dynmap.map.hasLayer(player.marker) == false)
|
2011-08-26 00:31:34 +02:00
|
|
|
dynmap.playermarkergroup.addLayer(player.marker);
|
2011-07-31 19:41:01 +02:00
|
|
|
else {
|
|
|
|
// Update the marker.
|
|
|
|
var markerPosition = dynmap.getProjection().fromLocationToLatLng(player.location);
|
|
|
|
player.marker.setLatLng(markerPosition);
|
|
|
|
// Update health
|
|
|
|
if (configuration.showplayerhealth) {
|
|
|
|
if (player.health !== undefined && player.armor !== undefined) {
|
|
|
|
player.healthContainer.css('display','block');
|
|
|
|
player.healthBar.css('width', (player.health/2*5) + 'px');
|
|
|
|
player.armorBar.css('width', (player.armor/2*5) + 'px');
|
|
|
|
} else {
|
|
|
|
player.healthContainer.css('display','none');
|
|
|
|
}
|
|
|
|
}
|
2011-05-22 16:09:50 +02:00
|
|
|
}
|
2011-07-31 19:41:01 +02:00
|
|
|
} else if(dynmap.map.hasLayer(player.marker)) {
|
2011-08-26 00:31:34 +02:00
|
|
|
dynmap.playermarkergroup.removeLayer(player.marker);
|
2011-05-22 16:09:50 +02:00
|
|
|
}
|
2011-03-31 12:54:32 +02:00
|
|
|
});
|
2011-06-03 07:39:21 +02:00
|
|
|
// Remove marker on start of map change
|
|
|
|
$(dynmap).bind('mapchanging', function(event) {
|
|
|
|
var name;
|
|
|
|
for(name in dynmap.players) {
|
|
|
|
var player = dynmap.players[name];
|
|
|
|
// Turn off marker - let update turn it back on
|
2011-08-26 00:31:34 +02:00
|
|
|
dynmap.playermarkergroup.removeLayer(player.marker);
|
2011-06-03 07:39:21 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
// Remove marker on map change - let update place it again
|
|
|
|
$(dynmap).bind('mapchanged', function(event) {
|
|
|
|
var name;
|
|
|
|
for(name in dynmap.players) {
|
|
|
|
var player = dynmap.players[name];
|
2011-07-31 19:41:01 +02:00
|
|
|
if(dynmap.world === player.location.world) {
|
|
|
|
if(dynmap.map.hasLayer(player.marker) == false)
|
2011-08-26 00:31:34 +02:00
|
|
|
dynmap.playermarkergroup.addLayer(player.marker);
|
2011-07-31 19:41:01 +02:00
|
|
|
var markerPosition = dynmap.getProjection().fromLocationToLatLng(player.location);
|
|
|
|
player.marker.setLatLng(markerPosition);
|
|
|
|
} else if(dynmap.map.hasLayer(player.marker)) {
|
2011-08-26 00:31:34 +02:00
|
|
|
dynmap.playermarkergroup.removeLayer(player.marker);
|
2011-07-31 19:41:01 +02:00
|
|
|
}
|
2011-06-03 07:39:21 +02:00
|
|
|
}
|
|
|
|
});
|
2011-08-26 00:31:34 +02:00
|
|
|
dynmap.playermarkergroup = new L.LayerGroup();
|
|
|
|
dynmap.map.addLayer(dynmap.playermarkergroup);
|
|
|
|
dynmap.layercontrol.addOverlay(dynmap.playermarkergroup, 'Players');
|
2011-05-22 16:09:50 +02:00
|
|
|
};
|