1
0
forked from MTSR/mapserver
mapserver/server/static/js/WorldInfoDisplay.js

69 lines
1.5 KiB
JavaScript
Raw Normal View History

2019-04-04 11:19:29 +03:00
/* exported WorldInfoDisplay */
2019-02-04 23:25:30 +03:00
2019-05-14 17:03:21 +03:00
var worldInfoRender = function(info){
2019-05-14 17:17:04 +03:00
2019-05-14 21:46:11 +03:00
var timeIcon = m("span", { class: "fa fa-sun", style: "color: orange;" });
2019-05-14 17:17:04 +03:00
if (info.time < 5500 || info.time > 19000) //0 - 24'000
2019-05-14 21:46:11 +03:00
timeIcon = m("span", { class: "fa fa-moon", style: "color: blue;" });
2019-05-14 17:17:04 +03:00
function getHour(){
return Math.floor(info.time/1000);
}
function getMinute(){
2019-05-14 21:46:11 +03:00
var min = Math.floor((info.time % 1000) / 1000 * 60);
return min > 10 ? min : "0" + min;
2019-05-14 17:17:04 +03:00
}
function getLag(){
var color = "green";
if (info.max_lag > 0.8)
2019-05-14 21:46:11 +03:00
color = "orange";
2019-05-14 17:17:04 +03:00
else if (info.max_lag > 1.2)
color = "red";
return [
m("span", { class: "fa fa-wifi", style: "color: " + color }),
2019-05-14 21:46:11 +03:00
parseInt(info.max_lag*1000),
2019-05-14 17:17:04 +03:00
" ms"
];
}
2019-05-14 17:19:24 +03:00
function getPlayers(){
return [
m("span", { class: "fa fa-users" }),
2019-05-14 21:46:11 +03:00
info.players ? info.players.length : "0"
2019-05-14 17:19:24 +03:00
];
}
2019-05-14 21:46:11 +03:00
return m("div", [
2019-05-14 17:19:24 +03:00
getPlayers(),
" ",
2019-05-14 17:17:04 +03:00
getLag(),
" ",
m("span", { class: "fa fa-clock" }),
timeIcon,
getHour(), ":", getMinute()
2019-05-14 21:46:11 +03:00
]);
2019-05-14 17:17:04 +03:00
2019-05-14 17:04:42 +03:00
};
2019-05-14 17:03:21 +03:00
2019-02-04 23:25:30 +03:00
// coord display
var WorldInfoDisplay = L.Control.extend({
initialize: function(wsChannel, opts) {
L.Control.prototype.initialize.call(this, opts);
this.wsChannel = wsChannel;
},
2019-04-04 11:19:29 +03:00
onAdd: function() {
2019-02-04 23:25:30 +03:00
var div = L.DomUtil.create('div', 'leaflet-bar leaflet-custom-display');
this.wsChannel.addListener("minetest-info", function(info){
2019-05-14 17:04:42 +03:00
m.render(div, worldInfoRender(info));
2019-02-04 23:25:30 +03:00
});
return div;
}
});