Factorize game proposals insertion to avoid spreading use of opponent and timestamp
This commit is contained in:
parent
173d71472e
commit
b8c95646dc
3 changed files with 12 additions and 13 deletions
|
@ -4,9 +4,7 @@ import I18n;
|
||||||
import * as Players from GUI.Screen.Hall.Players;
|
import * as Players from GUI.Screen.Hall.Players;
|
||||||
import * as GamesGUI from GUI.Screen.Hall.Games;
|
import * as GamesGUI from GUI.Screen.Hall.Games;
|
||||||
import Messaging;
|
import Messaging;
|
||||||
import opponent from Room;
|
|
||||||
import StatusHandler;
|
import StatusHandler;
|
||||||
import Time;
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
init: init
|
init: init
|
||||||
|
@ -29,10 +27,7 @@ function init() {
|
||||||
});
|
});
|
||||||
Messaging.addEventListener(["Relay", "Invitation"], function(o) {
|
Messaging.addEventListener(["Relay", "Invitation"], function(o) {
|
||||||
StatusHandler.set("🎴");
|
StatusHandler.set("🎴");
|
||||||
Games.entries.insert(
|
Games.proposal(o.from, true);
|
||||||
o.from,
|
|
||||||
Time.timestamp({vs: opponent(o.from), yourTurn: true})
|
|
||||||
);
|
|
||||||
GamesGUI.refresh();
|
GamesGUI.refresh();
|
||||||
});
|
});
|
||||||
Messaging.addEventListener(["Relay", "Answer"], function(o) {
|
Messaging.addEventListener(["Relay", "Answer"], function(o) {
|
||||||
|
|
|
@ -4,8 +4,7 @@ import * as ListSelector from GUI.ListSelector;
|
||||||
import * as GamesGUI from GUI.Screen.Hall.Games;
|
import * as GamesGUI from GUI.Screen.Hall.Games;
|
||||||
import I18n;
|
import I18n;
|
||||||
import Messaging;
|
import Messaging;
|
||||||
import {opponent, players} from Room;
|
import players from Room;
|
||||||
import Time;
|
|
||||||
import * as Dom from UnitJS.Dom;
|
import * as Dom from UnitJS.Dom;
|
||||||
|
|
||||||
var form = ConnectedForm.get('room');
|
var form = ConnectedForm.get('room');
|
||||||
|
@ -23,10 +22,7 @@ function initDOM() {
|
||||||
form.root.addEventListener('submit', function(e) {
|
form.root.addEventListener('submit', function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
Messaging.send({tag: "Invitation", to: them});
|
Messaging.send({tag: "Invitation", to: them});
|
||||||
Games.entries.insert(
|
Games.proposal(them, false);
|
||||||
them,
|
|
||||||
Time.timestamp({vs: opponent(them), yourTurn: false})
|
|
||||||
);
|
|
||||||
GamesGUI.refresh();
|
GamesGUI.refresh();
|
||||||
});
|
});
|
||||||
form.root.them.addEventListener("input", function() {refresh();});
|
form.root.them.addEventListener("input", function() {refresh();});
|
||||||
|
|
10
js/Games.js
10
js/Games.js
|
@ -10,7 +10,8 @@ entries.insertAll(Save.get('games.entry') || {});
|
||||||
initMessageHandlers();
|
initMessageHandlers();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
entries: entries
|
entries: entries,
|
||||||
|
proposal: proposal
|
||||||
};
|
};
|
||||||
|
|
||||||
function makeEntry(state) {
|
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() {
|
function initMessageHandlers() {
|
||||||
Messaging.addEventListener(["Game"], function(o) {
|
Messaging.addEventListener(["Game"], function(o) {
|
||||||
var gameID = o.state.public.gameState.gameID;
|
var gameID = o.state.public.gameState.gameID;
|
||||||
|
|
Loading…
Reference in a new issue