Feat: Ajout du glisser-déposer par appui long pour repositionner les impacts de tir
This commit is contained in:
@@ -39,11 +39,11 @@ class AnalysisProvider extends ChangeNotifier {
|
||||
DistortionCorrectionService? distortionService,
|
||||
OpenCVTargetService? opencvTargetService,
|
||||
}) : _detectionService = detectionService,
|
||||
_scoreCalculatorService = scoreCalculatorService,
|
||||
_groupingAnalyzerService = groupingAnalyzerService,
|
||||
_sessionRepository = sessionRepository,
|
||||
_distortionService = distortionService ?? DistortionCorrectionService(),
|
||||
_opencvTargetService = opencvTargetService ?? OpenCVTargetService();
|
||||
_scoreCalculatorService = scoreCalculatorService,
|
||||
_groupingAnalyzerService = groupingAnalyzerService,
|
||||
_sessionRepository = sessionRepository,
|
||||
_distortionService = distortionService ?? DistortionCorrectionService(),
|
||||
_opencvTargetService = opencvTargetService ?? OpenCVTargetService();
|
||||
|
||||
AnalysisState _state = AnalysisState.initial;
|
||||
String? _errorMessage;
|
||||
@@ -109,19 +109,19 @@ class AnalysisProvider extends ChangeNotifier {
|
||||
/// Retourne le chemin de l'image à afficher (corrigée si activée, originale sinon)
|
||||
String? get displayImagePath =>
|
||||
_distortionCorrectionEnabled && _correctedImagePath != null
|
||||
? _correctedImagePath
|
||||
: _imagePath;
|
||||
? _correctedImagePath
|
||||
: _imagePath;
|
||||
|
||||
/// Analyze an image
|
||||
///
|
||||
/// [autoAnalyze] determines if we should run automatic detection immediately.
|
||||
/// If false, only the image is loaded and default target parameters are set.
|
||||
Future<void> analyzeImage(
|
||||
String imagePath,
|
||||
TargetType targetType, {
|
||||
bool autoAnalyze = true,
|
||||
Offset? manualCenter,
|
||||
}) async {
|
||||
String imagePath,
|
||||
TargetType targetType, {
|
||||
bool autoAnalyze = true,
|
||||
Offset? manualCenter,
|
||||
}) async {
|
||||
_state = AnalysisState.loading;
|
||||
_imagePath = imagePath;
|
||||
_targetType = targetType;
|
||||
@@ -375,15 +375,15 @@ class AnalysisProvider extends ChangeNotifier {
|
||||
|
||||
final detectedImpacts = _detectionService
|
||||
.detectImpactsWithOpenCVFromReferences(
|
||||
_imagePath!,
|
||||
_targetType!,
|
||||
_targetCenterX,
|
||||
_targetCenterY,
|
||||
_targetRadius,
|
||||
_ringCount,
|
||||
references,
|
||||
tolerance: tolerance,
|
||||
);
|
||||
_imagePath!,
|
||||
_targetType!,
|
||||
_targetCenterX,
|
||||
_targetCenterY,
|
||||
_targetRadius,
|
||||
_ringCount,
|
||||
references,
|
||||
tolerance: tolerance,
|
||||
);
|
||||
|
||||
if (clearExisting) {
|
||||
_shots.clear();
|
||||
@@ -538,7 +538,7 @@ class AnalysisProvider extends ChangeNotifier {
|
||||
_correctedImagePath = correctedPath;
|
||||
_distortionCorrectionEnabled = true;
|
||||
_imageAspectRatio =
|
||||
1.0; // The corrected image is always square (side x side)
|
||||
1.0; // The corrected image is always square (side x side)
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
@@ -683,7 +683,7 @@ class AnalysisProvider extends ChangeNotifier {
|
||||
/// Exporte l'image et le json vers le backend IA
|
||||
Future<bool> exportToAiBackend() async {
|
||||
if (_imagePath == null || _targetType == null) {
|
||||
_errorMessage = "Impossible d'exporter : image ou type de cible manquant.";
|
||||
_errorMessage = "Impossible d'export : image ou type de cible manquant.";
|
||||
notifyListeners();
|
||||
return false;
|
||||
}
|
||||
@@ -694,7 +694,7 @@ class AnalysisProvider extends ChangeNotifier {
|
||||
: 'analysis_${DateTime.now().millisecondsSinceEpoch}';
|
||||
|
||||
final service = AiExportService(); // Local instanciation for simplicity
|
||||
|
||||
|
||||
_state = AnalysisState.loading;
|
||||
notifyListeners();
|
||||
|
||||
@@ -796,4 +796,23 @@ class AnalysisProvider extends ChangeNotifier {
|
||||
_correctedImagePath = null;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
/// Met à jour la position d'un impact de tir en direct (Glisser-Déposer).
|
||||
void updateShotPosition(String shotId, double newX, double newY) {
|
||||
final index = _shots.indexWhere((s) => s.id == shotId);
|
||||
if (index != -1) {
|
||||
// 1. On calcule dynamiquement le nouveau score de la zone survolée
|
||||
final newScore = _calculateShotScore(newX, newY);
|
||||
|
||||
// 2. On remplace l'ancien impact par le nouveau avec ses coordonnées et son score ajustés
|
||||
_shots[index] = _shots[index].copyWith(x: newX, y: newY, score: newScore);
|
||||
|
||||
// 3. On applique les deux méthodes natives de recalcul de ton application
|
||||
_recalculateScores();
|
||||
_recalculateGrouping();
|
||||
|
||||
// 4. On demande à l'écran de se redessiner en direct
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user