Browse Source

Add guardian artifacts (closes #1)

Skylar Ittner 2 years ago
parent
commit
6812969875
5 changed files with 139 additions and 2 deletions
  1. 8
    0
      www/css/main.css
  2. 6
    0
      www/js/auth.js
  3. 1
    1
      www/js/location.js
  4. 6
    0
      www/js/user.js
  5. 118
    1
      www/screens/place.html

+ 8
- 0
www/css/main.css View File

@@ -405,6 +405,14 @@ body {
405 405
     color: black;
406 406
 }
407 407
 
408
+#artifactbtn {
409
+    color: black;
410
+}
411
+
412
+#artifact-icon {
413
+    float: right;
414
+}
415
+
408 416
 .found-box {
409 417
     position: absolute;
410 418
     z-index: 9001;

+ 6
- 0
www/js/auth.js View File

@@ -66,6 +66,12 @@ function checkUserHasTeamOpenChooserIfNot(username) {
66 66
                 // Open the team intro thingy
67 67
                 openscreen('chooseteam');
68 68
             }
69
+        } else if (data.status == "ERROR" && data.kick == 1) {
70
+            localStorage.setItem("no_autologin", "true");
71
+            username = null;
72
+            password = null;
73
+            document.location.href = "index.html";
74
+            navigator.notification.alert("Your session status has changed, and you have been logged out.  \n\nReason: " + data.message, null, "Sign-in Status Changed", "OK");
69 75
         } else {
70 76
             // Might fix a strange bug that might not exist.
71 77
             if (!teamchoosercheckretried) {

+ 1
- 1
www/js/location.js View File

@@ -197,7 +197,7 @@ var updatePosition = function (position) {
197 197
 function pingServer() {
198 198
     if (lockGot && gpsaccuracy < requiredaccuracy) {
199 199
         $.getJSON(mkApiUrl('ping') + "?user=" + username + "&lat=" + latitude + "&long=" + longitude  + "&lang=" + USER_LANGUAGE, function (data) {
200
-            if (data.status == "ERROR" && logoutInProgress != true) {
200
+            if (data.status == "ERROR") {
201 201
                 localStorage.setItem("no_autologin", "true");
202 202
                 username = null;
203 203
                 password = null;

+ 6
- 0
www/js/user.js View File

@@ -41,6 +41,12 @@ function syncStats() {
41 41
             energy = data.stats.energy;
42 42
             level = data.stats.level;
43 43
             refreshStats();
44
+        } else if (data.status === "ERROR" && data.kick == 1) {
45
+            localStorage.setItem("no_autologin", "true");
46
+            username = null;
47
+            password = null;
48
+            document.location.href = "index.html";
49
+            navigator.notification.alert("Your session status has changed, and you have been logged out.  \n\nReason: " + data.message, null, "Sign-in Status Changed", "OK");
44 50
         }
45 51
     });
46 52
 }

+ 118
- 1
www/screens/place.html View File

@@ -22,7 +22,8 @@
22 22
         Type: <span id="team-label"></span><br />
23 23
         Owner: <span id="owner-label"></span><br />
24 24
         <!-- Life: <span id="life-label"></span><br /> -->
25
-        Place life: <div class="progress" id="place-health-place"><div id="place-health-place-bar" class="progress-bar" role="progressbar" ></div></div>
25
+        Place life: <span id="artifact-icon"></span>
26
+        <div class="progress" id="place-health-place"><div id="place-health-place-bar" class="progress-bar" role="progressbar" ></div></div>
26 27
         <div class="row">
27 28
             <div class="col-xs-6">
28 29
                 <div class="btn btn-success btn-wide" id="capturebtn" onclick="attempttake()"></div>
@@ -32,6 +33,12 @@
32 33
             </div>
33 34
         </div>
34 35
         <br />
36
+        <div class="row">
37
+            <div class="col-xs-6">
38
+                <div class="btn btn-success btn-wide" id="artifactbtn" onclick="openartifactselect()"></div>
39
+            </div>
40
+        </div>
41
+        <br />
35 42
         My life: <div class="progress" id="user-health-place"><div id="user-health-place-bar" class="progress-bar" role="progressbar" ></div></div>
36 43
     </div>
37 44
     <div class="well well-sm place-log" id="place-log">
@@ -39,11 +46,26 @@
39 46
     </div>
40 47
 </div>
41 48
 
49
+<div class="menumessage" id="artifactmessage">
50
+    <div class="menumessagecontent" id="artifactmessagecontent">
51
+        Select an artifact: <br />
52
+        <select class="form-control" id="artifact-dropdown"></select>
53
+    </div>
54
+    <div style="margin-bottom: 5px;" class="btn btn-wide btn-success" onclick="attemptartifact();">
55
+        Use
56
+    </div>
57
+    <div class="btn btn-wide btn-danger" onclick="$('#artifactmessage').css('display', 'none')">
58
+        Cancel
59
+    </div>
60
+    <span style="display: none;" id="giveitem-uuid"></span>
61
+</div>
62
+
42 63
 <script>
43 64
     var thisplace = null;
44 65
     var placeteam = 0;
45 66
     var capturebtndisabled = false;
46 67
     var refillbtndisabled = false;
68
+    var artifactbtndisabled = false;
47 69
 
48 70
     // Enforced time between actions, in ms
49 71
     var actioninterval = 1000;
@@ -84,6 +106,53 @@
84 106
         }
85 107
     }
86 108
 
109
+    function resetartifactbtn() {
110
+        artifactbtndisabled = false;
111
+        $('#artifactbtn').removeClass('btn-warning');
112
+        $('#artifactbtn').addClass('btn-primary');
113
+        $('#artifactbtn').removeClass('disabled');
114
+        $('#artifactbtn').prop('disabled', false);
115
+        if (placeteam == 0) {
116
+            $('#artifactbtn').addClass('disabled');
117
+            $('#artifactbtn').text("Add Artifact");
118
+            $('#artifactbtn').prop('disabled', true);
119
+        } else if (placeteam == userteamid) {
120
+            $('#artifactbtn').text("Add Artifact");
121
+        } else {
122
+            $('#artifactbtn').addClass('disabled');
123
+            $('#artifactbtn').text("Add Artifact");
124
+            $('#artifactbtn').prop('disabled', true);
125
+        }
126
+    }
127
+
128
+    function openartifactselect() {
129
+        $.getJSON(mkApiUrl('inventory', 'gs'), {
130
+            classname: 'artifact',
131
+            lang: USER_LANGUAGE
132
+        }, function (data) {
133
+            var content = "";
134
+            if (data.status === 'OK') {
135
+                var items = data.items;
136
+                items.forEach(function (item) {
137
+                    content += "<option value='" + item.itemuuid + "'>" + item.itemname + "</option>\n";
138
+                });
139
+            } else {
140
+                content = "";
141
+            }
142
+            if (content == '') {
143
+                playSound("error");
144
+                showErrorMessage("You don't have any artifacts.");
145
+            } else {
146
+                $('#artifact-dropdown').html(content);
147
+                $('#artifactmessage').css('display', 'block');
148
+            }
149
+        });
150
+    }
151
+
152
+    function closeartifactselect() {
153
+        $('#artifactmessage').css('display', 'none');
154
+    }
155
+
87 156
     function resync(firstload) {
88 157
         $('#place-refresh').addClass('fa-spin');
89 158
         $.getJSON(mkApiUrl('getstats', 'gs'), {
@@ -120,13 +189,19 @@
120 189
                     $('#owner-label').text(data.stats.nickname);
121 190
                 }
122 191
                 $('#place-health-place-bar').css('width', String(placepercent) + '%');
192
+                $('#artifact-icon').html("");
193
+                for (var i = 0; i < data.stats.artifact; i++) {
194
+                    $('#artifact-icon').append('<i class="fa fa-bolt" aria-hidden="true"></i> ');
195
+                }
123 196
                 loadTeamSwag();
124 197
                 if (firstload === true) {
125 198
                     resetcapturebtn();
126 199
                     resetrefillbtn();
200
+                    resetartifactbtn();
127 201
                 } else {
128 202
                     setTimeout(resetcapturebtn, actioninterval);
129 203
                     setTimeout(resetrefillbtn, actioninterval);
204
+                    setTimeout(resetartifactbtn, actioninterval);
130 205
                 }
131 206
             } else {
132 207
                 $('#place-log').prepend("An error occurred.<br />");
@@ -145,9 +220,11 @@
145 220
         if (placeteam == 0) {
146 221
             $("#capturebtn").css("background-color", "#" + getTeamColorFromId(userteamid));
147 222
             $("#refillbtn").css("background-color", "#" + getTeamColorFromId(userteamid));
223
+            $("#artifactbtn").css("background-color", "#" + getTeamColorFromId(userteamid));
148 224
         } else {
149 225
             $("#capturebtn").css("background-color", "#" + getTeamColorFromId(placeteam));
150 226
             $("#refillbtn").css("background-color", "#" + getTeamColorFromId(placeteam));
227
+            $("#artifactbtn").css("background-color", "#" + getTeamColorFromId(placeteam));
151 228
         }
152 229
         $("#place-health-place-bar").css("background-color", "#" + getTeamColorFromId(placeteam));
153 230
         $("#team-label").css("color", "#" + getTeamColorFromId(placeteam));
@@ -287,6 +364,46 @@
287 364
         });
288 365
     }
289 366
 
367
+    function attemptartifact() {
368
+        capturebtndisabled = true;
369
+        $('#artifactbtn').prop('disabled', true);
370
+        $('#artifactbtn').addClass('disabled');
371
+
372
+        $.getJSON(mkApiUrl('artifactplace', 'gs'), {
373
+            locationid: thisplace.properties.gameinfo.locationid,
374
+            lat: latitude,
375
+            long: longitude,
376
+            itemid: $('#artifact-dropdown').val(),
377
+            lang: USER_LANGUAGE
378
+        }, function (data) {
379
+            if (data.status === 'OK') {
380
+                $('#artifactbtn').text(data.message);
381
+                $('#place-log').prepend("Added Artifact<br />");
382
+                if (data.levelup === true) {
383
+                    playSound("levelup");
384
+                } else {
385
+                    playSound("claim");
386
+                }
387
+                resync();
388
+            } else {
389
+                playSound("error");
390
+                $('#artifactbtn').text(data.message);
391
+                $('#artifactbtn').removeClass('btn-primary');
392
+                $('#artifactbtn').addClass('btn-warning');
393
+                $('#place-log').prepend(data.message + "<br />");
394
+                resync();
395
+            }
396
+            closeartifactselect();
397
+        }).fail(function () {
398
+            playSound("error");
399
+            $('#artifactbtn').text("Try that again.");
400
+            $('#artifactbtn').removeClass('btn-primary');
401
+            $('#artifactbtn').addClass('btn-warning');
402
+            resync();
403
+            closeartifactselect();
404
+        });
405
+    }
406
+
290 407
     function attempttake() {
291 408
         if (capturebtndisabled) {
292 409
             return;

Loading…
Cancel
Save