-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbehavior.js
42 lines (40 loc) · 1.13 KB
/
behavior.js
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
var S = Standards.general;
var M = Standards.storage;
var G = Standards.game;
var loggedIn = false;
M.session.store("/games/leaving", true);
M.session.defaultLocation = "games";
M.local.defaultLocation = "games";
if (M.session.recall("save code") === null || M.session.recall("save code") instanceof Error) {
M.server.defaultLocation = "~websites/games/codes/default";
} else {
M.server.defaultLocation = "~websites/games/codes/" + M.session.recall("save code");
loggedIn = true;
}
if (loggedIn) {
S.onLoad(function () {
M.server.signIn("anonymous").then(function () {
S.makeDialog("Ready to play.");
});
});
window.addEventListener("beforeunload", function (event) {
if (M.session.recall("/games/leaving")) {
event.preventDefault();
M.server.recall("players present").then(function (value) {
if (value - 1 <= 0) {
M.server.forget("./").then(function () {
window.close();
}).catch(function () {
window.close();
});
} else {
M.server.store("players present", value - 1).then(function () {
window.close();
}).catch(function () {
window.close();
});
}
});
}
});
}