source: binary-improvements/webserver_legacy/js/stats.js@ 464

Last change on this file since 464 was 299, checked in by alloc, 8 years ago

Fixes

File size: 2.8 KB
Line 
1function DayName (days) {
2 var daynames = ["", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Bloodday"];
3 return daynames[DayOfWeek(days)];
4}
5
6function DayOfWeek (days) {
7 return days % 7 > 0 ? days % 7 : 7;
8}
9
10function GetDayStat (days) {
11 var daynames = ["", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Bloodday"];
12 var dayOfWeek = days % 7 > 0 ? days % 7 : 7;
13 var result = "";
14 // Show days til blood moon:
15 result += " (" + (7 - dayOfWeek) + " til blood moon)";
16 // Show day of week (number):
17 result += " (DoW: " + dayOfWeek + ")";
18 // Show day of week (name):
19 result += " (" + daynames[dayOfWeek] + ")";
20 return result;
21}
22
23function FormatServerTime (gametime) {
24 var time = "Day " + gametime.days;
25 time += " (" + DayName (gametime.days) + "), ";
26 if (gametime.hours < 10)
27 time += "0";
28 time += gametime.hours;
29 time += ":";
30 if (gametime.minutes < 10)
31 time += "0";
32 time += gametime.minutes;
33 return time;
34}
35
36function TimeTitle (gametime) {
37 var daynames = ["", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Bloodday"];
38 var dayOfWeek = DayOfWeek (gametime.days);
39 var result = "";
40 // Show days til blood moon:
41 result += (7 - dayOfWeek) + " days til blood moon\n";
42 // Show day of week (number):
43 result += "Day of week: " + dayOfWeek + "\n";
44 // Show day of week (name):
45 //result += daynames[dayOfWeek];
46 return result;
47}
48
49function StartStatsModule () {
50 var updateGameTimeEvent = function() {
51 $.getJSON( "../api/getstats")
52 .done(function(data) {
53 var time = FormatServerTime (data.gametime);
54
55 $("#stats_time").html (time);
56 $("#stats_time").prop ("title", TimeTitle (data.gametime));
57 $("#stats_players").html (data.players);
58 $("#stats_hostiles").html (data.hostiles);
59 $("#stats_animals").html (data.animals);
60 })
61 .fail(function(jqxhr, textStatus, error) {
62 console.log("Error fetching game stats");
63 })
64 .always(function() {
65 });
66 window.setTimeout(updateGameTimeEvent, 2000);
67 };
68 updateGameTimeEvent();
69}
70
71function StartUIUpdatesModule () {
72 var updateGameTimeEvent = function() {
73 $.getJSON( "../api/getwebuiupdates?latestLine=" + lastLogLine)
74 .done(function(data) {
75 var time = FormatServerTime (data.gametime);
76
77 $("#stats_time").html (time);
78 $("#stats_time").prop ("title", TimeTitle (data.gametime));
79 $("#stats_players").html (data.players);
80 $("#stats_hostiles").html (data.hostiles);
81 $("#stats_animals").html (data.animals);
82 $("#newlogcount").html (data.newlogs);
83 if (data.newlogs > 0) {
84 $("#newlogcount").addClass ("visible");
85 } else {
86 $("#newlogcount").removeClass ("visible");
87 }
88 })
89 .fail(function(jqxhr, textStatus, error) {
90 console.log("Error fetching ui updates");
91 })
92 .always(function() {
93 });
94 window.setTimeout(updateGameTimeEvent, 2000);
95 };
96 updateGameTimeEvent();
97}
98
Note: See TracBrowser for help on using the repository browser.