X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fviews%2FHall.vue;h=6cc58e978f5c301d2e289508931bd66e5a9d11b7;hb=8477e53d8e78606e4c4e4bf91c77b1011aab583c;hp=1b8681fd8e291ebcb79c2d2c9994b7409c66006c;hpb=26f70eee84024ee170c6142e62fa08b1616ef6e3;p=vchess.git diff --git a/client/src/views/Hall.vue b/client/src/views/Hall.vue index 1b8681fd..6cc58e97 100644 --- a/client/src/views/Hall.vue +++ b/client/src/views/Hall.vue @@ -28,9 +28,9 @@ main fieldset label(for="cadence") {{ st.tr["Cadence"] }} * div#predefinedCadences - button 3+2 - button 5+3 - button 15+5 + button(type="button") 3+2 + button(type="button") 5+3 + button(type="button") 15+5 input#cadence( type="text" v-model="newchallenge.cadence" @@ -67,7 +67,7 @@ main ) span {{ people[sid].name }} button.player-action( - v-if="sid!=st.user.sid || isGamer(sid)" + v-if="isGamer(sid) || (st.user.id > 0 && sid!=st.user.sid)" @click="challOrWatch(sid)" ) | {{ getActionLabel(sid) }} @@ -83,7 +83,7 @@ main .col-sm-12.col-md-10.col-md-offset-1.col-lg-8.col-lg-offset-2 .button-group button#peopleBtn(onClick="window.doClick('modalPeople')") - | {{ st.tr["Social"] }} + | {{ st.tr["Who's there?"] }} button(onClick="window.doClick('modalNewgame')") | {{ st.tr["New game"] }} .row @@ -275,8 +275,11 @@ export default { this.newchallenge.cadence = b.innerHTML; }); }); - const showCtype = localStorage.getItem("type-challenges") || "live"; - const showGtype = localStorage.getItem("type-games") || "live"; + const dispCorr = this.$route.query["disp"]; + const showCtype = + dispCorr || localStorage.getItem("type-challenges") || "live"; + const showGtype = + dispCorr || localStorage.getItem("type-games") || "live"; this.setDisplay("c", showCtype); this.setDisplay("g", showGtype); }, @@ -624,11 +627,24 @@ export default { }, // Challenge lifecycle: newChallenge: async function() { + if (this.newchallenge.cadence.match(/^[0-9]+$/)) + this.newchallenge.cadence += "+0"; //assume minutes, no increment + const ctype = this.classifyObject(this.newchallenge); + // TODO: cadence still unchecked so ctype could be wrong... let error = ""; - if (this.newchallenge.vid == "") + if (!this.newchallenge.vid) error = this.st.tr["Please select a variant"]; - else if (!!this.newchallenge.to && this.newchallenge.to == this.st.user.name) - error = this.st.tr["Self-challenge is forbidden"]; + else if (ctype == "corr" && this.st.user.id <= 0) + error = this.st.tr["Please log in to play correspondance games"]; + else if (this.newchallenge.to) { + if (this.newchallenge.to == this.st.user.name) + error = this.st.tr["Self-challenge is forbidden"]; + else if ( + ctype == "live" && + Object.values(this.people).every(p => p.name != this.newchallenge.to) + ) + error = this.newchallenge.to + " " + this.st.tr["is not online"]; + } if (error) { alert(error); return; @@ -636,12 +652,7 @@ export default { const vname = this.getVname(this.newchallenge.vid); const vModule = await import("@/variants/" + vname + ".js"); window.V = vModule.VariantRules; - if (this.newchallenge.cadence.match(/^[0-9]+$/)) - this.newchallenge.cadence += "+0"; //assume minutes, no increment - const ctype = this.classifyObject(this.newchallenge); error = checkChallenge(this.newchallenge); - if (!error && ctype == "corr" && this.st.user.id <= 0) - error = this.st.tr["Please log in to play correspondance games"]; if (error) { alert(error); return; @@ -786,10 +797,14 @@ export default { initime: [0, 0], //initialized later score: "*" }); - GameStorage.add(game); - if (this.st.settings.sound >= 1) - new Audio("/sounds/newgame.mp3").play().catch(() => {}); - this.$router.push("/game/" + gameInfo.id); + GameStorage.add(game, (err) => { + // If an error occurred, game is not added: abort + if (!err) { + if (this.st.settings.sound >= 1) + new Audio("/sounds/newgame.mp3").play().catch(() => {}); + this.$router.push("/game/" + gameInfo.id); + } + }); } } };