my-board seems OK. Now TODO: test my-game (with sockets)
[vchess.git] / public / javascripts / variant.js
index 1ec4d89..453656c 100644 (file)
@@ -1,15 +1,24 @@
 new Vue({
        el: "#VueElement",
        data: {
-               display: "room", //default: main hall
+               display: "undefined", //default to main hall; see "created()" function
                gameid: "undefined", //...yet
+               
+               // TEMPORARY: DEBUG
+               vr: null,
+               mode: "analyze",
+               orientation: "w",
+               userColor: "w",
+               gameOver: false,
        },
        created: function() {
                // TODO: navigation becomes a little more complex
                const url = window.location.href;
                const hashPos = url.indexOf("#");
-               if (hashPos >= 0)
-                       this.setDisplay(url.substr(hashPos+1));
+               const page = (hashPos >= 0 ? url.substr(hashPos+1) : "room");
+               this.setDisplay(page);
+
+               this.vr = new VariantRules( V.GenRandInitFen() );
        },
        methods: {
                setDisplay: function(elt) {
@@ -19,6 +28,27 @@ new Vue({
                        if (!!menuToggle)
                                menuToggle.checked = false;
                },
+
+               // TEMPORARY: DEBUG (duplicate code)
+               play: function(move) {
+                       // Not programmatic, or animation is over
+                       if (!move.notation)
+                               move.notation = this.vr.getNotation(move);
+                       this.vr.play(move);
+                       if (!move.fen)
+                               move.fen = this.vr.getFen();
+                       if (this.sound == 2)
+                               new Audio("/sounds/move.mp3").play().catch(err => {});
+                       // Is opponent in check?
+                       this.incheck = this.vr.getCheckSquares(this.vr.turn);
+                       const score = this.vr.getCurrentScore();
+               },
+               undo: function(move) {
+                       this.vr.undo(move);
+                       if (this.sound == 2)
+                               new Audio("/sounds/undo.mp3").play().catch(err => {});
+                       this.incheck = this.vr.getCheckSquares(this.vr.turn);
+               },
        },
 });