{{ vr.getFen() }} @@ -99,9 +105,12 @@ Vue.component('my-game', {
X-Git-Url: https://git.auder.net/assets/current/gitweb.js?a=blobdiff_plain;f=public%2Fjavascripts%2Fcomponents%2Fgame.js;h=d0d8125833d607dc25ffb1efd2226e62e0721036;hb=a6403027a66411ead248aab0369bf3ee3a75d8ec;hp=4048a3d404190ecdf93d6b9743dba9d8cac243b6;hpb=7d9e99bc177972c5af8b1b45f4bfb043d8306f30;p=vchess.git diff --git a/public/javascripts/components/game.js b/public/javascripts/components/game.js index 4048a3d4..d0d81258 100644 --- a/public/javascripts/components/game.js +++ b/public/javascripts/components/game.js @@ -1,48 +1,50 @@ -// TODO: envoyer juste "light move", sans FEN ni notation ...etc -// TODO: also "observers" prop, 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 ? Vue.component('my-game', { // gameId: to find the game in storage (assumption: it exists) // fen: to start from a FEN without identifiers (analyze mode) - props: ["conn","gameId","fen","mode","allowChat","allowMovelist"], + // subMode: "auto" (game comp vs comp) or "corr" (correspondance game), + // or "examine" (after human game: TODO) + props: ["conn","gameId","fen","mode","subMode","allowChat","allowMovelist", + "queryHash","settings"], data: function() { return { - // if oppid == "computer" then mode = "computer" (otherwise human) - myid: "", //our ID, always set - //this.myid = localStorage.getItem("myid") - oppid: "", //opponent ID in case of HH game - score: "*", //'*' means 'unfinished' - mycolor: "w", - oppConnected: false, //TODO? - pgnTxt: "", - // sound level: 0 = no sound, 1 = sound only on newgame, 2 = always - sound: parseInt(localStorage["sound"] || "2"), // Web worker to play computer moves without freezing interface: compWorker: new Worker('/javascripts/playCompMove.js'), timeStart: undefined, //time when computer starts thinking vr: null, //VariantRules object, describing the game state + rules endgameMessage: "", orientation: "w", + lockCompThink: false, //used to avoid some ghost moves + 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", fenStart: "", - moves: [], //TODO: initialize if gameId is defined... - cursor: 0, - // 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 ? - + cursor: -1, //index of the move just played + lastMove: null, }; }, watch: { fen: function(newFen) { - this.vr = new VariantRules(newFen); + // (Security) No effect if a computer move is in progress: + if (this.mode == "computer" && this.lockCompThink) + return this.$emit("computer-think"); + this.newGameFromFen(newFen); }, gameId: function() { this.loadGame(); }, + queryHash: function(newQhash) { + // New query hash = "id=42"; get 42 as gameId + this.gameId = parseInt(newQhash.substr(2)); + this.loadGame(); + }, }, computed: { showChat: function() { @@ -57,17 +59,6 @@ Vue.component('my-game', { }, }, // Modal end of game, and then sub-components - // TODO: provide chat parameters (connection, players ID...) - // and also moveList parameters (just moves ?) - // TODO: connection + turn indicators en haut à droite (superposé au menu) - // TODO: controls: abort, clear, resign, draw (avec confirm box) - // et si partie terminée : (mode analyse) just clear, back / play - // + flip button toujours disponible - // gotoMove : vr = new VariantRules(fen stocké dans le coup [TODO]) - - // NOTE: move.color must be fulfilled after each move played, because of Marseille (or Avalanche) chess - // --> useful in moveList component (universal comma separator ?) - template: `
{{ vr.getFen() }} @@ -99,9 +105,12 @@ Vue.component('my-game', {