X-Git-Url: https://git.auder.net/js/css/rpsls.css?a=blobdiff_plain;f=public%2Fjavascripts%2Fcomponents%2Fcorrespondance.js;h=35659c3f33db61d6fbd28dc3505cacdac6abbeae;hb=ab4f4bf258ed68d8292b64d81babde03cddbae3c;hp=87de3eb8af1d9383b2e33cd999c36d1c6e72025b;hpb=00f2759e16ec73fa1ecd0254a9c9018530d71892;p=vchess.git
diff --git a/public/javascripts/components/correspondance.js b/public/javascripts/components/correspondance.js
index 87de3eb8..35659c3f 100644
--- a/public/javascripts/components/correspondance.js
+++ b/public/javascripts/components/correspondance.js
@@ -1,11 +1,123 @@
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: ["","",""],
+ 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() {
+ // 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);
+ }
+ );
+ },
+ 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);
+ },
},
});