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;
|
||||
|
||||
var entries = Table.make(function(o) {return o.value.date;});
|
||||
entries.insertAll(Save.get('games.entry') || {});
|
||||
initMessageHandlers();
|
||||
|
||||
return {
|
||||
entries: entries
|
||||
};
|
||||
|
||||
function entry(state) {
|
||||
function makeEntry(state) {
|
||||
var sessionKey = Session.getKey();
|
||||
return Time.timestamp({
|
||||
vs: opponent(state.public.nextPlayer[sessionKey]),
|
||||
|
@ -23,7 +24,9 @@ function entry(state) {
|
|||
function initMessageHandlers() {
|
||||
Messaging.addEventListener(["Game"], function(o) {
|
||||
var gameID = o.state.public.gameState.gameID;
|
||||
var entry = makeEntry(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