[245] | 1 | function StartStatsModule () {
|
---|
| 2 | var updateGameTimeEvent = function() {
|
---|
| 3 | $.getJSON( "../api/getstats")
|
---|
| 4 | .done(function(data) {
|
---|
| 5 | var time = "Day " + data.gametime.days + ", ";
|
---|
| 6 | if (data.gametime.hours < 10)
|
---|
| 7 | time += "0";
|
---|
| 8 | time += data.gametime.hours;
|
---|
| 9 | time += ":";
|
---|
| 10 | if (data.gametime.minutes < 10)
|
---|
| 11 | time += "0";
|
---|
| 12 | time += data.gametime.minutes;
|
---|
| 13 |
|
---|
| 14 | $("#stats_time").html (time);
|
---|
| 15 | $("#stats_players").html (data.players);
|
---|
[251] | 16 | $("#stats_hostiles").html (data.hostiles);
|
---|
| 17 | $("#stats_animals").html (data.animals);
|
---|
[245] | 18 | })
|
---|
| 19 | .fail(function(jqxhr, textStatus, error) {
|
---|
| 20 | console.log("Error fetching game stats");
|
---|
| 21 | })
|
---|
| 22 | .always(function() {
|
---|
| 23 | });
|
---|
| 24 | window.setTimeout(updateGameTimeEvent, 2000);
|
---|
| 25 | };
|
---|
| 26 | updateGameTimeEvent();
|
---|
| 27 | }
|
---|
| 28 |
|
---|
[250] | 29 | function StartUIUpdatesModule () {
|
---|
| 30 | var updateGameTimeEvent = function() {
|
---|
| 31 | $.getJSON( "../api/getwebuiupdates?latestLine=" + lastLogLine)
|
---|
| 32 | .done(function(data) {
|
---|
| 33 | var time = "Day " + data.gametime.days + ", ";
|
---|
| 34 | if (data.gametime.hours < 10)
|
---|
| 35 | time += "0";
|
---|
| 36 | time += data.gametime.hours;
|
---|
| 37 | time += ":";
|
---|
| 38 | if (data.gametime.minutes < 10)
|
---|
| 39 | time += "0";
|
---|
| 40 | time += data.gametime.minutes;
|
---|
| 41 |
|
---|
| 42 | $("#stats_time").html (time);
|
---|
| 43 | $("#stats_players").html (data.players);
|
---|
[251] | 44 | $("#stats_hostiles").html (data.hostiles);
|
---|
| 45 | $("#stats_animals").html (data.animals);
|
---|
[250] | 46 | $("#newlogcount").html (data.newlogs);
|
---|
| 47 | if (data.newlogs > 0) {
|
---|
| 48 | $("#newlogcount").addClass ("visible");
|
---|
| 49 | } else {
|
---|
| 50 | $("#newlogcount").removeClass ("visible");
|
---|
| 51 | }
|
---|
| 52 | })
|
---|
| 53 | .fail(function(jqxhr, textStatus, error) {
|
---|
| 54 | console.log("Error fetching ui updates");
|
---|
| 55 | })
|
---|
| 56 | .always(function() {
|
---|
| 57 | });
|
---|
| 58 | window.setTimeout(updateGameTimeEvent, 2000);
|
---|
| 59 | };
|
---|
| 60 | updateGameTimeEvent();
|
---|
| 61 | }
|
---|
| 62 |
|
---|