X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=public%2Fjavascripts%2Fcomponents%2Fgame.js;h=555d3924b2d18cbd66e943deb29a574dcf5a8ece;hb=81bc1102368a5a8b9358f58b77c241f82f3c2c4b;hp=39c12c0e283513bf622fe6d3bbba2e235e09ce3e;hpb=2305d34a3f2ab561c20b1fcb7349320145ac1f5c;p=vchess.git diff --git a/public/javascripts/components/game.js b/public/javascripts/components/game.js index 39c12c0e..555d3924 100644 --- a/public/javascripts/components/game.js +++ b/public/javascripts/components/game.js @@ -4,7 +4,8 @@ // Game logic on a variant page: 3 modes, analyze, computer or human Vue.component('my-game', { // gameId: to find the game in storage (assumption: it exists) - props: ["gameId","mode","allowChat","allowMovelist"], + // fen: to start from a FEN without identifiers (analyze mode) + props: ["gameId","fen","mode","allowChat","allowMovelist"], data: function() { return { // if oppid == "computer" then mode = "computer" (otherwise human) @@ -22,8 +23,20 @@ Vue.component('my-game', { compWorker: new Worker('/javascripts/playCompMove.js'), timeStart: undefined, //time when computer starts thinking vr: null, //VariantRules object, describing the game state + rules + + // orientation :: button flip + // userColor: given by gameId, or fen (if no game Id) + // gameOver: known if gameId; otherwise assue false + // lastMove: update after every play, initialize with last move from list (if continuation) + //orientation ? userColor ? gameOver ? lastMove ? + }; }, + watch: { + fen: function(newFen) { + this.vr = new VariantRules(newFen); + }, + }, computed: { showChat: function() { return this.allowChat && this.mode=='human' && this.score != '*'; @@ -77,7 +90,9 @@ Vue.component('my-game', { `, created: function() { const url = socketUrl; - this.conn = new WebSocket(url + "/?sid=" + this.myid + "&page=" + variant._id); + +// TODO: connexion initialized in variant.js and passed as a prop + // TODO: after game, archive in indexedDB // TODO: this events listener is central. Refactor ? How ? const socketMessageListener = msg => { @@ -152,7 +167,6 @@ Vue.component('my-game', { }; const socketCloseListener = () => { - this.conn = new WebSocket(url + "/?sid=" + this.myid + "&page=" + variant._id); this.conn.addEventListener('message', socketMessageListener); this.conn.addEventListener('close', socketCloseListener); };