How fate-grand-automata/fga works
Project Overview
• Project Type: Native Android auto-battle application
• Purpose: Automates routine gameplay actions for Fate/Grand Order by capturing the screen, recognizing game elements via OpenCV, and simulating touches through Android’s Accessibility Services.
• Key Technologies: Kotlin (primary language), OpenCV for image matching, MediaProjection for screen capture, and Accessibility Services for automating taps/swipes. The project is divided into several modules such as the main app, libraries (libautomata), preferences/configuration, and script modules.
Main Components
a. User Interface (UI) Module:
• Located mainly in the “app” directory (e.g., ui folder structure with MainActivity, Onboarding, launcher screens, battle config items).
• Responsible for user interactions, configuration screens, and launching the automation service.
b. Automation Service & Core Engine:
• Implements the core automation logic using image recognition and gesture simulation.
• Split across modules:
• “libautomata” – offers low-level automation API (screen capture, image matching, gesture simulation, OCR processing).
• “scripts” – holds automatic action “scripts” for various tasks (AutoBattle, AutoCEBomb, etc.) and modules for game logic, script entry-points, and support selection.
c. Preferences/Configuration Module:
• Found in “prefs” (and editing options in “app/ui/prefs”) to store user configuration, battle config options, preferred support, etc.
• Provides settings management that other modules (like scripts and service modules) reference.
d. Supporting Components:
• MediaProjection: Handles taking screenshots.
• Accessibility Service: Manages UI interactions (taps, swipes).
• Tesseract OCR: There is asset support for trained data in assets/tessdata.
• Fastlane: Deployment/automation scripts (fastlane directory) which can be shown as a continuous integration/deployment pipeline on the side.
• Wiki & Documentation: Included as external support/documentation but not core to functional architecture.
Architectural Relationships and Data Flow
• The UI module (front-end) communicates with the automation/service components through clearly defined interfaces.
• The core engine in libautomata and scripts takes input from MediaProjection (screenshot) and Accessibility Service for executing UI actions.
• Preferences are read by both UI and Automation service to tailor behaviors (e.g., using dependency injection modules, as seen in the “di” folders).
• The automation engine calls out to external libraries (OpenCV, OCR, etc.) for specialized processing.
• User actions flow from UI → Automation Service.
• Screen capture flows from the system’s Media Projection → Automation Service → (then triggers image processing with OpenCV).
• Configuration settings flow from the Preferences module to the UI and service modules.
• Optionally, include a side module or CI/CD pipeline accessory representing the GitHub workflows and fastlane for deployment.