mirror of
https://github.com/webbukkit/dynmap.git
synced 2024-11-28 13:15:30 +01:00
Fix player faces in sidebar, while still preserving load cache
This commit is contained in:
parent
8bdce005c3
commit
eee6476d6a
@ -9,12 +9,44 @@ function createMinecraftHead(player,size,completed,failed) {
|
|||||||
faceImage.src = dynmap.options.tileUrl + 'faces/' + size + 'x' + size + '/' + player + '.png';
|
faceImage.src = dynmap.options.tileUrl + 'faces/' + size + 'x' + size + '/' + player + '.png';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var playerHeads = {};
|
||||||
|
|
||||||
function getMinecraftHead(player,size,completed) {
|
function getMinecraftHead(player,size,completed) {
|
||||||
createMinecraftHead(player, size, completed, function() {
|
var key = player + '.' + size;
|
||||||
console.error('Failed to retrieve face of "', player, '" with size "', size, '"!')
|
var head = playerHeads[key];
|
||||||
});
|
// Synchronous
|
||||||
|
if (!completed) {
|
||||||
|
return (!head || head.working) ? null : head;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Asynchronous
|
||||||
|
if (!head) {
|
||||||
|
playerHeads[key] = { working: true, hooks: [{f:completed}] };
|
||||||
|
createMinecraftHead(player, size, function(head) {
|
||||||
|
hooks = playerHeads[key].hooks;
|
||||||
|
playerHeads[key] = head;
|
||||||
|
var i;
|
||||||
|
for(i=0;i<hooks.length;i++) {
|
||||||
|
hooks[i].f(head);
|
||||||
|
}
|
||||||
|
head.working = false;
|
||||||
|
}, function() {
|
||||||
|
|
||||||
|
});
|
||||||
|
} else if (head.working) {
|
||||||
|
//console.log('Other process working on head of ',player,', will add myself to hooks...');
|
||||||
|
head.hooks[head.hooks.length] = {f:completed};
|
||||||
|
} else {
|
||||||
|
completed(head);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//function getMinecraftHead(player,size,completed) {
|
||||||
|
// createMinecraftHead(player, size, completed, function() {
|
||||||
|
// console.error('Failed to retrieve face of "', player, '" with size "', size, '"!')
|
||||||
|
// });
|
||||||
|
//}
|
||||||
|
|
||||||
function getMinecraftTime(servertime) {
|
function getMinecraftTime(servertime) {
|
||||||
servertime = parseInt(servertime);
|
servertime = parseInt(servertime);
|
||||||
var day = servertime >= 0 && servertime < 13700;
|
var day = servertime >= 0 && servertime < 13700;
|
||||||
|
Loading…
Reference in New Issue
Block a user