refactor(striscia): compatta struttura dati da array a stringa
Sostituisce r: ['home','guest',...] con ris: 'hg...' e i valori serv 'home'/'guest' con 'h'/'g'. Nessun cambiamento funzionale.
This commit is contained in:
+16
-12
@@ -5,7 +5,7 @@ export function createInitialState() {
|
||||
visuStriscia: true,
|
||||
modalitaPartita: "3/5",
|
||||
sp: {
|
||||
striscia: [{ serv: 'home', r: [] }],
|
||||
striscia: [{ serv: 'h', ris: '' }],
|
||||
servHome: true,
|
||||
punt: { home: 0, guest: 0 },
|
||||
set: { home: 0, guest: 0 },
|
||||
@@ -43,7 +43,7 @@ export function applyAction(state, action) {
|
||||
|
||||
const cambioPalla = (team === "home") !== s.sp.servHome
|
||||
s.sp.punt[team]++
|
||||
s.sp.striscia.at(-1).r.push(team)
|
||||
s.sp.striscia.at(-1).ris += team === 'home' ? 'h' : 'g'
|
||||
|
||||
if (cambioPalla) {
|
||||
s.sp.form[team].push(s.sp.form[team].shift())
|
||||
@@ -55,18 +55,22 @@ export function applyAction(state, action) {
|
||||
|
||||
case "decPunt": {
|
||||
const currentSet = s.sp.striscia.at(-1)
|
||||
if (currentSet.r.length === 0) break
|
||||
if (currentSet.ris.length === 0) break
|
||||
|
||||
const lastScorer = currentSet.r[currentSet.r.length - 1]
|
||||
const prevServer = currentSet.r.length >= 2
|
||||
? currentSet.r[currentSet.r.length - 2]
|
||||
const lastScorerShort = currentSet.ris.at(-1)
|
||||
const prevServerShort = currentSet.ris.length >= 2
|
||||
? currentSet.ris.at(-2)
|
||||
: currentSet.serv
|
||||
|
||||
const wasCambioPalla = lastScorer !== prevServer
|
||||
const wasCambioPalla = lastScorerShort !== prevServerShort
|
||||
|
||||
currentSet.ris = currentSet.ris.slice(0, -1)
|
||||
|
||||
const lastScorer = lastScorerShort === 'h' ? 'home' : 'guest'
|
||||
const prevServer = prevServerShort === 'h' ? 'home' : 'guest'
|
||||
|
||||
currentSet.r.pop()
|
||||
s.sp.punt[lastScorer]--
|
||||
s.sp.servHome = prevServer === 'home'
|
||||
s.sp.servHome = prevServerShort === 'h'
|
||||
|
||||
if (wasCambioPalla) {
|
||||
s.sp.form[lastScorer].unshift(s.sp.form[lastScorer].pop())
|
||||
@@ -91,7 +95,7 @@ export function applyAction(state, action) {
|
||||
s.sp.punt.home = 0
|
||||
s.sp.punt.guest = 0
|
||||
s.sp.servHome = team === 'home'
|
||||
s.sp.striscia.push({ serv: team, r: [] })
|
||||
s.sp.striscia.push({ serv: team === 'home' ? 'h' : 'g', ris: '' })
|
||||
s.sp.form = {
|
||||
home: ["1", "2", "3", "4", "5", "6"],
|
||||
guest: ["1", "2", "3", "4", "5", "6"],
|
||||
@@ -102,7 +106,7 @@ export function applyAction(state, action) {
|
||||
case "cambiaPalla": {
|
||||
if (s.sp.punt.home === 0 && s.sp.punt.guest === 0) {
|
||||
s.sp.servHome = !s.sp.servHome
|
||||
s.sp.striscia.at(-1).serv = s.sp.servHome ? 'home' : 'guest'
|
||||
s.sp.striscia.at(-1).serv = s.sp.servHome ? 'h' : 'g'
|
||||
}
|
||||
break
|
||||
}
|
||||
@@ -117,7 +121,7 @@ export function applyAction(state, action) {
|
||||
home: ["1", "2", "3", "4", "5", "6"],
|
||||
guest: ["1", "2", "3", "4", "5", "6"],
|
||||
}
|
||||
s.sp.striscia = [{ serv: s.sp.servHome ? 'home' : 'guest', r: [] }]
|
||||
s.sp.striscia = [{ serv: s.sp.servHome ? 'h' : 'g', ris: '' }]
|
||||
break
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user