import NoSleep from "nosleep.js"; export default { name: "HomePage", components: {}, data() { return { voices: null, diaNomi: { show: false, home: "", guest: "", }, visuForm: false, visuButt: true, visuStriscia: true, sp: { striscia: { home: [0], guest: [0] }, servHome: true, punt: { home: 0, guest: 0 }, set: { home: 0, guest: 0 }, nomi: { home: "Antoniana", guest: "Guest" }, form: { home: ["1", "2", "3", "4", "5", "6"], guest: ["1", "2", "3", "4", "5", "6"], }, }, } }, mounted() { this.voices = window.speechSynthesis.getVoices(); if (this.isMobile()) { this.speak(); var noSleep = new NoSleep(); noSleep.enable(); document.documentElement.requestFullscreen(); } this.abilitaTastiSpeciali(); }, methods: { closeApp() { var win = window.open("", "_self"); win.close(); }, fullScreen() { document.documentElement.requestFullscreen(); }, isMobile() { if ( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test( navigator.userAgent ) ) { return true; } else { return false; } }, resetta() { this.$waveui.notify("Punteggio
RESETTATO", "success"); this.visuForm = false; this.sp.punt.home = 0; this.sp.punt.guest = 0; this.sp.form = { home: ["1", "2", "3", "4", "5", "6"], guest: ["1", "2", "3", "4", "5", "6"], } this.sp.striscia = { home: [0], guest: [0] } }, incSet(team) { if (this.sp.set[team] == 2) { this.sp.set[team] = 0; } else { this.sp.set[team]++; } }, incPunt(team) { this.sp.punt[team]++; if (team == 'home') { this.sp.striscia.home.push(this.sp.punt.home) this.sp.striscia.guest.push(' ') } else { this.sp.striscia.guest.push(this.sp.punt.guest) this.sp.striscia.home.push(' ') } this.sp.servHome = (team == "home"); this.sp.form[team].push(this.sp.form[team].shift()); }, decPunt() { if (this.sp.striscia.home.length > 1) { var tmpHome = this.sp.striscia.home.pop() var tmpGuest = this.sp.striscia.guest.pop() if (tmpHome == ' ') { this.sp.punt.guest-- this.sp.form.guest.unshift(this.sp.form.guest.pop()); } else { this.sp.punt.home-- this.sp.form.home.unshift(this.sp.form.home.pop()); } } }, // decPunt(team) { // // decrementa il punteggio se รจ > 0. // if (this.sp.punt[team] > 0) { // this.sp.punt[team]--; // this.sp.striscia.home.pop() // this.sp.striscia.guest.pop() // this.sp.form[team].unshift(this.sp.form[team].pop()); // } // }, speak() { const msg = new SpeechSynthesisUtterance(); if (this.sp.punt.home + this.sp.punt.guest == 0) { msg.text = "zero a zero"; } else if (this.sp.punt.home == this.sp.punt.guest) { msg.text = this.sp.punt.home + " pari"; } else { if (this.sp.servHome) { msg.text = this.sp.punt.home + " a " + this.sp.punt.guest; } else { msg.text = this.sp.punt.guest + " a " + this.sp.punt.home; } } // msg.volume = 1.0; // speech volume (default: 1.0) // msg.pitch = 1.0; // speech pitch (default: 1.0) // msg.rate = 1.0; // speech rate (default: 1.0) // msg.lang = 'it_IT'; // speech language (default: 'en-US') const voices = window.speechSynthesis.getVoices(); msg.voice = voices.find(voice => voice.name === 'Google italiano'); // voice URI (default: platform-dependent) // msg.onboundary = function (event) { // console.log('Speech reached a boundary:', event.name); // }; // msg.onpause = function (event) { // console.log('Speech paused:', event.utterance.text.substring(event.charIndex)); // }; window.speechSynthesis.speak(msg); }, apriDialogConfig() { this.disabilitaTastiSpeciali(); this.diaNomi.show = true; }, disabilitaTastiSpeciali() { window.removeEventListener("keydown", this.funzioneTastiSpeciali); }, abilitaTastiSpeciali() { window.addEventListener("keydown", this.funzioneTastiSpeciali); }, funzioneTastiSpeciali(e) { e.preventDefault(); if (e.ctrlKey && e.key == "m") { this.diaNomi.show = true } else if (e.ctrlKey && e.key == "b") { this.visuButt = !this.visuButt } else if (e.ctrlKey && e.key == "f") { document.documentElement.requestFullscreen(); } else if (e.ctrlKey && e.key == "s") { this.speak(); } else if (e.ctrlKey && e.key == "z") { this.visuForm = !this.visuForm } else if (e.ctrlKey && e.key == "ArrowUp") { this.incPunt("home") } else if (e.ctrlKey && e.key == "ArrowDown") { this.decPunt("home") } else if (e.ctrlKey && e.key == "ArrowRight") { this.incSet("home") } else if (e.shiftKey && e.key == "ArrowUp") { this.incPunt("guest") } else if (e.shiftKey && e.key == "ArrowDown") { this.decPunt("guest") } else if (e.shiftKey && e.key == "ArrowRight") { this.incSet("guest") } else if (e.ctrlKey && e.key == "ArrowLeft") { this.sp.servHome = !this.sp.servHome } else { return false } } } }