feat: modalità amichevole e fix URL remoti in dev (WSL2)
- Aggiunge modalità "Amichevole" in config: i set si vincono normalmente ma la partita non termina mai automaticamente (checkVittoriaPartita restituisce false), consentendo di giocare set illimitati - Dev server ora espone su tutte le interfacce (vite --host) - printServerInfo mostra Display + Controller per dispositivi remoti - Su WSL2 getNetworkIPs() interroga PowerShell per ottenere gli IP Windows reali invece degli IP interni WSL (172.x)
This commit is contained in:
+1
-1
@@ -4,7 +4,7 @@
|
|||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite --host",
|
||||||
"build": "vite build",
|
"build": "vite build",
|
||||||
"serve": "vite build && node server.js",
|
"serve": "vite build && node server.js",
|
||||||
"test": "vitest",
|
"test": "vitest",
|
||||||
|
|||||||
@@ -113,6 +113,8 @@
|
|||||||
@click="configData.modalita = '2/3'">2/3</button>
|
@click="configData.modalita = '2/3'">2/3</button>
|
||||||
<button :class="['btn', 'btn-mode', configData.modalita === '3/5' ? 'active' : '']"
|
<button :class="['btn', 'btn-mode', configData.modalita === '3/5' ? 'active' : '']"
|
||||||
@click="configData.modalita = '3/5'">3/5</button>
|
@click="configData.modalita = '3/5'">3/5</button>
|
||||||
|
<button :class="['btn', 'btn-mode', configData.modalita === 'amichevole' ? 'active' : '']"
|
||||||
|
@click="configData.modalita = 'amichevole'">Amichevole</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -228,7 +230,7 @@ export default {
|
|||||||
return null
|
return null
|
||||||
},
|
},
|
||||||
isPartitaFinita() {
|
isPartitaFinita() {
|
||||||
if (!this.setVintoTeam) return false
|
if (!this.setVintoTeam || this.state.modalitaPartita === 'amichevole') return false
|
||||||
const setsToWin = this.state.modalitaPartita === '2/3' ? 2 : 3
|
const setsToWin = this.state.modalitaPartita === '2/3' ? 2 : 3
|
||||||
return this.set[this.setVintoTeam] + 1 >= setsToWin
|
return this.set[this.setVintoTeam] + 1 >= setsToWin
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ export function checkVittoria(state) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function checkVittoriaPartita(state) {
|
export function checkVittoriaPartita(state) {
|
||||||
|
if (state.modalitaPartita === 'amichevole') return false
|
||||||
const setsToWin = state.modalitaPartita === "2/3" ? 2 : 3
|
const setsToWin = state.modalitaPartita === "2/3" ? 2 : 3
|
||||||
const sv = setVinti(state.sp.striscia)
|
const sv = setVinti(state.sp.striscia)
|
||||||
return sv.home >= setsToWin || sv.guest >= setsToWin
|
return sv.home >= setsToWin || sv.guest >= setsToWin
|
||||||
|
|||||||
+25
-10
@@ -1,20 +1,34 @@
|
|||||||
import { networkInterfaces } from 'os'
|
import { networkInterfaces } from 'os'
|
||||||
|
import { readFileSync, existsSync } from 'fs'
|
||||||
|
import { execSync } from 'child_process'
|
||||||
|
|
||||||
|
function isWSL() {
|
||||||
|
try {
|
||||||
|
return existsSync('/proc/sys/kernel/osrelease') &&
|
||||||
|
readFileSync('/proc/sys/kernel/osrelease', 'utf8').toLowerCase().includes('microsoft')
|
||||||
|
} catch { return false }
|
||||||
|
}
|
||||||
|
|
||||||
export function getNetworkIPs() {
|
export function getNetworkIPs() {
|
||||||
|
if (isWSL()) {
|
||||||
|
try {
|
||||||
|
const out = execSync(
|
||||||
|
'powershell.exe -NoProfile -Command "Get-NetIPAddress -AddressFamily IPv4 | Select-Object -ExpandProperty IPAddress"',
|
||||||
|
{ timeout: 3000 }
|
||||||
|
)
|
||||||
|
return out.toString().trim().split('\n')
|
||||||
|
.map(s => s.trim())
|
||||||
|
.filter(ip => ip && !ip.startsWith('127.') && !ip.startsWith('169.254.') && !ip.startsWith('172.'))
|
||||||
|
} catch { return [] }
|
||||||
|
}
|
||||||
|
|
||||||
const nets = networkInterfaces()
|
const nets = networkInterfaces()
|
||||||
const networkIPs = []
|
const networkIPs = []
|
||||||
|
|
||||||
for (const name of Object.keys(nets)) {
|
for (const name of Object.keys(nets)) {
|
||||||
for (const net of nets[name]) {
|
for (const net of nets[name]) {
|
||||||
if (net.family === 'IPv4' &&
|
if (net.family === 'IPv4' && !net.internal) networkIPs.push(net.address)
|
||||||
!net.internal &&
|
|
||||||
!net.address.startsWith('172.17.') &&
|
|
||||||
!net.address.startsWith('172.18.')) {
|
|
||||||
networkIPs.push(net.address)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return networkIPs
|
return networkIPs
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -26,9 +40,10 @@ export function printServerInfo(port = 3000) {
|
|||||||
console.log(` Controller: http://127.0.0.1:${port}/controller`)
|
console.log(` Controller: http://127.0.0.1:${port}/controller`)
|
||||||
|
|
||||||
if (networkIPs.length > 0) {
|
if (networkIPs.length > 0) {
|
||||||
console.log(`\n Controller da dispositivi remoti:`)
|
console.log(`\n Da dispositivi remoti:`)
|
||||||
networkIPs.forEach(ip => {
|
networkIPs.forEach(ip => {
|
||||||
console.log(` http://${ip}:${port}/controller`)
|
console.log(` Display: http://${ip}:${port}/display`)
|
||||||
|
console.log(` Controller: http://${ip}:${port}/controller`)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user