37 lines
714 B
JavaScript
37 lines
714 B
JavaScript
|
import Messaging;
|
||
|
import opponent from Room;
|
||
|
import Save;
|
||
|
import Session;
|
||
|
import Table;
|
||
|
|
||
|
var entries = Table.make(makeEntry, 'date');
|
||
|
initMessageHandlers();
|
||
|
|
||
|
return {
|
||
|
entry: entry,
|
||
|
timestamp: timestamp
|
||
|
};
|
||
|
|
||
|
function entry(state) {
|
||
|
var sessionKey = Session.getKey();
|
||
|
return timestamp({
|
||
|
vs: opponent(state.public.nextPlayer[sessionKey]),
|
||
|
yourTurn: state.public.playing == sessionKey
|
||
|
});
|
||
|
}
|
||
|
|
||
|
function timestamp(config) {
|
||
|
return {
|
||
|
vs: config.vs,
|
||
|
yourTurn: config.yourTurn,
|
||
|
date: Date.now()
|
||
|
};
|
||
|
}
|
||
|
|
||
|
function initMessageHandlers() {
|
||
|
Messaging.addEventListener(["Game"], function(o) {
|
||
|
Save.set("games.state." + o.state.gameID, o.state);
|
||
|
Save.set("games.entry." + o.state.gameID, entry(o.state));
|
||
|
});
|
||
|
}
|