diff --git a/src/components/HomePage/HomePage.js b/src/components/HomePage/HomePage.js index 0741da9..5ebbe12 100644 --- a/src/components/HomePage/HomePage.js +++ b/src/components/HomePage/HomePage.js @@ -24,7 +24,7 @@ export default { home: ["1", "2", "3", "4", "5", "6"], guest: ["1", "2", "3", "4", "5", "6"], }, - servizioPrecedente: [], // Stack per tracciare i cambi palla + storicoServizio: [], // Stack per tracciare lo stato del servizio prima di ogni punto }, } }, @@ -72,7 +72,7 @@ export default { guest: ["1", "2", "3", "4", "5", "6"], } this.sp.striscia = { home: [0], guest: [0] } - this.sp.servizioPrecedente = [] + this.sp.storicoServizio = [] }, cambiaPalla() { if (!this.isPunteggioZeroZero) { @@ -95,6 +95,12 @@ export default { return; } + // Salva lo stato del servizio PRIMA di modificarlo + this.sp.storicoServizio.push({ + servHome: this.sp.servHome, + cambioPalla: (team == "home" && !this.sp.servHome) || (team == "guest" && this.sp.servHome) + }); + this.sp.punt[team]++; if (team == 'home') { this.sp.striscia.home.push(this.sp.punt.home) @@ -106,7 +112,6 @@ export default { // 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()); @@ -136,24 +141,27 @@ export default { return false; }, decPunt() { - if (this.sp.striscia.home.length > 1) { + if (this.sp.striscia.home.length > 1 && this.sp.storicoServizio.length > 0) { 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 + var statoServizio = this.sp.storicoServizio.pop() // Recupera lo stato completo del servizio if (tmpHome == ' ') { this.sp.punt.guest-- // Ruota indietro solo se c'era stato un cambio palla - if (cambioPalla) { + if (statoServizio.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) { + if (statoServizio.cambioPalla) { this.sp.form.home.unshift(this.sp.form.home.pop()); } } + + // Ripristina il servizio allo stato precedente + this.sp.servHome = statoServizio.servHome; } }, // decPunt(team) {