-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstorage.js
More file actions
70 lines (63 loc) · 1.71 KB
/
Copy pathstorage.js
File metadata and controls
70 lines (63 loc) · 1.71 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
// Initialize Firebase
var config = {
apiKey: "AIzaSyBW2fPQzgophaWJaevGndcgFbbJhvZqnFs",
authDomain: "sworm-1.firebaseapp.com",
databaseURL: "https://sworm-1.firebaseio.com",
projectId: "sworm-1",
storageBucket: "",
messagingSenderId: "610479094350"
};
firebase.initializeApp(config);
// Retourne l'état du monde tel que sur Firebase
function GetWorld() {
return firebase.database()
.ref("world")
.once('value')
.then(function(snapshot) {
return snapshot.val();
});
}
// SubscribeNewWorld pour être notifié du changement du monde
function SubscribeNewWorld(cb) {
return firebase.database()
.ref("world")
.on('value', function(value){
cb(value.val());
});
}
// Set l'état du monde sur Firebase.
function SendWorld(world) {
firebase.database()
.ref("world")
.set(world);
}
// SendAction envoie l'action au serveur
function SendAction(username, action) {
firebase.database()
.ref("actions/" + username)
.set(action);
}
// Retourne les actions à simuler.
function GetActions() {
return firebase.database()
.ref("actions")
.orderByChild('time')
.once('value')
.then(function(snaptshot) {
return snaptshot.val();
});
}
// SubscribeActions pour être notifié du changement du monde
function SubscribeActions(cb) {
return firebase.database()
.ref("actions")
.on('value', function(value){
cb(value.val());
});
}
// PurgeActions supprime toutes les actions
function PurgeActions() {
firebase.database()
.ref("actions")
.set({});
}