Simplify navigation
[vchess.git] / public / javascripts / variant.js
index 453656c..74c4298 100644 (file)
@@ -2,27 +2,43 @@ new Vue({
        el: "#VueElement",
        data: {
                display: "undefined", //default to main hall; see "created()" function
-               gameid: "undefined", //...yet
-               
+               gameid: undefined, //...yet
+       
+               conn: null,
+
                // TEMPORARY: DEBUG
-               vr: null,
                mode: "analyze",
                orientation: "w",
                userColor: "w",
-               gameOver: false,
+
+               allowChat: false,
+               allowMovelist: false,
+               fen: V.GenRandInitFen(),
        },
        created: function() {
                // TODO: navigation becomes a little more complex
-               const url = window.location.href;
-               const hashPos = url.indexOf("#");
-               const page = (hashPos >= 0 ? url.substr(hashPos+1) : "room");
-               this.setDisplay(page);
+               this.setDisplay();
+               window.onhashchange = this.setDisplay;
+
+               this.myid = "abcdefghij";
+//console.log(this.myid + " " + variant);
 
-               this.vr = new VariantRules( V.GenRandInitFen() );
+               this.conn = new WebSocket(socketUrl + "/?sid=" + this.myid + "&page=" + variant.id);
+               const socketCloseListener = () => {
+                       this.conn = new WebSocket(socketUrl + "/?sid=" + this.myid + "&page=" + variant.id);
+               }
+               this.conn.onclose = socketCloseListener;
+
+               //this.vr = new VariantRules( V.GenRandInitFen() );
        },
        methods: {
-               setDisplay: function(elt) {
-                       this.display = elt;
+               setDisplay: function() {
+
+//TODO: prevent set display if there is a running game
+
+                       if (!location.hash)
+                               location.hash = "#room"; //default
+                       this.display = location.hash.substr(1);
                        // Close menu on small screens:
                        let menuToggle = document.getElementById("drawer-control");
                        if (!!menuToggle)