Implement persistence and retrieval of Game states and entries

This commit is contained in:
Tissevert 2020-01-13 23:09:02 +01:00
parent d308d35069
commit 173d71472e

View file

@ -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);
});
}