Implement persistence and retrieval of Game states and entries
This commit is contained in:
parent
d308d35069
commit
173d71472e
1 changed files with 5 additions and 2 deletions
|
@ -6,13 +6,14 @@ import Table;
|
||||||
import Time;
|
import Time;
|
||||||
|
|
||||||
var entries = Table.make(function(o) {return o.value.date;});
|
var entries = Table.make(function(o) {return o.value.date;});
|
||||||
|
entries.insertAll(Save.get('games.entry') || {});
|
||||||
initMessageHandlers();
|
initMessageHandlers();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
entries: entries
|
entries: entries
|
||||||
};
|
};
|
||||||
|
|
||||||
function entry(state) {
|
function makeEntry(state) {
|
||||||
var sessionKey = Session.getKey();
|
var sessionKey = Session.getKey();
|
||||||
return Time.timestamp({
|
return Time.timestamp({
|
||||||
vs: opponent(state.public.nextPlayer[sessionKey]),
|
vs: opponent(state.public.nextPlayer[sessionKey]),
|
||||||
|
@ -23,7 +24,9 @@ function entry(state) {
|
||||||
function initMessageHandlers() {
|
function initMessageHandlers() {
|
||||||
Messaging.addEventListener(["Game"], function(o) {
|
Messaging.addEventListener(["Game"], function(o) {
|
||||||
var gameID = o.state.public.gameState.gameID;
|
var gameID = o.state.public.gameState.gameID;
|
||||||
|
var entry = makeEntry(o.state);
|
||||||
Save.set("games.state." + gameID, o.state);
|
Save.set("games.state." + gameID, o.state);
|
||||||
Save.set("games.entry." + gameID, entry(o.state));
|
Save.set("games.entry." + gameID, entry);
|
||||||
|
entries.insert(gameID, entry);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue