import NoSleep from "nosleep.js"; export default { name: "HomePage", components: {}, data() { return { order: true, 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"], }, servizioPrecedente: [], // Stack per tracciare i cambi palla }, } }, 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] } this.sp.servizioPrecedente = [] }, incSet(team) { if (this.sp.set[team] == 2) { this.sp.set[team] = 0; } else { this.sp.set[team]++; } }, incPunt(team) { // Controlla se c'è già una condizione di vittoria if (this.checkVittoria()) { this.$waveui.notify("Il set è terminato!", "warning"); return; } 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(' ') } // Ruota la formazione solo se c'è cambio palla (conquista del servizio) const cambioPalla = (team == "home" && !this.sp.servHome) || (team == "guest" && this.sp.servHome); this.sp.servizioPrecedente.push(cambioPalla); // Salva se c'è stato cambio palla if (cambioPalla) { this.sp.form[team].push(this.sp.form[team].shift()); } this.sp.servHome = (team == "home"); }, checkVittoria() { const puntHome = this.sp.punt.home; const puntGuest = this.sp.punt.guest; const setHome = this.sp.set.home; const setGuest = this.sp.set.guest; const totSet = setHome + setGuest; // Determina se siamo nel set decisivo (5° set) const isSetDecisivo = totSet >= 4; const punteggioVittoria = isSetDecisivo ? 15 : 25; // Vittoria con punteggio >= 25 (o 15 per set decisivo) e almeno 2 punti di vantaggio if (puntHome >= punteggioVittoria && puntHome - puntGuest >= 2) { return true; // Home ha vinto } if (puntGuest >= punteggioVittoria && puntGuest - puntHome >= 2) { return true; // Guest ha vinto } return false; }, decPunt() { if (this.sp.striscia.home.length > 1) { var tmpHome = this.sp.striscia.home.pop() var tmpGuest = this.sp.striscia.guest.pop() var cambioPalla = this.sp.servizioPrecedente.pop() // Recupera se c'era stato cambio palla if (tmpHome == ' ') { this.sp.punt.guest-- // Ruota indietro solo se c'era stato un cambio palla if (cambioPalla) { this.sp.form.guest.unshift(this.sp.form.guest.pop()); } } else { this.sp.punt.home-- // Ruota indietro solo se c'era stato un cambio palla if (cambioPalla) { 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 } } } }