projects
/
vchess.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix challenge creation (TODO: decide a challenge structure)
[vchess.git]
/
public
/
javascripts
/
components
/
game.js
diff --git
a/public/javascripts/components/game.js
b/public/javascripts/components/game.js
index
ef38559
..
fb4564f
100644
(file)
--- a/
public/javascripts/components/game.js
+++ b/
public/javascripts/components/game.js
@@
-10,8
+10,8
@@
Vue.component('my-game', {
// fen: to start from a FEN without identifiers (analyze mode)
// subMode: "auto" (game comp vs comp) or "corr" (correspondance game),
// or "examine" (after human game: TODO)
// fen: to start from a FEN without identifiers (analyze mode)
// subMode: "auto" (game comp vs comp) or "corr" (correspondance game),
// or "examine" (after human game: TODO)
- props: ["conn","game
Id","fen","mode","subMode","allowChat","allowMovelist
",
- "
queryHash
","settings"],
+ props: ["conn","game
Ref","fen","mode","subMode
",
+ "
allowChat","allowMovelist
","settings"],
data: function() {
return {
// Web worker to play computer moves without freezing interface:
data: function() {
return {
// Web worker to play computer moves without freezing interface:
@@
-35,18
+35,13
@@
Vue.component('my-game', {
};
},
watch: {
};
},
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");
// (Security) No effect if a computer move is in progress:
if (this.mode == "computer" && this.lockCompThink)
return this.$emit("computer-think");
- this.newGameFromFen(
newFen
);
+ this.newGameFromFen();
},
},
- gameId: function() {
- this.loadGame();
- },
- queryHash: function(newQhash) {
- // New query hash = "id=42"; get 42 as gameId
- this.gameId = parseInt(newQhash.substr(2));
+ gameRef: function() {
this.loadGame();
},
},
this.loadGame();
},
},
@@
-121,19
+116,21
@@
Vue.component('my-game', {
</div>
`,
created: function() {
</div>
`,
created: function() {
- if (!!this.game
Id
)
+ if (!!this.game
Ref
)
this.loadGame();
else if (!!this.fen)
{
this.loadGame();
else if (!!this.fen)
{
- this.vr = new V
ariantRules
(this.fen);
+ this.vr = new V(this.fen);
this.fenStart = this.fen;
}
// TODO: if I'm one of the players in game, then:
// Send ping to server (answer pong if opponent is connected)
this.fenStart = this.fen;
}
// TODO: if I'm one of the players in game, then:
// Send ping to server (answer pong if opponent is connected)
- if (true && !!this.conn)
+ if (true && !!this.conn
&& !!this.gameRef
)
{
{
- this.conn.send(JSON.stringify({
- code:"ping",oppid:this.oppid,gameId:this.gameId}));
+ this.conn.onopen = () => {
+ this.conn.send(JSON.stringify({
+ code:"ping",oppid:this.oppid,gameId:this.gameRef.id}));
+ };
}
// TODO: also handle "draw accepted" (use opponents array?)
// --> must give this info also when sending lastState...
}
// TODO: also handle "draw accepted" (use opponents array?)
// --> must give this info also when sending lastState...
@@
-147,7
+144,7
@@
Vue.component('my-game', {
this.play(data.move, variant.name!="Dark" ? "animate" : null);
break;
case "pong": //received if we sent a ping (game still alive on our side)
this.play(data.move, variant.name!="Dark" ? "animate" : null);
break;
case "pong": //received if we sent a ping (game still alive on our side)
- if (this.game
I
d != data.gameId)
+ if (this.game
Ref.i
d != data.gameId)
break; //games IDs don't match: definitely over...
this.oppConnected = true;
// Send our "last state" informations to opponent(s)
break; //games IDs don't match: definitely over...
this.oppConnected = true;
// Send our "last state" informations to opponent(s)
@@
-156,7
+153,7
@@
Vue.component('my-game', {
this.conn.send(JSON.stringify({
code: "lastate",
oppid: oid,
this.conn.send(JSON.stringify({
code: "lastate",
oppid: oid,
- gameId: this.game
I
d,
+ gameId: this.game
Ref.i
d,
lastMove: (L>0?this.vr.moves[L-1]:undefined),
movesCount: L,
}));
lastMove: (L>0?this.vr.moves[L-1]:undefined),
movesCount: L,
}));
@@
-165,7
+162,7
@@
Vue.component('my-game', {
// TODO: refactor this, because at 3 or 4 players we may have missed 2 or 3 moves (not just one)
case "lastate": //got opponent infos about last move
L = this.vr.moves.length;
// TODO: refactor this, because at 3 or 4 players we may have missed 2 or 3 moves (not just one)
case "lastate": //got opponent infos about last move
L = this.vr.moves.length;
- if (this.game
I
d != data.gameId)
+ if (this.game
Ref.i
d != data.gameId)
break; //games IDs don't match: nothing we can do...
// OK, opponent still in game (which might be over)
if (this.score != "*")
break; //games IDs don't match: nothing we can do...
// OK, opponent still in game (which might be over)
if (this.score != "*")
@@
-174,7
+171,7
@@
Vue.component('my-game', {
this.conn.send(JSON.stringify({
code: "lastate",
oppid: data.oppid,
this.conn.send(JSON.stringify({
code: "lastate",
oppid: data.oppid,
- gameId: this.game
I
d,
+ gameId: this.game
Ref.i
d,
score: this.score,
}));
}
score: this.score,
}));
}
@@
-186,7
+183,7
@@
Vue.component('my-game', {
this.conn.send(JSON.stringify({
code: "lastate",
oppid: this.opponent.id,
this.conn.send(JSON.stringify({
code: "lastate",
oppid: this.opponent.id,
- gameId: this.game
I
d,
+ gameId: this.game
Ref.i
d,
lastMove: this.vr.moves[L-1],
movesCount: L,
}));
lastMove: this.vr.moves[L-1],
movesCount: L,
}));
@@
-298,22
+295,22
@@
Vue.component('my-game', {
this.endGame(this.mycolor=="w"?"0-1":"1-0");
},
translate: translate,
this.endGame(this.mycolor=="w"?"0-1":"1-0");
},
translate: translate,
- newGameFromFen: function(
fen
) {
- this.vr = new V
ariantRules(
fen);
+ newGameFromFen: function() {
+ this.vr = new V
(this.
fen);
this.moves = [];
this.cursor = -1;
this.moves = [];
this.cursor = -1;
- this.fenStart =
newF
en;
+ this.fenStart =
this.f
en;
this.score = "*";
if (this.mode == "analyze")
{
this.score = "*";
if (this.mode == "analyze")
{
- this.mycolor = V.ParseFen(
newF
en).turn;
+ this.mycolor = V.ParseFen(
this.f
en).turn;
this.orientation = this.mycolor;
}
else if (this.mode == "computer") //only other alternative (HH with gameId)
{
this.mycolor = (Math.random() < 0.5 ? "w" : "b");
this.orientation = this.mycolor;
this.orientation = this.mycolor;
}
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",
newF
en]);
+ this.compWorker.postMessage(["init",
this.f
en]);
if (this.mycolor != "w" || this.subMode == "auto")
this.playComputerMove();
}
if (this.mycolor != "w" || this.subMode == "auto")
this.playComputerMove();
}
@@
-322,7
+319,7
@@
Vue.component('my-game', {
// TODO: ask game to remote peer if this.remoteId is set
// (or just if game not found locally)
// NOTE: if it's a corr game, ask it from server
// TODO: ask game to remote peer if this.remoteId is set
// (or just if game not found locally)
// NOTE: if it's a corr game, ask it from server
- const game = getGameFromStorage(this.game
Id);
+ const game = getGameFromStorage(this.game
Ref.id, this.gameRef.uid); //uid may be blank
this.opponent.id = game.oppid; //opponent ID in case of running HH game
this.opponent.name = game.oppname; //maye be blank (if anonymous)
this.score = game.score;
this.opponent.id = game.oppid; //opponent ID in case of running HH game
this.opponent.name = game.oppname; //maye be blank (if anonymous)
this.score = game.score;
@@
-493,7
+490,7
@@
Vue.component('my-game', {
if (this.cursor == this.moves.length)
this.moves.push(move);
else
if (this.cursor == this.moves.length)
this.moves.push(move);
else
- this.moves = this.moves.slice(0,this.cursor
-1
).concat([move]);
+ this.moves = this.moves.slice(0,this.cursor).concat([move]);
}
// Is opponent in check?
this.incheck = this.vr.getCheckSquares(this.vr.turn);
}
// Is opponent in check?
this.incheck = this.vr.getCheckSquares(this.vr.turn);
@@
-535,12
+532,12
@@
Vue.component('my-game', {
this.moves.pop();
},
gotoMove: function(index) {
this.moves.pop();
},
gotoMove: function(index) {
- this.vr = new V
ariantRules
(this.moves[index].fen);
+ this.vr = new V(this.moves[index].fen);
this.cursor = index;
this.lastMove = this.moves[index];
},
gotoBegin: function() {
this.cursor = index;
this.lastMove = this.moves[index];
},
gotoBegin: function() {
- this.vr = new V
ariantRules
(this.fenStart);
+ this.vr = new V(this.fenStart);
this.cursor = -1;
this.lastMove = null;
},
this.cursor = -1;
this.lastMove = null;
},