2011-08-24 07:51:54 +02:00
|
|
|
function createMinecraftHead(player,size,completed,failed) {
|
|
|
|
var faceImage = new Image();
|
|
|
|
faceImage.onload = function() {
|
|
|
|
completed(faceImage);
|
2010-12-28 14:41:44 +01:00
|
|
|
};
|
2011-08-24 07:51:54 +02:00
|
|
|
faceImage.onerror = function() {
|
|
|
|
failed();
|
2011-02-10 01:20:50 +01:00
|
|
|
};
|
2011-08-24 07:51:54 +02:00
|
|
|
faceImage.src = dynmap.options.tileUrl + 'faces/' + size + 'x' + size + '/' + player + '.png';
|
2010-12-28 14:41:44 +01:00
|
|
|
}
|
|
|
|
|
2011-01-01 19:36:28 +01:00
|
|
|
var playerHeads = {};
|
2010-12-28 14:41:44 +01:00
|
|
|
|
|
|
|
function getMinecraftHead(player,size,completed) {
|
2011-08-24 07:51:54 +02:00
|
|
|
var key = player + '.' + size;
|
|
|
|
var head = playerHeads[key];
|
2010-12-28 14:41:44 +01:00
|
|
|
// Synchronous
|
|
|
|
if (!completed) {
|
|
|
|
return (!head || head.working) ? null : head;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Asynchronous
|
|
|
|
if (!head) {
|
2011-08-24 07:51:54 +02:00
|
|
|
playerHeads[key] = { working: true, hooks: [{f:completed}] };
|
|
|
|
createMinecraftHead(player, size, function(head) {
|
|
|
|
hooks = playerHeads[key].hooks;
|
|
|
|
playerHeads[key] = head;
|
2010-12-28 14:41:44 +01:00
|
|
|
var i;
|
|
|
|
for(i=0;i<hooks.length;i++) {
|
2011-08-24 07:51:54 +02:00
|
|
|
hooks[i].f(head);
|
2010-12-28 14:41:44 +01:00
|
|
|
}
|
2011-02-10 01:20:50 +01:00
|
|
|
}, function() {
|
|
|
|
|
2010-12-28 14:41:44 +01:00
|
|
|
});
|
|
|
|
} else if (head.working) {
|
2011-01-15 02:11:31 +01:00
|
|
|
//console.log('Other process working on head of ',player,', will add myself to hooks...');
|
2011-08-24 07:51:54 +02:00
|
|
|
head.hooks[head.hooks.length] = {f:completed};
|
2010-12-28 14:41:44 +01:00
|
|
|
} else {
|
2011-08-24 07:51:54 +02:00
|
|
|
completed(head);
|
2010-12-28 14:41:44 +01:00
|
|
|
}
|
|
|
|
}
|
2011-02-13 23:30:19 +01:00
|
|
|
|
|
|
|
function getMinecraftTime(servertime) {
|
|
|
|
servertime = parseInt(servertime);
|
|
|
|
var day = servertime >= 0 && servertime < 13700;
|
|
|
|
return {
|
|
|
|
servertime: servertime,
|
|
|
|
days: parseInt((servertime+8000) / 24000),
|
|
|
|
|
|
|
|
// Assuming it is day at 8:00
|
|
|
|
hours: (parseInt(servertime / 1000)+8) % 24,
|
|
|
|
minutes: parseInt(((servertime / 1000) % 1) * 60),
|
|
|
|
seconds: parseInt(((((servertime / 1000) % 1) * 60) % 1) * 60),
|
|
|
|
|
|
|
|
day: day,
|
|
|
|
night: !day
|
|
|
|
};
|
2011-03-01 18:21:15 +01:00
|
|
|
}
|