X-Git-Url: https://git.auder.net/?a=blobdiff_plain;ds=sidebyside;f=public%2Fjavascripts%2Fcomponents%2Fcorrespondance.js;h=7dbde1570511098da2286d1dc8b3ce8dbbe79187;hb=b955c65b942d09d24b5c3bed0d755d4f2f8f71f1;hp=87de3eb8af1d9383b2e33cd999c36d1c6e72025b;hpb=00f2759e16ec73fa1ecd0254a9c9018530d71892;p=vchess.git
diff --git a/public/javascripts/components/correspondance.js b/public/javascripts/components/correspondance.js
index 87de3eb8..7dbde157 100644
--- a/public/javascripts/components/correspondance.js
+++ b/public/javascripts/components/correspondance.js
@@ -1,11 +1,161 @@
Vue.component("my-correspondance", {
+ data: function() {
+ return {
+ userId: user.id,
+ games: [],
+ challenges: [],
+ willPlay: [], //IDs of challenges in which I decide to play (>= 3 players)
+ newgameInfo: {
+ fen: "",
+ vid: 0,
+ nbPlayers: 0,
+ players: [{id:0,name:""},{id:0,name:""},{id:0,name:""}],
+ mainTime: 0,
+ increment: 0,
+ },
+ };
+ },
template: `
-
TODO: load from server, show timeControl + players + link "play"
-
Also tab for current challenges + button "new game"
+
+
+
+ Correspondance play is reserved to registered users
+
+
+
+
+
+
+
+
`,
+ computed: {
+ // TODO: this is very artificial...
+ variants: function() {
+ return variantArray;
+ },
+ },
created: function() {
- //TODO
+ // use user.id to load challenges + games from server
+ },
+ methods: {
+ translate: translate,
+ clickChallenge: function() {
+ // TODO: accepter un challenge peut lancer une partie, il
+ // faut alors supprimer challenge + creer partie + la retourner et l'ajouter ici
+ // autres actions:
+ // supprime mon défi
+ // accepte un défi
+ // annule l'acceptation d'un défi (si >= 3 joueurs)
+ //
+ // si pas le mien et FEN speciale :: (charger code variante et)
+ // montrer diagramme + couleur (orienté)
+ },
+ showGame: function(g) {
+ // Redirect to /variant#game?id=...
+ location.href="/variant#game?id=" + g.id;
+ },
+ newGame: function() {
+ 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);
+ return NbPlayers[variantArray[idxInVariants].name].includes(nbp);
+ },
},
});