2020-01-13 08:39:32 +01:00
|
|
|
import Messaging;
|
2020-01-14 17:27:56 +01:00
|
|
|
import player from Room;
|
2020-01-13 08:39:32 +01:00
|
|
|
import Save;
|
|
|
|
import Session;
|
|
|
|
import Table;
|
2020-01-13 18:05:11 +01:00
|
|
|
import Time;
|
2020-01-13 08:39:32 +01:00
|
|
|
|
2020-01-13 23:08:20 +01:00
|
|
|
var entries = Table.make(function(o) {return o.value.date;});
|
2020-01-13 23:09:02 +01:00
|
|
|
entries.insertAll(Save.get('games.entry') || {});
|
2020-01-13 08:39:32 +01:00
|
|
|
initMessageHandlers();
|
|
|
|
|
|
|
|
return {
|
2020-01-14 09:55:04 +01:00
|
|
|
entries: entries,
|
|
|
|
proposal: proposal
|
2020-01-13 08:39:32 +01:00
|
|
|
};
|
|
|
|
|
2020-01-13 23:09:02 +01:00
|
|
|
function makeEntry(state) {
|
2020-01-13 08:39:32 +01:00
|
|
|
var sessionKey = Session.getKey();
|
2020-01-13 18:05:11 +01:00
|
|
|
return Time.timestamp({
|
2020-01-14 17:27:56 +01:00
|
|
|
vs: player(state.public.nextPlayer[sessionKey]),
|
2020-01-13 08:39:32 +01:00
|
|
|
yourTurn: state.public.playing == sessionKey
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-01-14 09:55:04 +01:00
|
|
|
function proposal(playerID, yourTurn) {
|
|
|
|
entries.insert(
|
|
|
|
playerID,
|
2020-01-14 17:27:56 +01:00
|
|
|
Time.timestamp({vs: player(playerID), yourTurn: yourTurn})
|
2020-01-14 09:55:04 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-01-13 08:39:32 +01:00
|
|
|
function initMessageHandlers() {
|
|
|
|
Messaging.addEventListener(["Game"], function(o) {
|
2020-01-18 09:35:51 +01:00
|
|
|
var gameID = o.state.public.coordinates.gameID;
|
2020-01-13 23:09:02 +01:00
|
|
|
var entry = makeEntry(o.state);
|
2020-01-15 18:06:53 +01:00
|
|
|
Save.set("games.message." + gameID, o);
|
2020-01-13 23:09:02 +01:00
|
|
|
Save.set("games.entry." + gameID, entry);
|
|
|
|
entries.insert(gameID, entry);
|
2020-01-13 08:39:32 +01:00
|
|
|
});
|
|
|
|
}
|