</template>
<script>
-import Board from "@/components/Board.vue";
+import BaseGame from "@/components/BaseGame.vue";
//import Chat from "@/components/Chat.vue";
//import MoveList from "@/components/MoveList.vue";
import { store } from "@/store";
////////////
gameRef: {id: "", rid: ""}, //given in URL (rid = remote ID, if applicable)
mode: "live", //or "corr"
- variant: {}, //filled when game is retrieved
+ vname: "", //filled when game is retrieved
drawOfferSent: false, //did I just ask for draw?
players: [], //filled later (2 to 4 players)
people: [], //potential observers
'$route' (to, from) {
this.gameRef.id = to.params["id"];
this.gameRef.rid = to.query["rid"];
- this.launchGame();
+ this.loadGame();
},
},
created: function() {
{
this.gameRef.id = this.$route.params["id"];
this.gameRef.rid = this.$route.query["rid"];
- this.launchGame();
+ this.loadGame();
}
// Poll all players except me (if I'm playing) to know online status.
// --> Send ping to server (answer pong if players[s] are connected)
// TODO: observer on dark games must see all board ? Or alternate ? (seems better)
// ...or just see nothing as on buho21
this.$refs["baseGame"].play(
- data.move, this.variant.name!="Dark" ? "animate" : null);
+ data.move, this.vname!="Dark" ? "animate" : null);
break;
case "pong": //received if we sent a ping (game still alive on our side)
if (this.gameRef.id != data.gameId)
}
this.endGame(this.mycolor=="w"?"0-1":"1-0");
},
- launchGame: async function() {
- const vModule = await import("@/variants/" + this.variant.name + ".js");
- window.V = vModule.VariantRules;
- this.loadGame(this.gid);
- },
- loadGame: function(gid) {
- // 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(gid); //, 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)
+ // 4 cases for loading a game:
+ // - from localStorage (one running game I play)
+ // - from indexedDB (one completed live game)
+ // - from server (one correspondance game I play[ed] or not)
+ // - from remote peer (one live game I don't play, finished or not)
+ loadGame: async function() {
+ const game = getGameFromStorage(this.gameRef);
+ this.players = game.players;
this.score = game.score;
- this.mycolor = game.mycolor;
+ this.mycolor = game.mycolor; //may be irrelevant (if I don't play it)
this.fenStart = game.fenStart;
this.moves = game.moves;
this.cursor = game.moves.length-1;
this.lastMove = (game.moves.length > 0 ? game.moves[this.cursor] : null);
- // TODO: fill players array
+ const vModule = await import("@/variants/" + game.vname + ".js");
+ window.V = vModule.VariantRules;
},
oppConnected: function(uid) {
- return this.opponents.any(o => o.id == uidi && o.online);
+ return this.opponents.some(o => o.id == uid && o.online);
},
},
};