X-Git-Url: https://git.auder.net/?p=vchess.git;a=blobdiff_plain;f=public%2Fjavascripts%2Fcomponents%2Fcorrespondance.js;h=7dbde1570511098da2286d1dc8b3ce8dbbe79187;hp=35659c3f33db61d6fbd28dc3505cacdac6abbeae;hb=74ea2e8d9ec6980e2fb5a4f86afe33b4850e3d53;hpb=ab4f4bf258ed68d8292b64d81babde03cddbae3c diff --git a/public/javascripts/components/correspondance.js b/public/javascripts/components/correspondance.js index 35659c3f..7dbde157 100644 --- a/public/javascripts/components/correspondance.js +++ b/public/javascripts/components/correspondance.js @@ -9,7 +9,7 @@ Vue.component("my-correspondance", { fen: "", vid: 0, nbPlayers: 0, - players: ["","",""], + players: [{id:0,name:""},{id:0,name:""},{id:0,name:""}], mainTime: 0, increment: 0, }, @@ -25,11 +25,15 @@ Vue.component("my-correspondance", {
- + - + +
- + + v-model="newgameInfo.players[1].name"/> + v-model="newgameInfo.players[2].name"/>
- +
-

Correspondance play is reserved to registered users

+

+ Correspondance play is reserved to registered users +

- + @@ -97,26 +108,53 @@ Vue.component("my-correspondance", { location.href="/variant#game?id=" + g.id; }, newGame: function() { - // NOTE: side-effect = set FEN - // TODO: (to avoid any cheating option) separate the GenRandInitFen() functions - // in separate files, load on server and generate FEN on server. - const error = checkChallenge(this.newgameInfo); - if (!!error) - return alert(error); - // Possible (server) error if filled player does not exist - ajax( - "/challenges/" + this.newgameInfo.vid, - "POST", - this.newgameInfo, - response => { - this.challenges.push(response.challenge); - } - ); + const afterRulesAreLoaded = () => { + // NOTE: side-effect = set FEN + // TODO: (to avoid any cheating option) separate the GenRandInitFen() functions + // in separate files, load on server and generate FEN on server. + const error = checkChallenge(this.newgameInfo, vname); + if (!!error) + return alert(error); + // Possible (server) error if filled player does not exist + ajax( + "/challenges/" + this.newgameInfo.vid, + "POST", + this.newgameInfo, + response => { + const chall = Object.assign({}, + this.newgameInfo, + { + id: response.cid, + uid: user.id, + added: Date.now(), + vname: vname, + }, + this.challenges.push(response.challengei); + } + ); + }; + const idxInVariants = + variantArray.findIndex(v => v.id == this.newgameInfo.vid); + const vname = variantArray[idxInVariants].name; + const scriptId = vname + "RulesScript"; + if (!document.getElementById(scriptId)) + { + // Load variant rules (only once) + var script = document.createElement("script"); + script.id = scriptId; + script.onload = afterRulesAreLoaded; + //script.addEventListener ("load", afterRulesAreLoaded, false); + script.src = "/javascripts/variants/" + vname + ".js"; + document.body.appendChild(script); + } + else + afterRulesAreLoaded(); }, possibleNbplayers: function(nbp) { if (this.newgameInfo.vid == 0) return false; - const idxInVariants = variantArray.findIndex(v => v.id == this.newgameInfo.vid); + const idxInVariants = + variantArray.findIndex(v => v.id == this.newgameInfo.vid); return NbPlayers[variantArray[idxInVariants].name].includes(nbp); }, },