4 Commits

Author SHA1 Message Date
5621830803 feat(controller): aggiunge modal formazione a inizio set
Dopo la conferma di un set finito appare automaticamente un secondo
modal "FORMAZIONE SET N" con gli input (resettati a 1-6) per
registrare la formazione del set successivo. Al click INIZIA vengono
inviati setFormazione per home e guest, e la formazione viene
archiviata in formInizioSet (e quindi nel DB a fine partita via
strisce[].formInizio).

Se la conferma del set conclude la partita, il modal formazione viene
chiuso automaticamente non appena lo stato con partitaFinita arriva
dal server
2026-02-21 19:16:27 +01:00
b3faf06477 test: aggiunge copertura completa per le nuove funzionalità
- Nuovo db.test.js: 11 test per salvaPartita, getPartite, getPartita
  (isolamento con DB in memoria via vi.stubEnv + vi.resetModules)
- gameState.test.js: test per confermaSet, formInizioSet, partitaFinita,
  checkVittoriaPartita e guardie setFinito/partitaFinita; fix di 6 test
  pre-esistenti non allineati con la logica striscia aggiornata
- websocket.test.js: mock di db.js e 4 test per il salvataggio automatico
  su DB al termine della partita
- server-utils.test.js: 2 test aggiuntivi per storicoPort
- ControllerPage.test.js: 4 test per l'overlay di fine set (setFinito)
- DisplayPage.test.js: 4 test per l'overlay di fine partita (partitaFinita)
2026-02-21 18:59:50 +01:00
1df239ed3d feat: salva partite su SQLite e aggiunge storico in dev
- Aggiunge src/db.js con better-sqlite3: tabella partite con nomi,
  modalità, set, formazione di partenza per set, punteggi e vincitore
- Salvataggio automatico al termine della partita (websocket-handler.js)
- Aggiunge formInizioSet in gameState per tracciare la formazione
  iniziale di ogni set
- Aggiunge storico.html: pagina vanilla dark-theme con lista partite
  espandibili (set, punteggio, formazioni)
- Aggiunge server storico su porta 3002 in dev (vite-plugin-websocket.js)
- Aggiunge endpoint /api/partite su displayApp (server.js)
- Migliora banner di avvio con URL storico locale e da rete
- Migliora log WebSocket: connessione aperta, ruolo unregistered, client rimanenti
- Aggiorna .gitignore: ignora tutta la cartella data/
2026-02-21 18:36:58 +01:00
d9e1ac751f feat(partita): storico strisce multi-set, conferma fine set e avviso fine partita
- sp.strisce[] archivia la striscia di ogni set completato
- fine set rilevata automaticamente: controller mostra modale di conferma
- confermaSet salva il set, incrementa il contatore e prepara il successivo
- fine partita rilevata da checkVittoriaPartita(): display mostra overlay con
  vincitore e punteggio set; incPunt bloccato
- decPunt pulisce setFinito (undo dell'ultimo punto di vittoria)
- resetta azzera strisce[], setFinito e partitaFinita
2026-02-21 17:49:19 +01:00
18 changed files with 1645 additions and 19 deletions

3
.gitignore vendored
View File

@@ -35,3 +35,6 @@ dist-ssr
# Vitest # Vitest
coverage/ coverage/
# Database SQLite
data/

377
package-lock.json generated
View File

@@ -8,6 +8,7 @@
"name": "segnapuntianto", "name": "segnapuntianto",
"version": "0.0.0", "version": "0.0.0",
"dependencies": { "dependencies": {
"better-sqlite3": "^12.6.2",
"express": "^5.2.1", "express": "^5.2.1",
"vue": "^3.2.47", "vue": "^3.2.47",
"vue-router": "^4.6.4", "vue-router": "^4.6.4",
@@ -3483,6 +3484,38 @@
"integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==",
"dev": true "dev": true
}, },
"node_modules/base64-js": {
"version": "1.5.1",
"resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz",
"integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==",
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/feross"
},
{
"type": "patreon",
"url": "https://www.patreon.com/feross"
},
{
"type": "consulting",
"url": "https://feross.org/support"
}
]
},
"node_modules/better-sqlite3": {
"version": "12.6.2",
"resolved": "https://registry.npmjs.org/better-sqlite3/-/better-sqlite3-12.6.2.tgz",
"integrity": "sha512-8VYKM3MjCa9WcaSAI3hzwhmyHVlH8tiGFwf0RlTsZPWJ1I5MkzjiudCo4KC4DxOaL/53A5B1sI/IbldNFDbsKA==",
"hasInstallScript": true,
"dependencies": {
"bindings": "^1.5.0",
"prebuild-install": "^7.1.1"
},
"engines": {
"node": "20.x || 22.x || 23.x || 24.x || 25.x"
}
},
"node_modules/bidi-js": { "node_modules/bidi-js": {
"version": "1.0.3", "version": "1.0.3",
"resolved": "https://registry.npmjs.org/bidi-js/-/bidi-js-1.0.3.tgz", "resolved": "https://registry.npmjs.org/bidi-js/-/bidi-js-1.0.3.tgz",
@@ -3492,6 +3525,24 @@
"require-from-string": "^2.0.2" "require-from-string": "^2.0.2"
} }
}, },
"node_modules/bindings": {
"version": "1.5.0",
"resolved": "https://registry.npmjs.org/bindings/-/bindings-1.5.0.tgz",
"integrity": "sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==",
"dependencies": {
"file-uri-to-path": "1.0.0"
}
},
"node_modules/bl": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/bl/-/bl-4.1.0.tgz",
"integrity": "sha512-1W07cM9gS6DcLperZfFSj+bWLtaPGSOHWhPiGzXmvVJbRLdG82sH/Kn8EtW1VqWVA54AKf2h5k5BbnIbwF3h6w==",
"dependencies": {
"buffer": "^5.5.0",
"inherits": "^2.0.4",
"readable-stream": "^3.4.0"
}
},
"node_modules/body-parser": { "node_modules/body-parser": {
"version": "2.2.2", "version": "2.2.2",
"resolved": "https://registry.npmjs.org/body-parser/-/body-parser-2.2.2.tgz", "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-2.2.2.tgz",
@@ -3568,6 +3619,29 @@
"node": "^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7" "node": "^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7"
} }
}, },
"node_modules/buffer": {
"version": "5.7.1",
"resolved": "https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz",
"integrity": "sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==",
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/feross"
},
{
"type": "patreon",
"url": "https://www.patreon.com/feross"
},
{
"type": "consulting",
"url": "https://feross.org/support"
}
],
"dependencies": {
"base64-js": "^1.3.1",
"ieee754": "^1.1.13"
}
},
"node_modules/buffer-from": { "node_modules/buffer-from": {
"version": "1.1.2", "version": "1.1.2",
"resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz", "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz",
@@ -3678,6 +3752,11 @@
"node": ">=4" "node": ">=4"
} }
}, },
"node_modules/chownr": {
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/chownr/-/chownr-1.1.4.tgz",
"integrity": "sha512-jJ0bqzaylmJtVnNgzTeSOs8DPavpbYgEr/b0YL8/2GO3xJEhInFmhKMUnEJQjZumK7KXGFhUy89PrsJWlakBVg=="
},
"node_modules/cliui": { "node_modules/cliui": {
"version": "8.0.1", "version": "8.0.1",
"resolved": "https://registry.npmjs.org/cliui/-/cliui-8.0.1.tgz", "resolved": "https://registry.npmjs.org/cliui/-/cliui-8.0.1.tgz",
@@ -4037,6 +4116,28 @@
"integrity": "sha512-YpgQiITW3JXGntzdUmyUR1V812Hn8T1YVXhCu+wO3OpS4eU9l4YdD3qjyiKdV6mvV29zapkMeD390UVEf2lkUg==", "integrity": "sha512-YpgQiITW3JXGntzdUmyUR1V812Hn8T1YVXhCu+wO3OpS4eU9l4YdD3qjyiKdV6mvV29zapkMeD390UVEf2lkUg==",
"dev": true "dev": true
}, },
"node_modules/decompress-response": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/decompress-response/-/decompress-response-6.0.0.tgz",
"integrity": "sha512-aW35yZM6Bb/4oJlZncMH2LCoZtJXTRxES17vE3hoRiowU2kWHaJKFkSBDnDR+cm9J+9QhXmREyIfv0pji9ejCQ==",
"dependencies": {
"mimic-response": "^3.1.0"
},
"engines": {
"node": ">=10"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/deep-extend": {
"version": "0.6.0",
"resolved": "https://registry.npmjs.org/deep-extend/-/deep-extend-0.6.0.tgz",
"integrity": "sha512-LOHxIOaPYdHlJRtCQfDIVZtfw/ufM8+rVj649RIHzcm/vGwQRXFt6OPqIFWsm2XEMrNIEtWR64sY1LEKD2vAOA==",
"engines": {
"node": ">=4.0.0"
}
},
"node_modules/deepmerge": { "node_modules/deepmerge": {
"version": "4.3.1", "version": "4.3.1",
"resolved": "https://registry.npmjs.org/deepmerge/-/deepmerge-4.3.1.tgz", "resolved": "https://registry.npmjs.org/deepmerge/-/deepmerge-4.3.1.tgz",
@@ -4070,6 +4171,14 @@
"node": ">= 0.8" "node": ">= 0.8"
} }
}, },
"node_modules/detect-libc": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.1.2.tgz",
"integrity": "sha512-Btj2BOOO83o3WyH59e8MgXsxEQVcarkUOpEYrubB0urwnN10yQ364rsiByU11nZlqWYZm05i/of7io4mzihBtQ==",
"engines": {
"node": ">=8"
}
},
"node_modules/dunder-proto": { "node_modules/dunder-proto": {
"version": "1.0.1", "version": "1.0.1",
"resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz",
@@ -4183,6 +4292,14 @@
"node": ">= 0.8" "node": ">= 0.8"
} }
}, },
"node_modules/end-of-stream": {
"version": "1.4.5",
"resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.5.tgz",
"integrity": "sha512-ooEGc6HP26xXq/N+GCGOT0JKCLDGrq2bQUZrQ7gyrJiZANJ/8YDTxTpQBXGMn+WbIQXNVpyWymm7KYVICQnyOg==",
"dependencies": {
"once": "^1.4.0"
}
},
"node_modules/entities": { "node_modules/entities": {
"version": "7.0.1", "version": "7.0.1",
"resolved": "https://registry.npmjs.org/entities/-/entities-7.0.1.tgz", "resolved": "https://registry.npmjs.org/entities/-/entities-7.0.1.tgz",
@@ -4388,6 +4505,14 @@
"node": ">= 0.6" "node": ">= 0.6"
} }
}, },
"node_modules/expand-template": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/expand-template/-/expand-template-2.0.3.tgz",
"integrity": "sha512-XYfuKMvj4O35f/pOXLObndIRvyQ+/+6AhODh+OKWj9S9498pHHn/IMszH+gt0fBCRWMNfk1ZSp5x3AifmnI2vg==",
"engines": {
"node": ">=6"
}
},
"node_modules/expect-type": { "node_modules/expect-type": {
"version": "1.3.0", "version": "1.3.0",
"resolved": "https://registry.npmjs.org/expect-type/-/expect-type-1.3.0.tgz", "resolved": "https://registry.npmjs.org/expect-type/-/expect-type-1.3.0.tgz",
@@ -4482,6 +4607,11 @@
"integrity": "sha512-cPJU47OaAoCbg0pBvzsgpTPhmhqI5eJjh/JIu8tPj5q+T7iLvW/JAYUqmE7KOB4R1ZyEhzBaIQpQpardBF5z8A==", "integrity": "sha512-cPJU47OaAoCbg0pBvzsgpTPhmhqI5eJjh/JIu8tPj5q+T7iLvW/JAYUqmE7KOB4R1ZyEhzBaIQpQpardBF5z8A==",
"dev": true "dev": true
}, },
"node_modules/file-uri-to-path": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz",
"integrity": "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw=="
},
"node_modules/filelist": { "node_modules/filelist": {
"version": "1.0.4", "version": "1.0.4",
"resolved": "https://registry.npmjs.org/filelist/-/filelist-1.0.4.tgz", "resolved": "https://registry.npmjs.org/filelist/-/filelist-1.0.4.tgz",
@@ -4582,6 +4712,11 @@
"node": ">= 0.8" "node": ">= 0.8"
} }
}, },
"node_modules/fs-constants": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/fs-constants/-/fs-constants-1.0.0.tgz",
"integrity": "sha512-y6OAwoSIf7FyjMIv94u+b5rdheZEjzR63GTyZJm5qh4Bi+2YgwLCcI/fPFZkL5PSixOt6ZNKm+w+Hfp/Bciwow=="
},
"node_modules/fs-extra": { "node_modules/fs-extra": {
"version": "9.1.0", "version": "9.1.0",
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-9.1.0.tgz", "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-9.1.0.tgz",
@@ -4727,6 +4862,11 @@
"url": "https://github.com/sponsors/ljharb" "url": "https://github.com/sponsors/ljharb"
} }
}, },
"node_modules/github-from-package": {
"version": "0.0.0",
"resolved": "https://registry.npmjs.org/github-from-package/-/github-from-package-0.0.0.tgz",
"integrity": "sha512-SyHy3T1v2NUXn29OsWdxmK6RwHD+vkj3v8en8AOBZ1wBQ/hCAQ5bAQTD02kW4W9tUp/3Qh6J8r9EvntiyCmOOw=="
},
"node_modules/glob": { "node_modules/glob": {
"version": "7.2.3", "version": "7.2.3",
"resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz",
@@ -5007,6 +5147,25 @@
"integrity": "sha512-gchesWBzyvGHRO9W8tzUWFDycow5gwjvFKfyV9FF32Y7F50yZMp7mP+T2mJIWFx49zicqyC4uefHM17o6xKIVQ==", "integrity": "sha512-gchesWBzyvGHRO9W8tzUWFDycow5gwjvFKfyV9FF32Y7F50yZMp7mP+T2mJIWFx49zicqyC4uefHM17o6xKIVQ==",
"dev": true "dev": true
}, },
"node_modules/ieee754": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz",
"integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==",
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/feross"
},
{
"type": "patreon",
"url": "https://www.patreon.com/feross"
},
{
"type": "consulting",
"url": "https://feross.org/support"
}
]
},
"node_modules/inflight": { "node_modules/inflight": {
"version": "1.0.6", "version": "1.0.6",
"resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz",
@@ -5025,8 +5184,7 @@
"node_modules/ini": { "node_modules/ini": {
"version": "1.3.8", "version": "1.3.8",
"resolved": "https://registry.npmjs.org/ini/-/ini-1.3.8.tgz", "resolved": "https://registry.npmjs.org/ini/-/ini-1.3.8.tgz",
"integrity": "sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==", "integrity": "sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew=="
"dev": true
}, },
"node_modules/internal-slot": { "node_modules/internal-slot": {
"version": "1.0.5", "version": "1.0.5",
@@ -5808,6 +5966,17 @@
"url": "https://opencollective.com/express" "url": "https://opencollective.com/express"
} }
}, },
"node_modules/mimic-response": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-3.1.0.tgz",
"integrity": "sha512-z0yWI+4FDrrweS8Zmt4Ej5HdJmky15+L2e6Wgn3+iK5fWzb6T3fhNFq2+MeTRb064c6Wr4N/wv0DzQTjNzHNGQ==",
"engines": {
"node": ">=10"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/minimatch": { "node_modules/minimatch": {
"version": "3.1.2", "version": "3.1.2",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz",
@@ -5830,6 +5999,14 @@
"concat-map": "0.0.1" "concat-map": "0.0.1"
} }
}, },
"node_modules/minimist": {
"version": "1.2.8",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz",
"integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==",
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/minipass": { "node_modules/minipass": {
"version": "7.1.2", "version": "7.1.2",
"resolved": "https://registry.npmjs.org/minipass/-/minipass-7.1.2.tgz", "resolved": "https://registry.npmjs.org/minipass/-/minipass-7.1.2.tgz",
@@ -5839,6 +6016,11 @@
"node": ">=16 || 14 >=14.17" "node": ">=16 || 14 >=14.17"
} }
}, },
"node_modules/mkdirp-classic": {
"version": "0.5.3",
"resolved": "https://registry.npmjs.org/mkdirp-classic/-/mkdirp-classic-0.5.3.tgz",
"integrity": "sha512-gKLcREMhtuZRwRAfqP3RFW+TK4JqApVBtOIftVgjuABpAtpxhPGaDcfvbhNvD0B8iD1oUr/txX35NjcaY6Ns/A=="
},
"node_modules/mrmime": { "node_modules/mrmime": {
"version": "2.0.1", "version": "2.0.1",
"resolved": "https://registry.npmjs.org/mrmime/-/mrmime-2.0.1.tgz", "resolved": "https://registry.npmjs.org/mrmime/-/mrmime-2.0.1.tgz",
@@ -5870,6 +6052,11 @@
"node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1" "node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1"
} }
}, },
"node_modules/napi-build-utils": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/napi-build-utils/-/napi-build-utils-2.0.0.tgz",
"integrity": "sha512-GEbrYkbfF7MoNaoh2iGG84Mnf/WZfB0GdGEsM8wz7Expx/LlWf5U8t9nvJKXSp3qr5IsEbK04cBGhol/KwOsWA=="
},
"node_modules/negotiator": { "node_modules/negotiator": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/negotiator/-/negotiator-1.0.0.tgz", "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-1.0.0.tgz",
@@ -5878,6 +6065,28 @@
"node": ">= 0.6" "node": ">= 0.6"
} }
}, },
"node_modules/node-abi": {
"version": "3.87.0",
"resolved": "https://registry.npmjs.org/node-abi/-/node-abi-3.87.0.tgz",
"integrity": "sha512-+CGM1L1CgmtheLcBuleyYOn7NWPVu0s0EJH2C4puxgEZb9h8QpR9G2dBfZJOAUhi7VQxuBPMd0hiISWcTyiYyQ==",
"dependencies": {
"semver": "^7.3.5"
},
"engines": {
"node": ">=10"
}
},
"node_modules/node-abi/node_modules/semver": {
"version": "7.7.4",
"resolved": "https://registry.npmjs.org/semver/-/semver-7.7.4.tgz",
"integrity": "sha512-vFKC2IEtQnVhpT78h1Yp8wzwrf8CM+MzKMHGJZfBtzhZNycRFnXsHk6E5TxIkkMsgNS7mdX3AGB7x2QM2di4lA==",
"bin": {
"semver": "bin/semver.js"
},
"engines": {
"node": ">=10"
}
},
"node_modules/node-releases": { "node_modules/node-releases": {
"version": "2.0.12", "version": "2.0.12",
"resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.12.tgz", "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.12.tgz",
@@ -6153,6 +6362,32 @@
"node": "^10 || ^12 || >=14" "node": "^10 || ^12 || >=14"
} }
}, },
"node_modules/prebuild-install": {
"version": "7.1.3",
"resolved": "https://registry.npmjs.org/prebuild-install/-/prebuild-install-7.1.3.tgz",
"integrity": "sha512-8Mf2cbV7x1cXPUILADGI3wuhfqWvtiLA1iclTDbFRZkgRQS0NqsPZphna9V+HyTEadheuPmjaJMsbzKQFOzLug==",
"deprecated": "No longer maintained. Please contact the author of the relevant native addon; alternatives are available.",
"dependencies": {
"detect-libc": "^2.0.0",
"expand-template": "^2.0.3",
"github-from-package": "0.0.0",
"minimist": "^1.2.3",
"mkdirp-classic": "^0.5.3",
"napi-build-utils": "^2.0.0",
"node-abi": "^3.3.0",
"pump": "^3.0.0",
"rc": "^1.2.7",
"simple-get": "^4.0.0",
"tar-fs": "^2.0.0",
"tunnel-agent": "^0.6.0"
},
"bin": {
"prebuild-install": "bin.js"
},
"engines": {
"node": ">=10"
}
},
"node_modules/pretty-bytes": { "node_modules/pretty-bytes": {
"version": "6.1.0", "version": "6.1.0",
"resolved": "https://registry.npmjs.org/pretty-bytes/-/pretty-bytes-6.1.0.tgz", "resolved": "https://registry.npmjs.org/pretty-bytes/-/pretty-bytes-6.1.0.tgz",
@@ -6183,6 +6418,15 @@
"node": ">= 0.10" "node": ">= 0.10"
} }
}, },
"node_modules/pump": {
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/pump/-/pump-3.0.3.tgz",
"integrity": "sha512-todwxLMY7/heScKmntwQG8CXVkWUOdYxIvY2s0VWAAMh/nd8SoYiRaKjlr7+iCs984f2P8zvrfWcDDYVb73NfA==",
"dependencies": {
"end-of-stream": "^1.1.0",
"once": "^1.3.1"
}
},
"node_modules/punycode": { "node_modules/punycode": {
"version": "2.3.1", "version": "2.3.1",
"resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz",
@@ -6257,6 +6501,33 @@
"node": ">= 0.10" "node": ">= 0.10"
} }
}, },
"node_modules/rc": {
"version": "1.2.8",
"resolved": "https://registry.npmjs.org/rc/-/rc-1.2.8.tgz",
"integrity": "sha512-y3bGgqKj3QBdxLbLkomlohkvsA8gdAiUQlSBJnBhfn+BPxg4bc62d8TcBW15wavDfgexCgccckhcZvywyQYPOw==",
"dependencies": {
"deep-extend": "^0.6.0",
"ini": "~1.3.0",
"minimist": "^1.2.0",
"strip-json-comments": "~2.0.1"
},
"bin": {
"rc": "cli.js"
}
},
"node_modules/readable-stream": {
"version": "3.6.2",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz",
"integrity": "sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==",
"dependencies": {
"inherits": "^2.0.3",
"string_decoder": "^1.1.1",
"util-deprecate": "^1.0.1"
},
"engines": {
"node": ">= 6"
}
},
"node_modules/regenerate": { "node_modules/regenerate": {
"version": "1.4.2", "version": "1.4.2",
"resolved": "https://registry.npmjs.org/regenerate/-/regenerate-1.4.2.tgz", "resolved": "https://registry.npmjs.org/regenerate/-/regenerate-1.4.2.tgz",
@@ -6472,7 +6743,6 @@
"version": "5.2.1", "version": "5.2.1",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz",
"integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==",
"dev": true,
"funding": [ "funding": [
{ {
"type": "github", "type": "github",
@@ -6704,6 +6974,49 @@
"url": "https://github.com/sponsors/isaacs" "url": "https://github.com/sponsors/isaacs"
} }
}, },
"node_modules/simple-concat": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/simple-concat/-/simple-concat-1.0.1.tgz",
"integrity": "sha512-cSFtAPtRhljv69IK0hTVZQ+OfE9nePi/rtJmw5UjHeVyVroEqJXP1sFztKUy1qU+xvz3u/sfYJLa947b7nAN2Q==",
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/feross"
},
{
"type": "patreon",
"url": "https://www.patreon.com/feross"
},
{
"type": "consulting",
"url": "https://feross.org/support"
}
]
},
"node_modules/simple-get": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/simple-get/-/simple-get-4.0.1.tgz",
"integrity": "sha512-brv7p5WgH0jmQJr1ZDDfKDOSeWWg+OVypG99A/5vYGPqJ6pxiaHLy8nxtFjBA7oMa01ebA9gfh1uMCFqOuXxvA==",
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/feross"
},
{
"type": "patreon",
"url": "https://www.patreon.com/feross"
},
{
"type": "consulting",
"url": "https://feross.org/support"
}
],
"dependencies": {
"decompress-response": "^6.0.0",
"once": "^1.3.1",
"simple-concat": "^1.0.0"
}
},
"node_modules/sirv": { "node_modules/sirv": {
"version": "3.0.2", "version": "3.0.2",
"resolved": "https://registry.npmjs.org/sirv/-/sirv-3.0.2.tgz", "resolved": "https://registry.npmjs.org/sirv/-/sirv-3.0.2.tgz",
@@ -6784,6 +7097,14 @@
"integrity": "sha512-5GS12FdOZNliM5mAOxFRg7Ir0pWz8MdpYm6AY6VPkGpbA7ZzmbzNcBJQ0GPvvyWgcY7QAhCgf9Uy89I03faLkg==", "integrity": "sha512-5GS12FdOZNliM5mAOxFRg7Ir0pWz8MdpYm6AY6VPkGpbA7ZzmbzNcBJQ0GPvvyWgcY7QAhCgf9Uy89I03faLkg==",
"dev": true "dev": true
}, },
"node_modules/string_decoder": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz",
"integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==",
"dependencies": {
"safe-buffer": "~5.2.0"
}
},
"node_modules/string-width": { "node_modules/string-width": {
"version": "4.2.3", "version": "4.2.3",
"resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz",
@@ -6925,6 +7246,14 @@
"node": ">=10" "node": ">=10"
} }
}, },
"node_modules/strip-json-comments": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-2.0.1.tgz",
"integrity": "sha512-4gB8na07fecVVkOI6Rs4e7T6NOTki5EmL7TUduTs6bu3EdnSycntVJ4re8kgZA+wx9IueI2Y11bfbgwtzuE0KQ==",
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/supports-color": { "node_modules/supports-color": {
"version": "5.5.0", "version": "5.5.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz",
@@ -6955,6 +7284,32 @@
"integrity": "sha512-9QNk5KwDF+Bvz+PyObkmSYjI5ksVUYtjW7AU22r2NKcfLJcXp96hkDWU3+XndOsUb+AQ9QhfzfCT2O+CNWT5Tw==", "integrity": "sha512-9QNk5KwDF+Bvz+PyObkmSYjI5ksVUYtjW7AU22r2NKcfLJcXp96hkDWU3+XndOsUb+AQ9QhfzfCT2O+CNWT5Tw==",
"dev": true "dev": true
}, },
"node_modules/tar-fs": {
"version": "2.1.4",
"resolved": "https://registry.npmjs.org/tar-fs/-/tar-fs-2.1.4.tgz",
"integrity": "sha512-mDAjwmZdh7LTT6pNleZ05Yt65HC3E+NiQzl672vQG38jIrehtJk/J3mNwIg+vShQPcLF/LV7CMnDW6vjj6sfYQ==",
"dependencies": {
"chownr": "^1.1.1",
"mkdirp-classic": "^0.5.2",
"pump": "^3.0.0",
"tar-stream": "^2.1.4"
}
},
"node_modules/tar-stream": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/tar-stream/-/tar-stream-2.2.0.tgz",
"integrity": "sha512-ujeqbceABgwMZxEJnk2HDY2DlnUZ+9oEcb1KzTVfYHio0UE6dG71n60d8D2I4qNvleWrrXpmjpt7vZeF1LnMZQ==",
"dependencies": {
"bl": "^4.0.3",
"end-of-stream": "^1.4.1",
"fs-constants": "^1.0.0",
"inherits": "^2.0.3",
"readable-stream": "^3.1.1"
},
"engines": {
"node": ">=6"
}
},
"node_modules/temp-dir": { "node_modules/temp-dir": {
"version": "2.0.0", "version": "2.0.0",
"resolved": "https://registry.npmjs.org/temp-dir/-/temp-dir-2.0.0.tgz", "resolved": "https://registry.npmjs.org/temp-dir/-/temp-dir-2.0.0.tgz",
@@ -7152,6 +7507,17 @@
"integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==", "integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==",
"dev": true "dev": true
}, },
"node_modules/tunnel-agent": {
"version": "0.6.0",
"resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz",
"integrity": "sha512-McnNiV1l8RYeY8tBgEpuodCC1mLUdbSN+CYBL7kJsJNInOP8UjDDEwdk6Mw60vdLLrr5NHKZhMAOSrR2NZuQ+w==",
"dependencies": {
"safe-buffer": "^5.0.1"
},
"engines": {
"node": "*"
}
},
"node_modules/type-fest": { "node_modules/type-fest": {
"version": "0.16.0", "version": "0.16.0",
"resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.16.0.tgz", "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.16.0.tgz",
@@ -7339,6 +7705,11 @@
"punycode": "^2.1.0" "punycode": "^2.1.0"
} }
}, },
"node_modules/util-deprecate": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",
"integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw=="
},
"node_modules/vary": { "node_modules/vary": {
"version": "1.1.2", "version": "1.1.2",
"resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz",

View File

@@ -20,6 +20,7 @@
"test:e2e:codegen": "playwright codegen --config=playwright.config.cjs" "test:e2e:codegen": "playwright codegen --config=playwright.config.cjs"
}, },
"dependencies": { "dependencies": {
"better-sqlite3": "^12.6.2",
"express": "^5.2.1", "express": "^5.2.1",
"vue": "^3.2.47", "vue": "^3.2.47",
"vue-router": "^4.6.4", "vue-router": "^4.6.4",

View File

@@ -5,6 +5,7 @@ import { fileURLToPath } from 'url'
import { dirname, join } from 'path' import { dirname, join } from 'path'
import { setupWebSocketHandler } from './src/websocket-handler.js' import { setupWebSocketHandler } from './src/websocket-handler.js'
import { printServerInfo } from './src/server-utils.js' import { printServerInfo } from './src/server-utils.js'
import { getPartite, getPartita } from './src/db.js'
const __filename = fileURLToPath(import.meta.url) const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename) const __dirname = dirname(__filename)
@@ -23,6 +24,20 @@ const displayApp = express()
// Espone i file generati dalla build di Vite. // Espone i file generati dalla build di Vite.
displayApp.use(express.static(join(__dirname, 'dist'))) displayApp.use(express.static(join(__dirname, 'dist')))
// API REST per le partite salvate.
displayApp.get('/api/partite', (_req, res) => {
try { res.json(getPartite()) }
catch (err) { res.status(500).json({ error: err.message }) }
})
displayApp.get('/api/partite/:id', (req, res) => {
try {
const p = getPartita(Number(req.params.id))
if (!p) return res.status(404).json({ error: 'Not found' })
res.json(p)
} catch (err) { res.status(500).json({ error: err.message }) }
})
// Fallback per SPA: restituisce `index.html` per tutte le route. // Fallback per SPA: restituisce `index.html` per tutte le route.
displayApp.get(/.*/, (_req, res) => { displayApp.get(/.*/, (_req, res) => {
res.sendFile(join(__dirname, 'dist', 'index.html')) res.sendFile(join(__dirname, 'dist', 'index.html'))

View File

@@ -78,6 +78,64 @@
</div> </div>
</div> </div>
<!-- Finestra fine set -->
<div class="overlay" v-if="setFinito">
<div class="dialog">
<div class="dialog-title">SET FINITO</div>
<div class="set-finito-info">
<div class="set-vincitore">{{ state.sp.nomi[setFinito.vincitore] }}</div>
<div class="set-score">{{ state.sp.punt.home }} {{ state.sp.punt.guest }}</div>
</div>
<div class="dialog-buttons">
<button class="btn btn-confirm" @click="confermaSetEApriFormazione()">CONFERMA</button>
</div>
</div>
</div>
<!-- Finestra formazione inizio set -->
<div class="overlay" v-if="showFormazioneModal">
<div class="dialog dialog-config">
<div class="dialog-title">
FORMAZIONE SET {{ state.sp.set.home + state.sp.set.guest + 1 }}
</div>
<div class="form-group">
<label>{{ state.sp.nomi.home }}</label>
<div class="form-grid">
<div class="form-row">
<input type="text" v-model="formazioneSetData.home[3]" class="input-num" />
<input type="text" v-model="formazioneSetData.home[2]" class="input-num" />
<input type="text" v-model="formazioneSetData.home[1]" class="input-num" />
</div>
<div class="form-line"></div>
<div class="form-row">
<input type="text" v-model="formazioneSetData.home[4]" class="input-num" />
<input type="text" v-model="formazioneSetData.home[5]" class="input-num" />
<input type="text" v-model="formazioneSetData.home[0]" class="input-num" />
</div>
</div>
</div>
<div class="form-group">
<label>{{ state.sp.nomi.guest }}</label>
<div class="form-grid">
<div class="form-row">
<input type="text" v-model="formazioneSetData.guest[3]" class="input-num" />
<input type="text" v-model="formazioneSetData.guest[2]" class="input-num" />
<input type="text" v-model="formazioneSetData.guest[1]" class="input-num" />
</div>
<div class="form-line"></div>
<div class="form-row">
<input type="text" v-model="formazioneSetData.guest[4]" class="input-num" />
<input type="text" v-model="formazioneSetData.guest[5]" class="input-num" />
<input type="text" v-model="formazioneSetData.guest[0]" class="input-num" />
</div>
</div>
</div>
<div class="dialog-buttons">
<button class="btn btn-confirm" @click="confermaFormazioneSet()">INIZIA</button>
</div>
</div>
</div>
<!-- Finestra configurazione --> <!-- Finestra configurazione -->
<div class="overlay" v-if="showConfig" @click.self="showConfig = false"> <div class="overlay" v-if="showConfig" @click.self="showConfig = false">
<div class="dialog dialog-config"> <div class="dialog dialog-config">
@@ -187,6 +245,11 @@ export default {
reconnectAttempts: 0, reconnectAttempts: 0,
maxReconnectDelay: 30000, maxReconnectDelay: 30000,
confirmReset: false, confirmReset: false,
showFormazioneModal: false,
formazioneSetData: {
home: ["1", "2", "3", "4", "5", "6"],
guest: ["1", "2", "3", "4", "5", "6"],
},
showConfig: false, showConfig: false,
showCambiTeam: false, showCambiTeam: false,
showCambi: false, showCambi: false,
@@ -209,6 +272,8 @@ export default {
visuStriscia: true, visuStriscia: true,
modalitaPartita: "3/5", modalitaPartita: "3/5",
sp: { sp: {
strisce: [],
setFinito: null,
striscia: { home: [0], guest: [0] }, striscia: { home: [0], guest: [0] },
servHome: true, servHome: true,
punt: { home: 0, guest: 0 }, punt: { home: 0, guest: 0 },
@@ -227,6 +292,9 @@ export default {
isPunteggioZeroZero() { isPunteggioZeroZero() {
return this.state.sp.punt.home === 0 && this.state.sp.punt.guest === 0 return this.state.sp.punt.home === 0 && this.state.sp.punt.guest === 0
}, },
setFinito() {
return this.state.sp.setFinito
},
cambiValid() { cambiValid() {
let hasComplete = false let hasComplete = false
let allValid = true let allValid = true
@@ -355,6 +423,9 @@ export default {
if (msg.type === 'state') { if (msg.type === 'state') {
this.state = msg.state this.state = msg.state
if (this.state.sp.partitaFinita && this.showFormazioneModal) {
this.showFormazioneModal = false
}
} else if (msg.type === 'error') { } else if (msg.type === 'error') {
console.error('[Controller] Server error:', msg.message) console.error('[Controller] Server error:', msg.message)
// Fornisce feedback di errore all'utente. // Fornisce feedback di errore all'utente.
@@ -435,6 +506,21 @@ export default {
console.error('[Controller] Error:', message) console.error('[Controller] Error:', message)
}, },
confermaSetEApriFormazione() {
this.sendAction({ type: 'confermaSet' })
this.formazioneSetData = {
home: ["1", "2", "3", "4", "5", "6"],
guest: ["1", "2", "3", "4", "5", "6"],
}
this.showFormazioneModal = true
},
confermaFormazioneSet() {
this.sendAction({ type: 'setFormazione', team: 'home', form: this.formazioneSetData.home })
this.sendAction({ type: 'setFormazione', team: 'guest', form: this.formazioneSetData.guest })
this.showFormazioneModal = false
},
doReset() { doReset() {
this.sendAction({ type: 'resetta' }) this.sendAction({ type: 'resetta' })
this.confirmReset = false this.confirmReset = false
@@ -905,4 +991,21 @@ export default {
padding: 8px 0; padding: 8px 0;
font-weight: 600; font-weight: 600;
} }
/* Fine set */
.set-finito-info {
text-align: center;
padding: 16px 0;
}
.set-vincitore {
font-size: 22px;
font-weight: 800;
color: #fdd835;
text-transform: uppercase;
margin-bottom: 8px;
}
.set-score {
font-size: 36px;
font-weight: 900;
}
</style> </style>

View File

@@ -112,6 +112,15 @@
{{ wsConnected ? '' : 'Disconnesso' }} {{ wsConnected ? '' : 'Disconnesso' }}
</div> </div>
</div> </div>
<!-- Overlay fine partita -->
<div class="partita-finita-overlay" v-if="state.sp.partitaFinita">
<div class="partita-finita-box">
<div class="partita-finita-label">PARTITA FINITA</div>
<div class="partita-finita-vincitore">{{ state.sp.nomi[state.sp.partitaFinita.vincitore] }}</div>
<div class="partita-finita-set">{{ state.sp.set.home }} {{ state.sp.set.guest }}</div>
</div>
</div>
</section> </section>
</template> </template>
@@ -132,6 +141,9 @@ export default {
visuStriscia: true, visuStriscia: true,
modalitaPartita: "3/5", modalitaPartita: "3/5",
sp: { sp: {
strisce: [],
setFinito: null,
partitaFinita: null,
striscia: { home: [0], guest: [0] }, striscia: { home: [0], guest: [0] },
servHome: true, servHome: true,
punt: { home: 0, guest: 0 }, punt: { home: 0, guest: 0 },
@@ -436,4 +448,38 @@ export default {
overflow: hidden; overflow: hidden;
box-sizing: border-box; box-sizing: border-box;
} }
/* Fine partita */
.partita-finita-overlay {
position: fixed;
inset: 0;
background: rgba(0, 0, 0, 0.88);
display: flex;
align-items: center;
justify-content: center;
z-index: 500;
}
.partita-finita-box {
text-align: center;
color: #fff;
}
.partita-finita-label {
font-size: 5vw;
font-weight: 700;
letter-spacing: 0.1em;
color: #aaa;
margin-bottom: 0.3em;
}
.partita-finita-vincitore {
font-size: 14vw;
font-weight: 900;
color: #fdd835;
text-transform: uppercase;
line-height: 1;
margin-bottom: 0.2em;
}
.partita-finita-set {
font-size: 8vw;
font-weight: 700;
}
</style> </style>

62
src/db.js Normal file
View File

@@ -0,0 +1,62 @@
import Database from 'better-sqlite3'
import { mkdirSync } from 'fs'
import { join, dirname } from 'path'
import { fileURLToPath } from 'url'
const __dirname = dirname(fileURLToPath(import.meta.url))
const DATA_DIR = join(__dirname, '..', 'data')
const DB_PATH = process.env.DB_PATH || join(DATA_DIR, 'partite.db')
mkdirSync(DATA_DIR, { recursive: true })
const db = new Database(DB_PATH)
db.pragma('journal_mode = WAL')
db.exec(`
CREATE TABLE IF NOT EXISTS partite (
id INTEGER PRIMARY KEY AUTOINCREMENT,
data TEXT NOT NULL,
modalita TEXT NOT NULL,
nome_home TEXT NOT NULL,
nome_guest TEXT NOT NULL,
set_home INTEGER NOT NULL,
set_guest INTEGER NOT NULL,
vincitore TEXT,
json TEXT NOT NULL
)
`)
const stmtInsert = db.prepare(`
INSERT INTO partite (data, modalita, nome_home, nome_guest, set_home, set_guest, vincitore, json)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
`)
export function salvaPartita(state) {
const payload = {
data: new Date().toISOString(),
modalita: state.modalitaPartita,
nomi: state.sp.nomi,
set: state.sp.set,
vincitore: state.sp.partitaFinita?.vincitore ?? null,
strisce: state.sp.strisce,
}
const { lastInsertRowid } = stmtInsert.run(
payload.data,
payload.modalita,
payload.nomi.home,
payload.nomi.guest,
payload.set.home,
payload.set.guest,
payload.vincitore,
JSON.stringify(payload)
)
return lastInsertRowid
}
export function getPartite() {
return db.prepare('SELECT * FROM partite ORDER BY id DESC').all()
}
export function getPartita(id) {
return db.prepare('SELECT * FROM partite WHERE id = ?').get(id)
}

View File

@@ -10,6 +10,13 @@ export function createInitialState() {
visuStriscia: true, visuStriscia: true,
modalitaPartita: "3/5", modalitaPartita: "3/5",
sp: { sp: {
strisce: [],
setFinito: null,
partitaFinita: null,
formInizioSet: {
home: ["1", "2", "3", "4", "5", "6"],
guest: ["1", "2", "3", "4", "5", "6"],
},
striscia: { home: [0], guest: [" "] }, striscia: { home: [0], guest: [" "] },
servHome: true, servHome: true,
punt: { home: 0, guest: 0 }, punt: { home: 0, guest: 0 },
@@ -24,6 +31,13 @@ export function createInitialState() {
} }
} }
export function checkVittoriaPartita(state) {
const setsToWin = state.modalitaPartita === "2/3" ? 2 : 3
if (state.sp.set.home >= setsToWin) return "home"
if (state.sp.set.guest >= setsToWin) return "guest"
return null
}
export function checkVittoria(state) { export function checkVittoria(state) {
const puntHome = state.sp.punt.home const puntHome = state.sp.punt.home
const puntGuest = state.sp.punt.guest const puntGuest = state.sp.punt.guest
@@ -58,7 +72,7 @@ export function applyAction(state, action) {
switch (action.type) { switch (action.type) {
case "incPunt": { case "incPunt": {
const team = action.team const team = action.team
if (checkVittoria(s)) break if (s.sp.setFinito !== null || s.sp.partitaFinita !== null) break
s.sp.storicoServizio.push({ s.sp.storicoServizio.push({
servHome: s.sp.servHome, servHome: s.sp.servHome,
@@ -80,10 +94,17 @@ export function applyAction(state, action) {
} }
s.sp.servHome = team === "home" s.sp.servHome = team === "home"
if (checkVittoria(s)) {
s.sp.setFinito = { vincitore: team }
}
break break
} }
case "decPunt": { case "decPunt": {
if (s.sp.setFinito !== null) {
s.sp.setFinito = null
}
if (s.sp.storicoServizio.length > 0) { if (s.sp.storicoServizio.length > 0) {
const tmpHome = s.sp.striscia.home.pop() const tmpHome = s.sp.striscia.home.pop()
s.sp.striscia.guest.pop() s.sp.striscia.guest.pop()
@@ -105,6 +126,45 @@ export function applyAction(state, action) {
break break
} }
case "confermaSet": {
if (!s.sp.setFinito) break
const vincitore = s.sp.setFinito.vincitore
s.sp.strisce.push({
set: s.sp.strisce.length + 1,
formInizio: {
home: [...s.sp.formInizioSet.home],
guest: [...s.sp.formInizioSet.guest],
},
home: [...s.sp.striscia.home],
guest: [...s.sp.striscia.guest],
vincitore,
punt: { ...s.sp.punt },
})
s.sp.formInizioSet = {
home: [...s.sp.form.home],
guest: [...s.sp.form.guest],
}
s.sp.set[vincitore]++
s.sp.punt.home = 0
s.sp.punt.guest = 0
s.sp.storicoServizio = []
s.sp.setFinito = null
const vincitorePartita = checkVittoriaPartita(s)
if (vincitorePartita) {
s.sp.partitaFinita = { vincitore: vincitorePartita }
} else {
s.sp.striscia = s.sp.servHome
? { home: [0], guest: [" "] }
: { home: [" "], guest: [0] }
}
break
}
case "incSet": { case "incSet": {
const team = action.team const team = action.team
if (s.sp.set[team] === 2) { if (s.sp.set[team] === 2) {
@@ -139,6 +199,13 @@ export function applyAction(state, action) {
? { home: [0], guest: [" "] } ? { home: [0], guest: [" "] }
: { home: [" "], guest: [0] } : { home: [" "], guest: [0] }
s.sp.storicoServizio = [] s.sp.storicoServizio = []
s.sp.strisce = []
s.sp.setFinito = null
s.sp.partitaFinita = null
s.sp.formInizioSet = {
home: ["1", "2", "3", "4", "5", "6"],
guest: ["1", "2", "3", "4", "5", "6"],
}
break break
} }
@@ -171,6 +238,7 @@ export function applyAction(state, action) {
case "setFormazione": { case "setFormazione": {
if (action.team && action.form) { if (action.team && action.form) {
s.sp.form[action.team] = [...action.form] s.sp.form[action.team] = [...action.form]
s.sp.formInizioSet[action.team] = [...action.form]
} }
break break
} }

View File

@@ -28,18 +28,23 @@ export function getNetworkIPs() {
* @param {number} displayPort - Porta del display. * @param {number} displayPort - Porta del display.
* @param {number} controllerPort - Porta del controller. * @param {number} controllerPort - Porta del controller.
*/ */
export function printServerInfo(displayPort = 5173, controllerPort = 3001) { export function printServerInfo(displayPort = 5173, controllerPort = 3001, storicoPort = 3002) {
const networkIPs = getNetworkIPs() const networkIPs = getNetworkIPs()
console.log(`\nSegnapunti Server`) console.log(`\nSegnapunti Server`)
console.log(` Display: http://127.0.0.1:${displayPort}/`) console.log(` Display: http://127.0.0.1:${displayPort}/`)
console.log(` Controller: http://127.0.0.1:${controllerPort}/`) console.log(` Controller: http://127.0.0.1:${controllerPort}/`)
console.log(` Storico: http://127.0.0.1:${storicoPort}/`)
if (networkIPs.length > 0) { if (networkIPs.length > 0) {
console.log(`\n Controller da dispositivi remoti:`) console.log(`\n Controller da dispositivi remoti:`)
networkIPs.forEach(ip => { networkIPs.forEach(ip => {
console.log(` http://${ip}:${controllerPort}/`) console.log(` http://${ip}:${controllerPort}/`)
}) })
console.log(`\n Storico da dispositivi remoti:`)
networkIPs.forEach(ip => {
console.log(` http://${ip}:${storicoPort}/`)
})
} }
console.log() console.log()

View File

@@ -1,4 +1,5 @@
import { createInitialState, applyAction } from './gameState.js' import { createInitialState, applyAction } from './gameState.js'
import { salvaPartita } from './db.js'
/** /**
* Crea e configura il server WebSocket per la gestione dello stato di gioco. * Crea e configura il server WebSocket per la gestione dello stato di gioco.
@@ -98,6 +99,16 @@ export function setupWebSocketHandler(wss) {
return return
} }
// Salva su DB quando la partita appena finisce.
if (!previousState.sp.partitaFinita && gameState.sp.partitaFinita) {
try {
const id = salvaPartita(gameState)
console.log(`[DB] Partita salvata (id: ${id})`)
} catch (err) {
console.error('[DB] Errore salvataggio partita:', err)
}
}
// Propaga il nuovo stato a tutti i client connessi. // Propaga il nuovo stato a tutti i client connessi.
broadcastState() broadcastState()
} }
@@ -156,9 +167,9 @@ export function setupWebSocketHandler(wss) {
*/ */
function handleClose(ws) { function handleClose(ws) {
const client = clients.get(ws) const client = clients.get(ws)
const role = client?.role || 'unknown' const role = client?.role || 'unregistered'
console.log(`[WebSocket] Client disconnected (role: ${role})`)
clients.delete(ws) clients.delete(ws)
console.log(`[WebSocket] Client disconnected (role: ${role}, remaining: ${wss.clients.size})`)
} }
/** /**
@@ -184,6 +195,8 @@ export function setupWebSocketHandler(wss) {
// Imposta il tipo binario per ridurre i problemi di codifica. // Imposta il tipo binario per ridurre i problemi di codifica.
ws.binaryType = 'arraybuffer' ws.binaryType = 'arraybuffer'
console.log(`[WebSocket] New connection (total: ${wss.clients.size})`)
ws.on('message', (data) => handleMessage(ws, data)) ws.on('message', (data) => handleMessage(ws, data))
ws.on('close', () => handleClose(ws)) ws.on('close', () => handleClose(ws))
ws.on('error', (err) => handleError(err, ws)) ws.on('error', (err) => handleError(err, ws))

293
storico.html Normal file
View File

@@ -0,0 +1,293 @@
<!DOCTYPE html>
<html lang="it">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Storico Partite</title>
<style>
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
background: #111;
color: #e0e0e0;
font-family: 'Inter', system-ui, sans-serif;
min-height: 100vh;
padding: 24px 16px;
}
h1 {
text-align: center;
font-size: 22px;
font-weight: 800;
letter-spacing: 0.1em;
color: #fdd835;
text-transform: uppercase;
margin-bottom: 24px;
}
#lista {
max-width: 700px;
margin: 0 auto;
display: flex;
flex-direction: column;
gap: 12px;
}
.card {
background: #1e1e1e;
border: 1px solid rgba(255,255,255,0.1);
border-radius: 16px;
overflow: hidden;
cursor: pointer;
}
.card-header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 16px 20px;
gap: 12px;
user-select: none;
}
.card-header:hover {
background: rgba(255,255,255,0.04);
}
.card-data {
font-size: 11px;
color: #777;
white-space: nowrap;
}
.card-teams {
flex: 1;
text-align: center;
}
.card-nomi {
font-size: 16px;
font-weight: 700;
}
.card-result {
font-size: 22px;
font-weight: 900;
letter-spacing: 0.05em;
margin-top: 2px;
}
.card-result .winner { color: #fdd835; }
.card-modalita {
font-size: 11px;
color: #777;
white-space: nowrap;
}
.card-arrow {
font-size: 18px;
color: #555;
transition: transform 0.2s;
}
.card.open .card-arrow { transform: rotate(180deg); }
.card-detail {
display: none;
border-top: 1px solid rgba(255,255,255,0.08);
padding: 16px 20px;
}
.card.open .card-detail { display: block; }
.set-table {
width: 100%;
border-collapse: collapse;
font-size: 13px;
}
.set-table th {
text-align: left;
padding: 6px 8px;
font-size: 11px;
font-weight: 700;
color: #777;
text-transform: uppercase;
letter-spacing: 0.05em;
border-bottom: 1px solid rgba(255,255,255,0.08);
}
.set-table td {
padding: 8px 8px;
vertical-align: top;
border-bottom: 1px solid rgba(255,255,255,0.05);
}
.set-table tr:last-child td { border-bottom: none; }
.set-num {
font-weight: 800;
color: #aaa;
width: 32px;
}
.set-vince {
font-weight: 700;
color: #fdd835;
}
.set-punt {
font-weight: 700;
font-size: 15px;
}
.form-grid {
display: inline-grid;
grid-template-columns: repeat(3, 28px);
grid-template-rows: repeat(2, 24px);
gap: 2px;
background: rgba(255,255,255,0.05);
border-radius: 6px;
padding: 4px;
}
.form-cell {
display: flex;
align-items: center;
justify-content: center;
font-size: 11px;
font-weight: 700;
background: rgba(255,255,255,0.08);
border-radius: 4px;
}
.form-label {
font-size: 11px;
color: #666;
margin-bottom: 4px;
}
.form-wrap {
display: flex;
flex-direction: column;
}
#vuoto {
text-align: center;
color: #555;
padding: 48px 16px;
font-size: 15px;
}
#errore {
text-align: center;
color: #ef5350;
padding: 24px;
}
</style>
</head>
<body>
<h1>Storico Partite</h1>
<div id="lista"></div>
<script>
function formatData(iso) {
const d = new Date(iso)
return d.toLocaleDateString('it-IT', { day: '2-digit', month: '2-digit', year: 'numeric' })
+ ' ' + d.toLocaleTimeString('it-IT', { hour: '2-digit', minute: '2-digit' })
}
// Layout campo: righe [fila attacco 3-2-1, fila difesa 4-5-0] → indici nell'array form
const LAYOUT = [3, 2, 1, 4, 5, 0]
function renderForm(form, label) {
const cells = LAYOUT.map(i => `<div class="form-cell">${form[i] ?? '?'}</div>`).join('')
return `<div class="form-wrap">
<div class="form-label">${label}</div>
<div class="form-grid">${cells}</div>
</div>`
}
function renderDettaglio(dati, nomiHome, nomiGuest) {
if (!dati.strisce || dati.strisce.length === 0) return '<p style="color:#555">Nessun set registrato.</p>'
const righe = dati.strisce.map(s => {
const vince = s.vincitore === 'home' ? nomiHome : nomiGuest
const formHome = s.formInizio?.home ?? []
const formGuest = s.formInizio?.guest ?? []
return `<tr>
<td class="set-num">${s.set}</td>
<td class="set-vince">${vince}</td>
<td class="set-punt">${s.punt.home} ${s.punt.guest}</td>
<td>${renderForm(formHome, nomiHome)}</td>
<td>${renderForm(formGuest, nomiGuest)}</td>
</tr>`
}).join('')
return `<table class="set-table">
<thead>
<tr>
<th>Set</th>
<th>Vincitore</th>
<th>Punteggio</th>
<th>Form Home</th>
<th>Form Guest</th>
</tr>
</thead>
<tbody>${righe}</tbody>
</table>`
}
function renderCard(p) {
const dati = JSON.parse(p.json)
const nomeHome = p.nome_home
const nomeGuest = p.nome_guest
const vincitoreNome = p.vincitore === 'home' ? nomeHome : nomeGuest
const homeWin = p.vincitore === 'home'
const resultHome = homeWin ? `<span class="winner">${p.set_home}</span>` : p.set_home
const resultGuest = homeWin ? p.set_guest : `<span class="winner">${p.set_guest}</span>`
const card = document.createElement('div')
card.className = 'card'
card.innerHTML = `
<div class="card-header">
<div class="card-data">${formatData(p.data)}</div>
<div class="card-teams">
<div class="card-nomi">${nomeHome} vs ${nomeGuest}</div>
<div class="card-result">${resultHome} ${resultGuest}</div>
</div>
<div class="card-modalita">${p.modalita}</div>
<div class="card-arrow">▾</div>
</div>
<div class="card-detail">
${renderDettaglio(dati, nomeHome, nomeGuest)}
</div>
`
card.querySelector('.card-header').addEventListener('click', () => {
card.classList.toggle('open')
})
return card
}
async function caricaPartite() {
const lista = document.getElementById('lista')
try {
const res = await fetch('/api/partite')
if (!res.ok) throw new Error(`HTTP ${res.status}`)
const partite = await res.json()
if (partite.length === 0) {
lista.innerHTML = '<div id="vuoto">Nessuna partita registrata.</div>'
return
}
partite.forEach(p => lista.appendChild(renderCard(p)))
} catch (err) {
lista.innerHTML = `<div id="errore">Errore caricamento: ${err.message}</div>`
}
}
caricaPartite()
</script>
</body>
</html>

View File

@@ -252,4 +252,37 @@ describe('ControllerPage.vue', () => {
expect(wrapper.find('.conn-bar').text()).toContain('Connesso') expect(wrapper.find('.conn-bar').text()).toContain('Connesso')
}) })
}) })
// =============================================
// OVERLAY SET FINITO
// =============================================
describe('Overlay set finito', () => {
it('non mostra l\'overlay se setFinito è null', () => {
const wrapper = mountController()
expect(wrapper.find('.overlay').exists()).toBe(false)
})
it('mostra l\'overlay quando setFinito è impostato', async () => {
const wrapper = mountController()
wrapper.vm.state.sp.setFinito = { vincitore: 'home' }
await wrapper.vm.$nextTick()
expect(wrapper.find('.overlay').exists()).toBe(true)
})
it('l\'overlay mostra il nome del vincitore del set', async () => {
const wrapper = mountController()
wrapper.vm.state.sp.setFinito = { vincitore: 'home' }
await wrapper.vm.$nextTick()
expect(wrapper.find('.overlay').text()).toContain('Antoniana')
})
it('click su CONFERMA invia l\'azione confermaSet', async () => {
const wrapper = mountController()
wrapper.vm.state.sp.setFinito = { vincitore: 'guest' }
await wrapper.vm.$nextTick()
const spy = vi.spyOn(wrapper.vm, 'sendAction')
await wrapper.find('.btn-confirm').trigger('click')
expect(spy).toHaveBeenCalledWith({ type: 'confermaSet' })
})
})
}) })

View File

@@ -192,4 +192,39 @@ describe('DisplayPage.vue', () => {
expect(guestStyle).toContain('display: none') expect(guestStyle).toContain('display: none')
}) })
}) })
// =============================================
// OVERLAY PARTITA FINITA
// =============================================
describe('Overlay partita finita', () => {
it('non mostra l\'overlay se partitaFinita è null', () => {
const wrapper = mountDisplay()
expect(wrapper.find('.partita-finita-overlay').exists()).toBe(false)
})
it('mostra l\'overlay quando partitaFinita è impostato', async () => {
const wrapper = mountDisplay()
wrapper.vm.state.sp.partitaFinita = { vincitore: 'home' }
await wrapper.vm.$nextTick()
expect(wrapper.find('.partita-finita-overlay').exists()).toBe(true)
})
it('l\'overlay mostra il nome del vincitore della partita', async () => {
const wrapper = mountDisplay()
wrapper.vm.state.sp.nomi = { home: 'Antoniana', guest: 'Rivali' }
wrapper.vm.state.sp.partitaFinita = { vincitore: 'guest' }
await wrapper.vm.$nextTick()
expect(wrapper.find('.partita-finita-overlay').text()).toContain('Rivali')
})
it('l\'overlay mostra il punteggio dei set', async () => {
const wrapper = mountDisplay()
wrapper.vm.state.sp.set = { home: 3, guest: 1 }
wrapper.vm.state.sp.partitaFinita = { vincitore: 'home' }
await wrapper.vm.$nextTick()
const text = wrapper.find('.partita-finita-overlay').text()
expect(text).toContain('3')
expect(text).toContain('1')
})
})
}) })

View File

@@ -1,6 +1,13 @@
import { describe, it, expect, beforeEach, vi, afterEach } from 'vitest' import { describe, it, expect, beforeEach, vi, afterEach } from 'vitest'
import { setupWebSocketHandler } from '../../src/websocket-handler.js' import { setupWebSocketHandler } from '../../src/websocket-handler.js'
import { EventEmitter } from 'events' import { EventEmitter } from 'events'
import { salvaPartita } from '../../src/db.js'
// Mock di db.js: evita connessioni reali al DB SQLite durante i test.
// vi.mock è automaticamente hoistato da Vitest all'inizio del file.
vi.mock('../../src/db.js', () => ({
salvaPartita: vi.fn().mockReturnValue(42n),
}))
// Mock parziale di una WebSocket e del Server // Mock parziale di una WebSocket e del Server
class MockWebSocket extends EventEmitter { class MockWebSocket extends EventEmitter {
@@ -400,4 +407,72 @@ describe('WebSocket Integration (websocket-handler.js)', () => {
expect(handler.getClients().size).toBe(1) expect(handler.getClients().size).toBe(1)
}) })
}) })
// =============================================
// SALVATAGGIO DB
// =============================================
describe('Salvataggio DB', () => {
// Helper: inietta uno stato con setFinito già impostato e N set vinti da home
function injectPreFinaleState(setHomeVinti, modalita = '3/5') {
const base = handler.getState()
handler.setState({
...base,
modalitaPartita: modalita,
sp: {
...base.sp,
set: { home: setHomeVinti, guest: 0 },
punt: { home: 25, guest: 0 },
setFinito: { vincitore: 'home' },
partitaFinita: null,
storicoServizio: [],
strisce: [],
striscia: { home: [0], guest: [" "] },
},
})
}
afterEach(() => {
vi.mocked(salvaPartita).mockClear()
})
it('salvaPartita viene chiamata quando confermaSet porta partitaFinita a non-null', () => {
// 3/5: servono 3 set → inietta 2 già vinti + setFinito, poi confermaSet
injectPreFinaleState(2, '3/5')
const controller = connectAndRegister(wss, 'controller')
controller.emit('message', JSON.stringify({ type: 'action', action: { type: 'confermaSet' } }))
expect(salvaPartita).toHaveBeenCalledTimes(1)
})
it('salvaPartita NON viene chiamata per azioni normali (incPunt)', () => {
const controller = connectAndRegister(wss, 'controller')
controller.emit('message', JSON.stringify({ type: 'action', action: { type: 'incPunt', team: 'home' } }))
expect(salvaPartita).not.toHaveBeenCalled()
})
it('salvaPartita NON viene chiamata se partitaFinita era già impostata', () => {
// Inietta stato con partitaFinita già presente
const base = handler.getState()
handler.setState({
...base,
sp: { ...base.sp, partitaFinita: { vincitore: 'home' } },
})
const controller = connectAndRegister(wss, 'controller')
// Qualsiasi azione non dovrebbe triggerare un secondo salvataggio
controller.emit('message', JSON.stringify({ type: 'action', action: { type: 'incPunt', team: 'home' } }))
expect(salvaPartita).not.toHaveBeenCalled()
})
it('se salvaPartita lancia un errore il broadcast avviene comunque', () => {
vi.mocked(salvaPartita).mockImplementationOnce(() => { throw new Error('DB error') })
injectPreFinaleState(2, '3/5')
const display = connectAndRegister(wss, 'display')
const controller = connectAndRegister(wss, 'controller')
display.send.mockClear()
controller.emit('message', JSON.stringify({ type: 'action', action: { type: 'confermaSet' } }))
// Il broadcast deve avvenire anche se il DB ha fallito
expect(display.send).toHaveBeenCalled()
const msg = lastSent(display)
expect(msg.type).toBe('state')
})
})
}) })

145
tests/unit/db.test.js Normal file
View File

@@ -0,0 +1,145 @@
import { describe, it, expect, beforeAll, afterAll, vi } from 'vitest'
// Il modulo db.js apre il DB a livello di modulo (top-level).
// Per isolarlo usiamo un DB in memoria: vi.stubEnv + vi.resetModules + import dinamico.
let salvaPartita, getPartite, getPartita
beforeAll(async () => {
vi.stubEnv('DB_PATH', ':memory:')
vi.resetModules()
const mod = await import('../../src/db.js')
salvaPartita = mod.salvaPartita
getPartite = mod.getPartite
getPartita = mod.getPartita
})
afterAll(() => {
vi.unstubAllEnvs()
})
// Stato minimo valido da passare a salvaPartita
function makeState({ vincitore = 'home', setHome = 3, setGuest = 1, strisce = [] } = {}) {
return {
modalitaPartita: '3/5',
sp: {
nomi: { home: 'Antoniana', guest: 'Ospiti' },
set: { home: setHome, guest: setGuest },
partitaFinita: vincitore ? { vincitore } : null,
strisce,
},
}
}
describe('db.js', () => {
// =============================================
// salvaPartita
// =============================================
describe('salvaPartita', () => {
it('ritorna un ID numerico intero positivo', () => {
const id = salvaPartita(makeState())
expect(typeof id).toBe('number')
expect(id).toBeGreaterThan(0)
expect(Number.isInteger(id)).toBe(true)
})
it('IDs sono incrementali su inserimenti multipli', () => {
const id1 = salvaPartita(makeState())
const id2 = salvaPartita(makeState())
expect(id2).toBeGreaterThan(id1)
})
it('il record ha i campi corretti: modalita, nomi, set, vincitore', () => {
const state = makeState({ vincitore: 'guest', setHome: 1, setGuest: 3 })
const id = salvaPartita(state)
const row = getPartita(Number(id))
expect(row.modalita).toBe('3/5')
expect(row.nome_home).toBe('Antoniana')
expect(row.nome_guest).toBe('Ospiti')
expect(row.set_home).toBe(1)
expect(row.set_guest).toBe(3)
expect(row.vincitore).toBe('guest')
})
it('il campo json è una stringa JSON parsabile', () => {
const id = salvaPartita(makeState())
const row = getPartita(Number(id))
expect(() => JSON.parse(row.json)).not.toThrow()
})
it('il JSON contiene nomi, set, strisce, vincitore e data', () => {
const strisce = [{ set: 1, vincitore: 'home', punt: { home: 25, guest: 20 } }]
const state = makeState({ strisce })
const id = salvaPartita(state)
const row = getPartita(Number(id))
const json = JSON.parse(row.json)
expect(json.nomi).toEqual({ home: 'Antoniana', guest: 'Ospiti' })
expect(json.set).toEqual({ home: 3, guest: 1 })
expect(json.vincitore).toBe('home')
expect(json.strisce).toEqual(strisce)
expect(typeof json.data).toBe('string')
expect(() => new Date(json.data)).not.toThrow()
})
it('vincitore nel DB è null se partitaFinita è null', () => {
const state = makeState({ vincitore: null })
const id = salvaPartita(state)
const row = getPartita(Number(id))
expect(row.vincitore).toBeNull()
})
})
// =============================================
// getPartite
// =============================================
describe('getPartite', () => {
it('ritorna tutte le partite inserite', () => {
const prima = getPartite().length
salvaPartita(makeState())
salvaPartita(makeState())
const dopo = getPartite()
expect(dopo.length).toBe(prima + 2)
})
it('ordina per ID discendente (più recente prima)', () => {
const id1 = Number(salvaPartita(makeState()))
const id2 = Number(salvaPartita(makeState()))
const partite = getPartite()
const ids = partite.map(p => p.id)
const idx1 = ids.indexOf(id1)
const idx2 = ids.indexOf(id2)
// id2 (inserito dopo) deve apparire prima (indice minore)
expect(idx2).toBeLessThan(idx1)
})
})
// =============================================
// getPartita
// =============================================
describe('getPartita', () => {
it('ritorna undefined per ID inesistente', () => {
const result = getPartita(999999)
expect(result).toBeUndefined()
})
it('ritorna il record corretto per ID valido', () => {
const id = Number(salvaPartita(makeState({ vincitore: 'home', setHome: 3, setGuest: 0 })))
const row = getPartita(id)
expect(row).toBeDefined()
expect(row.id).toBe(id)
expect(row.set_home).toBe(3)
expect(row.set_guest).toBe(0)
})
it('il record ha tutti i campi attesi', () => {
const id = Number(salvaPartita(makeState()))
const row = getPartita(id)
const campi = ['id', 'data', 'modalita', 'nome_home', 'nome_guest', 'set_home', 'set_guest', 'vincitore', 'json']
for (const campo of campi) {
expect(row).toHaveProperty(campo)
}
})
})
})

View File

@@ -1,5 +1,5 @@
import { describe, it, expect, beforeEach } from 'vitest' import { describe, it, expect, beforeEach } from 'vitest'
import { createInitialState, applyAction, checkVittoria } from '../../src/gameState.js' import { createInitialState, applyAction, checkVittoria, checkVittoriaPartita } from '../../src/gameState.js'
describe('Game Logic (gameState.js)', () => { describe('Game Logic (gameState.js)', () => {
let state let state
@@ -31,9 +31,10 @@ describe('Game Logic (gameState.js)', () => {
expect(state.sp.form.guest).toEqual(["1", "2", "3", "4", "5", "6"]) expect(state.sp.form.guest).toEqual(["1", "2", "3", "4", "5", "6"])
}) })
it('dovrebbe avere la striscia iniziale a [0]', () => { it('dovrebbe avere la striscia iniziale a [0] per home e [" "] per guest', () => {
// home serve per primo → home parte con [0], guest con [" "]
expect(state.sp.striscia.home).toEqual([0]) expect(state.sp.striscia.home).toEqual([0])
expect(state.sp.striscia.guest).toEqual([0]) expect(state.sp.striscia.guest).toEqual([" "])
}) })
it('dovrebbe avere storico servizio vuoto', () => { it('dovrebbe avere storico servizio vuoto', () => {
@@ -116,13 +117,15 @@ describe('Game Logic (gameState.js)', () => {
it('dovrebbe aggiornare la striscia per punto Home', () => { it('dovrebbe aggiornare la striscia per punto Home', () => {
const s = applyAction(state, { type: 'incPunt', team: 'home' }) const s = applyAction(state, { type: 'incPunt', team: 'home' })
// Lo stato iniziale ha striscia = { home: [0], guest: [" "] }
expect(s.sp.striscia.home).toEqual([0, 1]) expect(s.sp.striscia.home).toEqual([0, 1])
expect(s.sp.striscia.guest).toEqual([0, " "]) expect(s.sp.striscia.guest).toEqual([" ", " "])
}) })
it('dovrebbe aggiornare la striscia per punto Guest', () => { it('dovrebbe aggiornare la striscia per punto Guest', () => {
const s = applyAction(state, { type: 'incPunt', team: 'guest' }) const s = applyAction(state, { type: 'incPunt', team: 'guest' })
expect(s.sp.striscia.guest).toEqual([0, 1]) // Lo stato iniziale ha striscia = { home: [0], guest: [" "] }
expect(s.sp.striscia.guest).toEqual([" ", 1])
expect(s.sp.striscia.home).toEqual([0, " "]) expect(s.sp.striscia.home).toEqual([0, " "])
}) })
@@ -133,9 +136,11 @@ describe('Game Logic (gameState.js)', () => {
expect(s.sp.storicoServizio[0]).toHaveProperty('cambioPalla') expect(s.sp.storicoServizio[0]).toHaveProperty('cambioPalla')
}) })
it('non dovrebbe incrementare i punti dopo vittoria', () => { it('non dovrebbe incrementare i punti dopo vittoria (setFinito impostato)', () => {
// Il guard controlla setFinito: va impostato come farebbe il ciclo di gioco reale
state.sp.punt.home = 25 state.sp.punt.home = 25
state.sp.punt.guest = 23 state.sp.punt.guest = 23
state.sp.setFinito = { vincitore: 'home' }
const s = applyAction(state, { type: 'incPunt', team: 'home' }) const s = applyAction(state, { type: 'incPunt', team: 'home' })
expect(s.sp.punt.home).toBe(25) expect(s.sp.punt.home).toBe(25)
}) })
@@ -619,10 +624,11 @@ describe('Game Logic (gameState.js)', () => {
}) })
it('dovrebbe resettare la striscia', () => { it('dovrebbe resettare la striscia', () => {
state.sp.striscia = { home: [0, 1, 2, 3], guest: [0, " ", " ", 1] } state.sp.striscia = { home: [0, 1, 2, 3], guest: [" ", " ", " ", 1] }
const s = applyAction(state, { type: 'resetta' }) const s = applyAction(state, { type: 'resetta' })
// servHome è true di default → home parte con [0], guest con [" "]
expect(s.sp.striscia.home).toEqual([0]) expect(s.sp.striscia.home).toEqual([0])
expect(s.sp.striscia.guest).toEqual([0]) expect(s.sp.striscia.guest).toEqual([" "])
}) })
it('dovrebbe resettare lo storico servizio', () => { it('dovrebbe resettare lo storico servizio', () => {
@@ -656,4 +662,278 @@ describe('Game Logic (gameState.js)', () => {
expect(s.sp.punt.guest).toBe(0) expect(s.sp.punt.guest).toBe(0)
}) })
}) })
// =============================================
// FORMAZIONEINIZIOSET
// =============================================
describe('formInizioSet', () => {
it('dovrebbe esistere nello stato iniziale con valori di default', () => {
expect(state.sp.formInizioSet.home).toEqual(["1", "2", "3", "4", "5", "6"])
expect(state.sp.formInizioSet.guest).toEqual(["1", "2", "3", "4", "5", "6"])
})
it('setFormazione aggiorna sia form che formInizioSet per il team indicato', () => {
const nuova = ["10", "11", "12", "13", "14", "15"]
const s = applyAction(state, { type: 'setFormazione', team: 'home', form: nuova })
expect(s.sp.form.home).toEqual(nuova)
expect(s.sp.formInizioSet.home).toEqual(nuova)
})
it('setFormazione non tocca formInizioSet dell\'altro team', () => {
const nuova = ["10", "11", "12", "13", "14", "15"]
const s = applyAction(state, { type: 'setFormazione', team: 'home', form: nuova })
expect(s.sp.formInizioSet.guest).toEqual(["1", "2", "3", "4", "5", "6"])
})
})
// =============================================
// CONFERMASET
// =============================================
describe('confermaSet', () => {
// Helper: porta lo stato a fine set (home vince 25-0)
function stateConSetFinito(modalita = '3/5') {
let s = createInitialState()
s.modalitaPartita = modalita
// Aggiungiamo 25 punti a home: a 24-0 il prossimo punto vince il set
for (let i = 0; i < 25; i++) {
s = applyAction(s, { type: 'incPunt', team: 'home' })
}
// Ora setFinito dovrebbe essere impostato
return s
}
it('non fa nulla se setFinito è null', () => {
expect(state.sp.setFinito).toBeNull()
const s = applyAction(state, { type: 'confermaSet' })
expect(s.sp.strisce).toEqual([])
expect(s.sp.set.home).toBe(0)
})
it('aggiunge una entry in strisce con i campi corretti', () => {
const s = applyAction(stateConSetFinito(), { type: 'confermaSet' })
expect(s.sp.strisce).toHaveLength(1)
const striscia = s.sp.strisce[0]
expect(striscia).toHaveProperty('set')
expect(striscia).toHaveProperty('formInizio')
expect(striscia).toHaveProperty('home')
expect(striscia).toHaveProperty('guest')
expect(striscia).toHaveProperty('vincitore')
expect(striscia).toHaveProperty('punt')
})
it('il numero set è 1 per il primo set, 2 per il secondo', () => {
let s = stateConSetFinito()
s = applyAction(s, { type: 'confermaSet' })
expect(s.sp.strisce[0].set).toBe(1)
// Secondo set
for (let i = 0; i < 25; i++) {
s = applyAction(s, { type: 'incPunt', team: 'home' })
}
s = applyAction(s, { type: 'confermaSet' })
expect(s.sp.strisce[1].set).toBe(2)
})
it('formInizio nella striscia corrisponde a formInizioSet prima del conferma', () => {
const formazioneInizio = ["7", "8", "9", "10", "11", "12"]
let s = createInitialState()
s = applyAction(s, { type: 'setFormazione', team: 'home', form: formazioneInizio })
// porta a fine set
for (let i = 0; i < 25; i++) {
s = applyAction(s, { type: 'incPunt', team: 'home' })
}
s = applyAction(s, { type: 'confermaSet' })
expect(s.sp.strisce[0].formInizio.home).toEqual(formazioneInizio)
})
it('incrementa set[vincitore]', () => {
const s = applyAction(stateConSetFinito(), { type: 'confermaSet' })
expect(s.sp.set.home).toBe(1)
expect(s.sp.set.guest).toBe(0)
})
it('resetta punt a 0', () => {
const s = applyAction(stateConSetFinito(), { type: 'confermaSet' })
expect(s.sp.punt.home).toBe(0)
expect(s.sp.punt.guest).toBe(0)
})
it('svuota storicoServizio', () => {
const s = applyAction(stateConSetFinito(), { type: 'confermaSet' })
expect(s.sp.storicoServizio).toEqual([])
})
it('azzera setFinito', () => {
const s = applyAction(stateConSetFinito(), { type: 'confermaSet' })
expect(s.sp.setFinito).toBeNull()
})
it('aggiorna formInizioSet con la form corrente post-conferma', () => {
const preConferma = stateConSetFinito()
// La form potrebbe essere ruotata durante il set
const formDopoSet = [...preConferma.sp.form.home]
const s = applyAction(preConferma, { type: 'confermaSet' })
expect(s.sp.formInizioSet.home).toEqual(formDopoSet)
})
it('NON imposta partitaFinita se la partita non è ancora vinta (3/5)', () => {
const s = applyAction(stateConSetFinito('3/5'), { type: 'confermaSet' })
// 1 set vinto su 3 necessari → partita non finita
expect(s.sp.partitaFinita).toBeNull()
})
it('imposta partitaFinita quando home vince 3 set (modalità 3/5)', () => {
let s = createInitialState()
s.modalitaPartita = '3/5'
// Vinci 3 set
for (let set = 0; set < 3; set++) {
for (let i = 0; i < 25; i++) s = applyAction(s, { type: 'incPunt', team: 'home' })
s = applyAction(s, { type: 'confermaSet' })
}
expect(s.sp.partitaFinita).not.toBeNull()
expect(s.sp.partitaFinita.vincitore).toBe('home')
})
it('imposta partitaFinita quando home vince 2 set (modalità 2/3)', () => {
let s = createInitialState()
s.modalitaPartita = '2/3'
for (let set = 0; set < 2; set++) {
for (let i = 0; i < 25; i++) s = applyAction(s, { type: 'incPunt', team: 'home' })
s = applyAction(s, { type: 'confermaSet' })
}
expect(s.sp.partitaFinita).not.toBeNull()
expect(s.sp.partitaFinita.vincitore).toBe('home')
})
it('resetta striscia per il set successivo con 0 per chi serve', () => {
const s = applyAction(stateConSetFinito(), { type: 'confermaSet' })
// servHome era true (home segna per primo → resta home a servire)
expect(s.sp.striscia.home).toEqual([0])
expect(s.sp.striscia.guest).toEqual([" "])
})
})
// =============================================
// GUARDIE setFinito / partitaFinita
// =============================================
describe('Guardie setFinito e partitaFinita', () => {
it('incPunt non incrementa se setFinito è impostato', () => {
state.sp.setFinito = { vincitore: 'home' }
const s = applyAction(state, { type: 'incPunt', team: 'home' })
expect(s.sp.punt.home).toBe(0)
})
it('incPunt non incrementa se partitaFinita è impostata', () => {
state.sp.partitaFinita = { vincitore: 'home' }
const s = applyAction(state, { type: 'incPunt', team: 'guest' })
expect(s.sp.punt.guest).toBe(0)
})
it('decPunt azzera setFinito se era impostato', () => {
state.sp.setFinito = { vincitore: 'home' }
const s = applyAction(state, { type: 'decPunt' })
expect(s.sp.setFinito).toBeNull()
})
})
// =============================================
// RESETTA — nuovi campi
// =============================================
describe('resetta (nuovi campi)', () => {
it('azzera strisce', () => {
state.sp.strisce = [{ set: 1, vincitore: 'home', punt: { home: 25, guest: 20 } }]
const s = applyAction(state, { type: 'resetta' })
expect(s.sp.strisce).toEqual([])
})
it('azzera setFinito', () => {
state.sp.setFinito = { vincitore: 'home' }
const s = applyAction(state, { type: 'resetta' })
expect(s.sp.setFinito).toBeNull()
})
it('azzera partitaFinita', () => {
state.sp.partitaFinita = { vincitore: 'guest' }
const s = applyAction(state, { type: 'resetta' })
expect(s.sp.partitaFinita).toBeNull()
})
it('reimposta formInizioSet ai valori di default', () => {
state.sp.formInizioSet = { home: ["7", "8", "9", "10", "11", "12"], guest: ["7", "8", "9", "10", "11", "12"] }
const s = applyAction(state, { type: 'resetta' })
expect(s.sp.formInizioSet.home).toEqual(["1", "2", "3", "4", "5", "6"])
expect(s.sp.formInizioSet.guest).toEqual(["1", "2", "3", "4", "5", "6"])
})
})
// =============================================
// checkVittoriaPartita
// =============================================
describe('checkVittoriaPartita', () => {
it('ritorna null se nessuno ha vinto (3/5, 1-1)', () => {
state.sp.set.home = 1
state.sp.set.guest = 1
expect(checkVittoriaPartita(state)).toBeNull()
})
it('ritorna "home" con 3 set in modalità 3/5', () => {
state.modalitaPartita = '3/5'
state.sp.set.home = 3
state.sp.set.guest = 1
expect(checkVittoriaPartita(state)).toBe('home')
})
it('ritorna "guest" con 3 set in modalità 3/5', () => {
state.modalitaPartita = '3/5'
state.sp.set.home = 0
state.sp.set.guest = 3
expect(checkVittoriaPartita(state)).toBe('guest')
})
it('ritorna null con 2 set in modalità 3/5 (non ancora vinto)', () => {
state.modalitaPartita = '3/5'
state.sp.set.home = 2
state.sp.set.guest = 2
expect(checkVittoriaPartita(state)).toBeNull()
})
it('ritorna "home" con 2 set in modalità 2/3', () => {
state.modalitaPartita = '2/3'
state.sp.set.home = 2
state.sp.set.guest = 0
expect(checkVittoriaPartita(state)).toBe('home')
})
it('ritorna "guest" con 2 set in modalità 2/3', () => {
state.modalitaPartita = '2/3'
state.sp.set.home = 1
state.sp.set.guest = 2
expect(checkVittoriaPartita(state)).toBe('guest')
})
it('ritorna null con 1 set in modalità 2/3 (non ancora vinto)', () => {
state.modalitaPartita = '2/3'
state.sp.set.home = 1
state.sp.set.guest = 0
expect(checkVittoriaPartita(state)).toBeNull()
})
})
// =============================================
// confermaSet con servHome=false
// =============================================
describe('confermaSet — striscia con servHome=false', () => {
it('resetta striscia con guest a [0] se è guest a servire', () => {
let s = createInitialState()
// guest serve
s = applyAction(s, { type: 'cambiaPalla' })
expect(s.sp.servHome).toBe(false)
// porta a fine set (guest segna 25 volte)
for (let i = 0; i < 25; i++) s = applyAction(s, { type: 'incPunt', team: 'guest' })
s = applyAction(s, { type: 'confermaSet' })
// dopo il set, continua a servire guest
expect(s.sp.striscia.guest).toEqual([0])
expect(s.sp.striscia.home).toEqual([" "])
})
})
}) })

View File

@@ -109,6 +109,7 @@ describe('Server Utils', () => {
const allLogs = consoleSpy.mock.calls.map(c => c[0]).join('\n') const allLogs = consoleSpy.mock.calls.map(c => c[0]).join('\n')
expect(allLogs).toContain('5173') expect(allLogs).toContain('5173')
expect(allLogs).toContain('3001') expect(allLogs).toContain('3001')
expect(allLogs).toContain('3002')
consoleSpy.mockRestore() consoleSpy.mockRestore()
}) })
@@ -122,17 +123,27 @@ describe('Server Utils', () => {
consoleSpy.mockRestore() consoleSpy.mockRestore()
}) })
it('dovrebbe mostrare gli URL remoti se ci sono IP di rete', () => { it('dovrebbe stampare storicoPort personalizzato', () => {
os.networkInterfaces.mockReturnValue({})
const consoleSpy = vi.spyOn(console, 'log').mockImplementation(() => {})
printServerInfo(3000, 3001, 5000)
const allLogs = consoleSpy.mock.calls.map(c => c[0]).join('\n')
expect(allLogs).toContain('5000')
consoleSpy.mockRestore()
})
it('dovrebbe mostrare gli URL remoti per controller e storico', () => {
os.networkInterfaces.mockReturnValue({ os.networkInterfaces.mockReturnValue({
eth0: [ eth0: [
{ family: 'IPv4', internal: false, address: '192.168.1.50' } { family: 'IPv4', internal: false, address: '192.168.1.50' }
] ]
}) })
const consoleSpy = vi.spyOn(console, 'log').mockImplementation(() => {}) const consoleSpy = vi.spyOn(console, 'log').mockImplementation(() => {})
printServerInfo(3000, 3001) printServerInfo(3000, 3001, 3002)
const allLogs = consoleSpy.mock.calls.map(c => c[0]).join('\n') const allLogs = consoleSpy.mock.calls.map(c => c[0]).join('\n')
expect(allLogs).toContain('192.168.1.50') expect(allLogs).toContain('192.168.1.50')
expect(allLogs).toContain('remoti') expect(allLogs).toContain('3001')
expect(allLogs).toContain('3002')
consoleSpy.mockRestore() consoleSpy.mockRestore()
}) })

View File

@@ -1,9 +1,15 @@
import { WebSocketServer } from 'ws' import { WebSocketServer } from 'ws'
import { createServer as createHttpServer, request as httpRequest } from 'http' import { createServer as createHttpServer, request as httpRequest } from 'http'
import { readFile } from 'fs'
import { join, dirname } from 'path'
import { fileURLToPath } from 'url'
import { setupWebSocketHandler } from './src/websocket-handler.js' import { setupWebSocketHandler } from './src/websocket-handler.js'
import { printServerInfo } from './src/server-utils.js' import { printServerInfo } from './src/server-utils.js'
import { getPartite, getPartita } from './src/db.js'
const __dirname = dirname(fileURLToPath(import.meta.url))
const CONTROLLER_PORT = 3001 const CONTROLLER_PORT = 3001
const STORICO_PORT = process.env.STORICO_PORT || 3002
const DEV_PROXY_HOST = process.env.DEV_PROXY_HOST || '127.0.0.1' const DEV_PROXY_HOST = process.env.DEV_PROXY_HOST || '127.0.0.1'
/** /**
@@ -38,8 +44,9 @@ export default function websocketPlugin() {
const vitePort = viteAddr.port const vitePort = viteAddr.port
startControllerDevServer(vitePort, wss) startControllerDevServer(vitePort, wss)
startStoricoDevServer()
setTimeout(() => printServerInfo(vitePort, CONTROLLER_PORT), 100) setTimeout(() => printServerInfo(vitePort, CONTROLLER_PORT, STORICO_PORT), 100)
}) })
} }
} }
@@ -129,3 +136,63 @@ function startControllerDevServer(vitePort, wss) {
console.log(`[Controller] Dev server running on port ${CONTROLLER_PORT}`) console.log(`[Controller] Dev server running on port ${CONTROLLER_PORT}`)
}) })
} }
/**
* Avvia il server di sviluppo per lo storico sulla porta 3002.
* Serve storico.html e gli endpoint /api/partite.
*/
function startStoricoDevServer() {
const storicoServer = createHttpServer((req, res) => {
const url = new URL(req.url, `http://${req.headers.host}`)
const pathname = url.pathname
if (pathname === '/api/partite') {
try {
res.writeHead(200, { 'Content-Type': 'application/json' })
res.end(JSON.stringify(getPartite()))
} catch (err) {
res.writeHead(500, { 'Content-Type': 'application/json' })
res.end(JSON.stringify({ error: err.message }))
}
return
}
const matchId = pathname.match(/^\/api\/partite\/(\d+)$/)
if (matchId) {
try {
const p = getPartita(Number(matchId[1]))
if (!p) {
res.writeHead(404, { 'Content-Type': 'application/json' })
res.end(JSON.stringify({ error: 'Not found' }))
} else {
res.writeHead(200, { 'Content-Type': 'application/json' })
res.end(JSON.stringify(p))
}
} catch (err) {
res.writeHead(500, { 'Content-Type': 'application/json' })
res.end(JSON.stringify({ error: err.message }))
}
return
}
if (pathname === '/' || pathname === '') {
readFile(join(__dirname, 'storico.html'), (err, data) => {
if (err) {
res.writeHead(500)
res.end('Error loading storico.html')
} else {
res.writeHead(200, { 'Content-Type': 'text/html' })
res.end(data)
}
})
return
}
res.writeHead(404)
res.end('Not found')
})
storicoServer.listen(STORICO_PORT, '0.0.0.0', () => {
console.log(`[Storico] http://localhost:${STORICO_PORT}`)
})
}