X-Git-Url: https://git.auder.net/doc/index.css?a=blobdiff_plain;f=public%2Fjavascripts%2Fcomponents%2Fgame.js;h=0d9322e2962b683d6c93ed2341c60798b2f52e42;hb=97da8720d3f33cb0c29079baf42c52ed047c3049;hp=37cdec193654940872aff8eff47a14202bfb4d40;hpb=d337a94cd6d38bb743a8935017d03fe21d4ad324;p=vchess.git
diff --git a/public/javascripts/components/game.js b/public/javascripts/components/game.js
index 37cdec19..0d9322e2 100644
--- a/public/javascripts/components/game.js
+++ b/public/javascripts/components/game.js
@@ -1,14 +1,19 @@
-// TODO: envoyer juste "light move", sans FEN ni notation ...etc
-// TODO: also "observers" prop (human mode only), we should send moves to them too (in a web worker ? webRTC ?)
// Game logic on a variant page: 3 modes, analyze, computer or human
+// TODO: envoyer juste "light move", sans FEN ni notation ...etc
+// TODO: if I'm an observer and player(s) disconnect/reconnect, how to find me ?
+// onClick :: ask full game to remote player, and register as an observer in game
+// (use gameId to communicate)
+// on landing on game :: if gameId not found locally, check remotely
+// ==> il manque un param dans game : "remoteId"
Vue.component('my-game', {
// gameId: to find the game in storage (assumption: it exists)
// fen: to start from a FEN without identifiers (analyze mode)
- // subMode: "auto" (game comp vs comp) or "corr" (correspondance game)
- props: ["conn","gameId","fen","mode","subMode","allowChat","allowMovelist","queryHash","settings"],
+ // subMode: "auto" (game comp vs comp) or "corr" (correspondance game),
+ // or "examine" (after human game: TODO)
+ props: ["conn","gameRef","fen","mode","subMode",
+ "allowChat","allowMovelist","settings"],
data: function() {
return {
- oppConnected: false, //TODO?
// Web worker to play computer moves without freezing interface:
compWorker: new Worker('/javascripts/playCompMove.js'),
timeStart: undefined, //time when computer starts thinking
@@ -16,8 +21,10 @@ Vue.component('my-game', {
endgameMessage: "",
orientation: "w",
lockCompThink: false, //used to avoid some ghost moves
-
- oppid: "", //opponent ID in case of HH game
+ myname: user.name, //may be anonymous (thus no name)
+ opponents: {}, //filled later (potentially 2 or 3 opponents)
+ drawOfferSent: false, //did I just ask for draw?
+ people: {}, //observers
score: "*", //'*' means 'unfinished'
// userColor: given by gameId, or fen in problems mode (if no game Id)...
mycolor: "w",
@@ -28,35 +35,13 @@ Vue.component('my-game', {
};
},
watch: {
- fen: function(newFen) {
+ fen: function() {
// (Security) No effect if a computer move is in progress:
if (this.mode == "computer" && this.lockCompThink)
return this.$emit("computer-think");
- this.vr = new VariantRules(newFen);
- this.moves = [];
- this.cursor = -1;
- this.fenStart = newFen;
- this.score = "*";
- if (this.mode == "analyze")
- {
- this.mycolor = V.ParseFen(newFen).turn;
- this.orientation = "w"; //convention (TODO?!)
- }
- else if (this.mode == "computer") //only other alternative (HH with gameId)
- {
- this.mycolor = (Math.random() < 0.5 ? "w" : "b");
- this.orientation = this.mycolor;
- this.compWorker.postMessage(["init",newFen]);
- if (this.mycolor != "w" || this.subMode == "auto")
- this.playComputerMove();
- }
- },
- gameId: function() {
- this.loadGame();
+ this.newGameFromFen();
},
- queryHash: function(newQhash) {
- // New query hash = "id=42"; get 42 as gameId
- this.gameId = parseInt(newQhash.substr(2));
+ gameRef: function() {
this.loadGame();
},
},
@@ -73,9 +58,6 @@ Vue.component('my-game', {
},
},
// Modal end of game, and then sub-components
- // TODO: provide chat parameters (connection, players ID...)
- // TODO: controls: abort, clear, resign, draw (avec confirm box)
- // TODO: add corrMsg to sent move in case of corr game
template: `