From beda3dd096a455ed337eaaeadc400712bf0f5c6d Mon Sep 17 00:00:00 2001
From: Benjamin Auder <benjamin.auder@somewhere>
Date: Wed, 10 Jun 2020 20:17:50 +0200
Subject: [PATCH] Add some TODOs for simultaneous games support

---
 client/src/components/ChallengeList.vue | 10 ++++-
 client/src/translations/variants/en.pug |  1 +
 client/src/translations/variants/es.pug |  1 +
 client/src/translations/variants/fr.pug |  1 +
 client/src/views/Game.vue               |  3 ++
 client/src/views/Hall.vue               | 54 +++++++++++++++++--------
 6 files changed, 52 insertions(+), 18 deletions(-)

diff --git a/client/src/components/ChallengeList.vue b/client/src/components/ChallengeList.vue
index 1107b58c..5c582631 100644
--- a/client/src/components/ChallengeList.vue
+++ b/client/src/components/ChallengeList.vue
@@ -15,7 +15,7 @@ div
       )
         td {{ c.vname }}
         td {{ withWho(c) }}
-        td {{ c.cadence }}
+        td(:class="getCadenceClass(c)") {{ c.cadence }}
         td(:class="getRandomnessClass(c)")
   p(v-else)
     | {{ st.tr["No challenges found :( Click on 'New game'!"] }}
@@ -66,6 +66,11 @@ export default {
       return {
         ["random-" + c.randomness]: true
       };
+    },
+    getCadenceClass: function(c) {
+      return {
+        "simultaneous": c.cadence.indexOf("/") >= 0
+      };
     }
   }
 };
@@ -82,6 +87,9 @@ tr.fromyou > td
 tr.toyou > td
   background-color: #fcd785
 
+td.simultaneous
+  background-color: purple
+
 tr > td:last-child
   &.random-0
     background-color: #FF5733
diff --git a/client/src/translations/variants/en.pug b/client/src/translations/variants/en.pug
index 29c4a898..67227c79 100644
--- a/client/src/translations/variants/en.pug
+++ b/client/src/translations/variants/en.pug
@@ -115,6 +115,7 @@ p.
     "Grand",
     "Grasshopper",
     "Omega",
+    "Ordamirror",
     "Perfect",
     "Schess",
     "Shako",
diff --git a/client/src/translations/variants/es.pug b/client/src/translations/variants/es.pug
index b6939cc7..a373000d 100644
--- a/client/src/translations/variants/es.pug
+++ b/client/src/translations/variants/es.pug
@@ -122,6 +122,7 @@ p.
     "Grand",
     "Grasshopper",
     "Omega",
+    "Ordamirror",
     "Perfect",
     "Schess",
     "Shako",
diff --git a/client/src/translations/variants/fr.pug b/client/src/translations/variants/fr.pug
index d108dcd1..72e481ae 100644
--- a/client/src/translations/variants/fr.pug
+++ b/client/src/translations/variants/fr.pug
@@ -121,6 +121,7 @@ p.
     "Grand",
     "Grasshopper",
     "Omega",
+    "Ordamirror",
     "Perfect",
     "Schess",
     "Shako",
diff --git a/client/src/views/Game.vue b/client/src/views/Game.vue
index fa7ab3b2..d702b0ec 100644
--- a/client/src/views/Game.vue
+++ b/client/src/views/Game.vue
@@ -179,6 +179,9 @@ main
 </template>
 
 <script>
+// TODO: this will be a component instead ?
+// If simultaneous games, no "rematch" button
+
 import BaseGame from "@/components/BaseGame.vue";
 import UserBio from "@/components/UserBio.vue";
 import Chat from "@/components/Chat.vue";
diff --git a/client/src/views/Hall.vue b/client/src/views/Hall.vue
index 4be708d2..0e4d574b 100644
--- a/client/src/views/Hall.vue
+++ b/client/src/views/Hall.vue
@@ -857,6 +857,10 @@ export default {
           }
           break;
         }
+        case "entersimul":
+          // TODO: confirm box accept/refuse.
+          // If accept, update seat (array in this case)
+          break;
         case "game": // Individual request
         case "newgame": {
           const game = data.data;
@@ -1221,24 +1225,33 @@ export default {
           alert(this.st.tr["Please log in to accept corr challenges"]);
           return;
         }
-        c.accepted = true;
-        await import("@/variants/" + c.vname + ".js")
-        .then((vModule) => {
-          window.V = vModule[c.vname + "Rules"];
-          if (!!c.to) {
-            // c.to == this.st.user.name (connected)
-            if (!!c.fen) {
-              const parsedFen = V.ParseFen(c.fen);
-              this.tchallDiag = getDiagram({
-                position: parsedFen.position,
-                orientation: parsedFen.turn
-              });
+        if (c.type == "simul") {
+          // Just notify that I wanna enter the simultaneous game(s)
+          // TODO: dans défi, indiquer si positions aleatoires, si tjours blancs ou noirs
+          // --> /w30 ou b1h ou juste 30 (random, sans préfixe).
+          // => message "entersimul" to c.from
+          return;
+        }
+        else {
+          c.accepted = true;
+          await import("@/variants/" + c.vname + ".js")
+          .then((vModule) => {
+            window.V = vModule[c.vname + "Rules"];
+            if (!!c.to) {
+              // c.to == this.st.user.name (connected)
+              if (!!c.fen) {
+                const parsedFen = V.ParseFen(c.fen);
+                this.tchallDiag = getDiagram({
+                  position: parsedFen.position,
+                  orientation: parsedFen.turn
+                });
+              }
+              this.curChallToAccept = c;
+              document.getElementById("modalAccept").checked = true;
             }
-            this.curChallToAccept = c;
-            document.getElementById("modalAccept").checked = true;
-          }
-          else this.finishProcessingChallenge(c);
-        });
+            else this.finishProcessingChallenge(c);
+          });
+        }
       }
       else {
         // My challenge
@@ -1249,12 +1262,19 @@ export default {
             { data: { id: c.id } }
           );
         }
+        else if (c.type == "simul" && !!c.seat && Array.isArray(c.seat))
+          // TODO: if some players entered, start game
+          this.launchSimultaneous(c);
         this.send("deletechallenge_s", { data: { cid: c.id } });
       }
       // In all cases, the challenge is consumed:
       ArrayFun.remove(this.challenges, ch => ch.id == c.id);
     },
     // NOTE: when launching game, the challenge is already being deleted
+    // TODO: adapt for simultaneous games, or just write a new function (better)
+    launchSimultaneous: function(c) {
+      // TODO
+    },
     launchGame: function(c) {
       // White player index 0, black player index 1:
       let players =
-- 
2.44.0