Commit Graph

12 Commits

Author SHA1 Message Date
Alexander Doerflinger
939b0425b0 Added rudimentary "Bust" Animation 2026-02-03 10:38:54 +01:00
Alexander Doerflinger
cd0ee3ed4d Fixed the Day/Night Mode handling in the app 2026-02-03 09:21:42 +01:00
Alexander Doerflinger
689bf2808a Added a Player stats view to the GameResult
Currently only showing the stats of the winning player and also only the overall stats, has to be improved to show stats of all players and also only the stats of the match, not the overall one.
2026-02-02 14:54:06 +01:00
Alexander Doerflinger
5e627aa50c feat: Implement comprehensive player statistics with hit distribution heatmap
This commit introduces a complete statistics tracking and visualization system for the Oche Companion darts app, addressing multiple race condition issues and enhancing user experience with audio/vibration feedback controls.

MAJOR FEATURES:

Statistics & Database (Breaking Changes)
- Upgraded Room database from v10 to v12 with destructive migration
- Added hit distribution map (Map<String, Integer>) to Statistics entity
- Implemented HitDistributionConverter with Gson for Map<->JSON persistence
- Registered TypeConverter at database level for automatic conversion
- Expanded Statistics entity to track:
  * Scoring milestones (60+, 100+, 140+, 180)
  * First 9 darts average (starting consistency metric)
  * Checkout statistics (successful finishes, highest checkout)
  * Double-out attempt tracking (success/miss rates)
  * Hit distribution for heat map visualization
  * Matches played counter

GameActivity Enhancements
- Added DartHit inner class to track baseValue and multiplier per dart
- Implemented parallel tracking with mCurrentTurnDartHits list
- Created recordTurnHitsToStatistics() for hit distribution updates
- Added trackDoubleAttempt() for double-out success/failure recording
- Added incrementMatchesPlayed() called on match completion
- Fixed checkout value calculation (final dart, not full turn score)
- Fixed bust tracking (addMissedDarts instead of saveDartsThrown)
- Renamed Statistics getters/setters for consistency:
  * dartsThrown -> totalDartsThrown
  * overallPointsMade -> totalPoints
  * doubleOutsTargeted -> totalDartsAtDouble

CRITICAL BUG FIXES:

Race Condition Resolution
- Fixed list clearing race: Pass copies (new ArrayList<>) to background threads
- Fixed database race: Added per-player synchronization locks (mPlayerStatsLocks HashMap)
- Implemented double synchronized block pattern:
  1. synchronized(mPlayerStatsLocks) to get/create player lock
  2. synchronized(lock) to protect entire READ-MODIFY-WRITE operation
- Allows concurrent updates for different players while preventing data corruption

User Feedback System
- Added audio/vibration feedback toggle preferences
- Implemented SharedPreferences reading in onResume()
- Added conditional checks (mIsAudioEnabled, mIsVibrationEnabled) throughout
- Created preference UI with toggle buttons and dynamic icons
- Added Day/Night auto mode with mutual exclusion logic

Visualization Components
- Created HeatmapView custom view extending View
- Implements dartboard rendering with Canvas path calculations
- Color interpolation from cold (faded) to hot (volt green)
- Splits board into concentric rings: doubles, outer singles, triples, inner singles
- Added TestActivity for heatmap development/debugging
- Added navigation from MainMenuActivity title click to TestActivity

UI/UX Improvements
- Added vector drawables for audio/vibration states (on/off)
- Enhanced preferences screen with categorized sections
- Improved settings fragment with preference interaction logic
- Added Gson dependency (v2.13.2) for JSON serialization

Code Quality
- Added comprehensive JavaDoc to all new Statistics methods
- Made all method parameters final for immutability
- Added detailed logging for statistics operations
- Improved error handling with try-catch blocks in background threads

TECHNICAL NOTES:
- Database migration is DESTRUCTIVE (all data lost on schema change)
- Per-player locks enable parallel statistics updates across players
- Hit distribution keys use format: "t20", "d16", "s5", "sb", "db"
- Heatmap normalizes weights against max hits for consistent coloring
- Statistics now tracks 15+ distinct performance metrics

TESTING RECOMMENDATIONS:
- Verify hit distribution persists correctly across matches
- Test concurrent multi-player statistics updates
- Confirm checkout values reflect final dart, not turn total
- Validate milestone counters increment accurately
- Test heatmap visualization with varied hit patterns
2026-02-02 14:27:14 +01:00
Alexander Doerflinger
60e707b9f6 Fixed animation, fixed UI 2026-01-30 14:43:24 +01:00
Alexander Doerflinger
3fc5966e40 Added Animation and Sound for Game End 2026-01-30 10:29:43 +01:00
Alexander Doerflinger
c2f18d9328 feat: implement comprehensive statistics tracking and refactor checkout engine
BREAKING CHANGE: Database schema updated from v3 to v9 (destructive migration)

Major Features:
- Statistics system: Track player performance (darts, points, matches, double-outs)
- Match state management: ONGOING/COMPLETED/CANCELED with state-based queries
- Settings activity: Day/night mode and standard game mode preferences
- CheckoutEngine refactored to standalone utility class with 1/2/3-dart methods

CheckoutConstants Overhaul:
- Generate all possible double-out combinations (~37,200 routes)
- Intelligent route selection (fewer darts > T20/T19 > higher doubles)
- Store both optimal routes and complete alternatives

GameActivity Enhancements:
- Automatic statistics tracking on turn submission and win
- Career average calculation and database updates
- Fixed race condition with dart value capture

Database Changes:
- Added Statistics entity and StatisticsDao
- Player ID migration: int → long for consistency
- Match entity: added MatchState enum and helper methods
- MatchDao: new state-based query methods

Developer Experience:
- Comprehensive JavaDoc across all new/modified classes
- Test harness for checkout generation validation
- Improved code organization with utils package separation
2026-01-30 08:21:26 +01:00
Alexander Doerflinger
2953a1bf67 Cleaned up code 2026-01-28 15:28:39 +01:00
Alexander Doerflinger
dde11329bf Replacesd magic numbers with constants 2026-01-28 14:14:29 +01:00
Alexander Doerflinger
52a18b40d0 Simplifed JavaDoc, applied coding rules 2026-01-28 14:00:46 +01:00
Alexander Doerflinger
1cc77d6edd Added Readme.md 2026-01-28 12:36:12 +01:00
Alexander Doerflinger
a4a42fc73f Initial Commit 2026-01-28 12:33:38 +01:00