Factorize game proposals insertion to avoid spreading use of opponent and timestamp

This commit is contained in:
Tissevert 2020-01-14 09:55:04 +01:00
parent 173d71472e
commit b8c95646dc
3 changed files with 12 additions and 13 deletions

View file

@ -4,9 +4,7 @@ import I18n;
import * as Players from GUI.Screen.Hall.Players;
import * as GamesGUI from GUI.Screen.Hall.Games;
import Messaging;
import opponent from Room;
import StatusHandler;
import Time;
return {
init: init
@ -29,10 +27,7 @@ function init() {
});
Messaging.addEventListener(["Relay", "Invitation"], function(o) {
StatusHandler.set("🎴");
Games.entries.insert(
o.from,
Time.timestamp({vs: opponent(o.from), yourTurn: true})
);
Games.proposal(o.from, true);
GamesGUI.refresh();
});
Messaging.addEventListener(["Relay", "Answer"], function(o) {

View file

@ -4,8 +4,7 @@ import * as ListSelector from GUI.ListSelector;
import * as GamesGUI from GUI.Screen.Hall.Games;
import I18n;
import Messaging;
import {opponent, players} from Room;
import Time;
import players from Room;
import * as Dom from UnitJS.Dom;
var form = ConnectedForm.get('room');
@ -23,10 +22,7 @@ function initDOM() {
form.root.addEventListener('submit', function(e) {
e.preventDefault();
Messaging.send({tag: "Invitation", to: them});
Games.entries.insert(
them,
Time.timestamp({vs: opponent(them), yourTurn: false})
);
Games.proposal(them, false);
GamesGUI.refresh();
});
form.root.them.addEventListener("input", function() {refresh();});

View file

@ -10,7 +10,8 @@ entries.insertAll(Save.get('games.entry') || {});
initMessageHandlers();
return {
entries: entries
entries: entries,
proposal: proposal
};
function makeEntry(state) {
@ -21,6 +22,13 @@ function makeEntry(state) {
});
}
function proposal(playerID, yourTurn) {
entries.insert(
playerID,
Time.timestamp({vs: opponent(playerID), yourTurn: yourTurn})
);
}
function initMessageHandlers() {
Messaging.addEventListener(["Game"], function(o) {
var gameID = o.state.public.gameState.gameID;