-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy patharisjs.js
More file actions
executable file
·231 lines (203 loc) · 11.8 KB
/
arisjs.js
File metadata and controls
executable file
·231 lines (203 loc) · 11.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
var ARISJS = function(_ARIS)
{
_ARIS.requestsQueue = new Array();
_ARIS.currentlyCalling = false;
_ARIS.enqueueRequest = function(nextRequest)
{
_ARIS.requestsQueue.push(nextRequest);
if(!_ARIS.currentlyCalling)
{
_ARIS.currentlyCalling = true;
_ARIS.dequeueRequest();
}
}
_ARIS.isCurrentlyCalling = function()
{
_ARIS.currentlyCalling = true;
}
_ARIS.dequeueRequest = function()
{
if(_ARIS.requestsQueue.length)
{
var req = _ARIS.requestsQueue.shift();
window.location = req;
}
}
_ARIS.isNotCurrentlyCalling = function()
{
_ARIS.currentlyCalling = false;
_ARIS.dequeueRequest();
}
//legacy
_ARIS.closeMe = function() { _ARIS.enqueueRequest("aris://exit"); }
_ARIS.hideLeaveButton = function() { }
_ARIS.playMediaAndVibrate = function(media_id) { }
_ARIS.exitToCharacter = function(dialog_id) { _ARIS.enqueueRequest("aris://exit/character/"+dialog_id); }
_ARIS.getItemCount = function(item_id) { _ARIS.enqueueRequest("aris://instances/player/get/" + item_id); }
_ARIS.setItemCount = function(item_id,qty) { _ARIS.enqueueRequest("aris://instances/player/set/" + item_id + "/" + qty); }
_ARIS.giveItemCount = function(item_id,qty) { _ARIS.enqueueRequest("aris://instances/player/give/" + item_id + "/" + qty); }
_ARIS.takeItemCount = function(item_id,qty) { _ARIS.enqueueRequest("aris://instances/player/take/" + item_id + "/" + qty); }
_ARIS.logOut = function() { _ARIS.enqueueRequest("aris://logout"); }
_ARIS.exit = function() { _ARIS.enqueueRequest("aris://exit"); }
_ARIS.exitToTab = function(tab) { _ARIS.enqueueRequest("aris://exit/tab/"+tab); }
_ARIS.exitToScanner = function(prompt) { _ARIS.enqueueRequest("aris://exit/scanner/"+(prompt || "")); }
_ARIS.exitToAugmented = function(options) {
if (options == null) options = {};
_ARIS.enqueueRequest("aris://exit/augmented/"+(options.media_id || 0)+"/"+(options.prompt || ""));
}
_ARIS.exitToPlaque = function(plaque_id) { _ARIS.enqueueRequest("aris://exit/plaque/"+plaque_id); }
_ARIS.exitToWebpage = function(webpageId) { _ARIS.enqueueRequest("aris://exit/webpage/"+webpageId); }
_ARIS.exitToItem = function(item_id) { _ARIS.enqueueRequest("aris://exit/item/"+item_id); }
_ARIS.exitToDialog = function(dialog_id) { _ARIS.enqueueRequest("aris://exit/character/"+dialog_id); }
_ARIS.exitToQuest = function(quest_name) { _ARIS.enqueueRequest("aris://exit/quest/"+quest_name); }
_ARIS.exitGame = function() { _ARIS.enqueueRequest("aris://exit/game/"); }
_ARIS.prepareMedia = function(media_id) { _ARIS.enqueueRequest("aris://media/prepare/" + media_id); }
_ARIS.playMedia = function(media_id) { _ARIS.enqueueRequest("aris://media/play/" + media_id); }
_ARIS.stopMedia = function(media_id) { _ARIS.enqueueRequest("aris://media/stop/" + media_id); }
_ARIS.setMediaVolume = function(media_id, volume) { _ARIS.enqueueRequest("aris://media/setVolume/" + media_id + "/" + volume); }
_ARIS.vibrate = function() { _ARIS.enqueueRequest("aris://vibrate"); }
_ARIS.getPlayerItemCount = function(item_id) { _ARIS.enqueueRequest("aris://instances/player/get/" + item_id); }
_ARIS.setPlayerItemCount = function(item_id,qty) { _ARIS.enqueueRequest("aris://instances/player/set/" + item_id + "/" + qty); }
_ARIS.givePlayerItemCount = function(item_id,qty) { _ARIS.enqueueRequest("aris://instances/player/give/" + item_id + "/" + qty); }
_ARIS.takePlayerItemCount = function(item_id,qty) { _ARIS.enqueueRequest("aris://instances/player/take/" + item_id + "/" + qty); }
_ARIS.getGameItemCount = function(item_id) { _ARIS.enqueueRequest("aris://instances/game/get/" + item_id); }
_ARIS.setGameItemCount = function(item_id,qty) { _ARIS.enqueueRequest("aris://instances/game/set/" + item_id + "/" + qty); }
_ARIS.giveGameItemCount = function(item_id,qty) { _ARIS.enqueueRequest("aris://instances/game/give/" + item_id + "/" + qty); }
_ARIS.takeGameItemCount = function(item_id,qty) { _ARIS.enqueueRequest("aris://instances/game/take/" + item_id + "/" + qty); }
_ARIS.getGroupItemCount = function(item_id) { _ARIS.enqueueRequest("aris://instances/group/get/" + item_id); }
_ARIS.setGroupItemCount = function(item_id,qty) { _ARIS.enqueueRequest("aris://instances/group/set/" + item_id + "/" + qty); }
_ARIS.giveGroupItemCount = function(item_id,qty) { _ARIS.enqueueRequest("aris://instances/group/give/" + item_id + "/" + qty); }
_ARIS.takeGroupItemCount = function(item_id,qty) { _ARIS.enqueueRequest("aris://instances/group/take/" + item_id + "/" + qty); }
_ARIS.setGroup = function(group_id) { _ARIS.enqueueRequest("aris://group/set/" + group_id); }
_ARIS.setScene = function(scene_id) { _ARIS.enqueueRequest("aris://scene/set/" + scene_id); }
_ARIS.getPlayer = function() { _ARIS.enqueueRequest("aris://player"); }
_ARIS.getTriggerLocation = function(trigger_id) { _ARIS.enqueueRequest("aris://trigger/" + (trigger_id || 0)); }
_ARIS.showNotesOnMap = function(showNotes) { _ARIS.enqueueRequest("aris://instances/map/showNotesOnMap/set/" + showNotes); }
//Call ARIS API directly (USE WITH CAUTION)
_ARIS.callService = function(serviceName, body, auth, callback)
{
var ROOT_URL = "https://arisgames.org"
var url = ROOT_URL+'/server/json.php/v2.'+serviceName;
var request = new XMLHttpRequest();
request.onreadystatechange = function()
{
if(request.readyState == 4)
{
debugLog(request.responseText);
if(request.status == 200)
callback(JSON.parse(request.responseText));
else
callback(false);
}
};
body.auth = auth;
request.open('POST', url, true);
request.setRequestHeader("Content-type","application/json");
debugLog(JSON.stringify(body));
request.send(JSON.stringify(body));
}
//Not ARIS related... just kinda useful
_ARIS.parseURLParams = function(url)
{
var queryStart = url.indexOf("?") + 1;
var queryEnd = url.indexOf("#") + 1 || url.length + 1;
var query = url.slice(queryStart, queryEnd - 1);
var params = {};
if (query === url || query === "") return params;
var nvPairs = query.replace(/\+/g, " ").split("&");
for(var i=0; i<nvPairs.length; i++)
{
var nv = nvPairs[i].split("=");
var n = decodeURIComponent(nv[0]);
var v = decodeURIComponent(nv[1]);
if(!(n in params)) params[n] = [];
params[n].push(nv.length === 2 ? v : null);
}
return params;
}
/*
* ARIS CALLBACK FUNCTIONS
*/
var callbacks_enabled = (typeof(_ARIS.callbacksEnabled) === 'undefined' || _ARIS.callbacksEnabled);
if(!callbacks_enabled || typeof(_ARIS.didUpdateItemQty) === 'undefined') { _ARIS.didUpdateItemQty = function(updatedItemId,qty) {} }
if(!callbacks_enabled || typeof(_ARIS.didUpdatePlayerItemQty) === 'undefined') { _ARIS.didUpdatePlayerItemQty = function(updatedItemId,qty) {} }
if(!callbacks_enabled || typeof(_ARIS.didUpdateGameItemQty) === 'undefined') { _ARIS.didUpdateGameItemQty = function(updatedItemId,qty) {} }
if(!callbacks_enabled || typeof(_ARIS.didUpdateGroupItemQty) === 'undefined') { _ARIS.didUpdateGroupItemQty = function(updatedItemId,qty) {} }
if(!callbacks_enabled || typeof(_ARIS.didReceivePlayer) === 'undefined') { _ARIS.didReceivePlayer = function(player) {} }
if(!callbacks_enabled || typeof(_ARIS.didReceiveTriggerLocation) === 'undefined') { _ARIS.didReceiveTriggerLocation = function(trigger) {} }
if(!callbacks_enabled || typeof(_ARIS.hook) === 'undefined') { _ARIS.hook = function(paramsJSON) {} }
if(!callbacks_enabled || typeof(_ARIS.tick) === 'undefined') { _ARIS.tick = function(paramsJSON) {} }
if( typeof(_ARIS.ready) === 'undefined') { _ARIS.ready = function() {} }
/*
* ARIS CACHE FUNCTIONS (USER DO NOT TOUCH)
*/
var cache_enabled = (typeof(_ARIS.dataCacheEnabled) !== 'undefined' && _ARIS.dataCacheEnabled);
if(cache_enabled)
{
var name_map = [];
var cache_player = [];
var cache_game = [];
var cache_group = [];
_ARIS.cache = {};
_ARIS.cache.preload = function() {
_ARIS.enqueueRequest("aris://cache/preload");
};
_ARIS.cache.idForItemName = function(item_name) { if(name_map[item_name] === 'undefined') return 0; return name_map[item_name]; }
_ARIS.cache.getPlayerItemCount = function(item_id) { if(typeof(cache_player[item_id]) === 'undefined') return 0; return cache_player[item_id]; }
_ARIS.cache.getGameItemCount = function(item_id) { if(typeof(cache_game[item_id]) === 'undefined') return 0; return cache_game[item_id]; }
_ARIS.cache.getGroupItemCount = function(item_id) { if(typeof(cache_group[item_id]) === 'undefined') return 0; return cache_group[item_id]; }
_ARIS.cache.setItemName = function(item_id, name) { name_map[name] = item_id; }
_ARIS.cache.setPlayerItem = function(item_id, qty) { cache_player[item_id] = qty; }
_ARIS.cache.setGameItem = function(item_id, qty) { cache_game[item_id] = qty; }
_ARIS.cache.setGroupItem = function(item_id, qty) { cache_group[item_id] = qty; }
_ARIS.cache.setPlayer = function(player)
{
_ARIS.cache.player = player;
_ARIS.cache.player.auth = {};
_ARIS.cache.player.auth.user_id = _ARIS.cache.player.user_id;
_ARIS.cache.player.auth.key = _ARIS.cache.player.key;
};
_ARIS.cache.detach = function()
{
_ARIS.cache.setItemName = undefined;
_ARIS.cache.setPlayerItem = undefined;
_ARIS.cache.setGameItem = undefined;
_ARIS.cache.setGroupItem = undefined;
_ARIS.ready();
}
_ARIS.cache.wholeCache = function() { return {"player":cache_player,"game":cache_game,"group":cache_group}; } //FOR DEBUGGING
}
/*
* ARIS DEBUG LOG FUNCTIONS
*/
var debugLog = function(str) { }
var log_enabled = (typeof(_ARIS.debugLogEnabled) !== 'undefined' && _ARIS.debugLogEnabled);
if(log_enabled)
{
var debug = document.createElement('div');
debug.setAttribute("id","_ARIS_JS_DEBUG_LOG");
debug.style.width = "100%";
debug.style.height = "100%";
debug.style.position = "absolute";
debug.style.top = "0px";
debug.style.left = "0px";
debug.style.pointerEvents = "none";
debug.style.wordWrap = "break-word";
document.body.appendChild(debug);
debugLog = function(str)
{
console.log(str);
debug.innerHTML = str+"<br />"+debug.innerHTML;
}
}
return _ARIS;
}
if(typeof(ARIS) === 'undefined') var ARIS = ARISJS({});
else
{
if(typeof ARIS.dataCacheEnabled === 'undefined')
ARIS.dataCacheEnabled = true;
ARIS = ARISJS(ARIS);
}
if(ARIS.dataCacheEnabled) ARIS.cache.preload();
else ARIS.ready();