melhorar o calor

This commit is contained in:
2026-03-17 10:35:38 +00:00
parent ec5bdc4867
commit 2a987e517b
4 changed files with 1540 additions and 155 deletions

View File

@@ -8,7 +8,6 @@ class ShotRecord {
final double relativeY;
final bool isMake;
final String playerName;
// 👇 AGORA ACEITA ZONAS E PONTOS!
final String? zone;
final int? points;
@@ -72,7 +71,6 @@ class PlacarController {
Timer? timer;
bool isRunning = false;
// 👇 VARIÁVEIS DE CALIBRAÇÃO DO CAMPO (OS TEUS NÚMEROS!) 👇
bool isCalibrating = false;
double hoopBaseX = 0.088;
double arcRadius = 0.459;
@@ -90,6 +88,7 @@ class PlacarController {
playerStats.clear();
playerNumbers.clear();
playerDbIds.clear();
matchShots.clear(); // Limpa as bolas do último jogo
myFouls = 0;
opponentFouls = 0;
@@ -159,6 +158,19 @@ class PlacarController {
}
_padTeam(oppCourt, oppBench, "Adversário", isMyTeam: false);
// 👇 CARREGA AS BOLINHAS ANTIGAS (MAPA DE CALOR DO JOGO ATUAL) 👇
final shotsResponse = await supabase.from('shot_locations').select().eq('game_id', gameId);
for (var shotData in shotsResponse) {
matchShots.add(ShotRecord(
relativeX: double.parse(shotData['relative_x'].toString()),
relativeY: double.parse(shotData['relative_y'].toString()),
isMake: shotData['is_make'] == true,
playerName: shotData['player_name'].toString(),
zone: shotData['zone']?.toString(),
points: shotData['points'] != null ? int.parse(shotData['points'].toString()) : null,
));
}
isLoading = false;
onUpdate();
} catch (e) {
@@ -282,11 +294,8 @@ class PlacarController {
// 👇 REGISTA PONTOS VINDO DO POP-UP AMARELO (E MARCA A BOLINHA)
// =========================================================================
void registerShotFromPopup(BuildContext context, String action, String targetPlayer, String zone, int points, double relativeX, double relativeY) {
if (!isRunning) {
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('⏳ O relógio está parado! Inicie o tempo primeiro.'), backgroundColor: Colors.red));
return;
}
// 💡 AVISO AMIGÁVEL REMOVIDO. Agora podes marcar pontos mesmo com o tempo parado!
String name = targetPlayer.replaceAll("player_my_", "").replaceAll("player_opp_", "");
bool isMyTeam = targetPlayer.startsWith("player_my_");
bool isMake = action.startsWith("add_");
@@ -331,7 +340,6 @@ class PlacarController {
onUpdate();
}
// MANTIDO PARA CASO USES A MARCAÇÃO CLÁSSICA DIRETAMENTE NO CAMPO ESCURO
void registerShotLocation(BuildContext context, Offset position, Size size) {
if (pendingAction == null || pendingPlayer == null) return;
@@ -388,7 +396,7 @@ class PlacarController {
}
if (is3Pt) return !isInside2Pts;
return isInside2Pts;
return isInside2Pts;
}
void cancelShotLocation() {
@@ -537,8 +545,32 @@ class PlacarController {
await supabase.from('player_stats').insert(batchStats);
}
// 👇 6. GUARDA AS BOLINHAS (MAPA DE CALOR) NO SUPABASE 👇
List<Map<String, dynamic>> batchShots = [];
for (var shot in matchShots) {
String? memberDbId = playerDbIds[shot.playerName];
if (memberDbId != null) {
batchShots.add({
'game_id': gameId,
'member_id': memberDbId,
'player_name': shot.playerName,
'relative_x': shot.relativeX,
'relative_y': shot.relativeY,
'is_make': shot.isMake,
'zone': shot.zone ?? 'Desconhecida',
'points': shot.points ?? (shot.isMake ? 2 : 0),
});
}
}
// Apaga os antigos (para não duplicar) e guarda os novos!
await supabase.from('shot_locations').delete().eq('game_id', gameId);
if (batchShots.isNotEmpty) {
await supabase.from('shot_locations').insert(batchShots);
}
if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('Estatísticas e Resultados guardados com Sucesso!'), backgroundColor: Colors.green));
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('Estatísticas, Mapa de Calor e Resultados guardados com Sucesso!'), backgroundColor: Colors.green));
}
} catch (e) {