How runhey/onmyojiautoscript works
Project Type & Purpose
• This is a Python-driven automation tool for the mobile game Onmyoji. It automates an extensive list of game-related tasks (daily tasks, weekly events, various in-game battles, etc.) to “free up” the player’s time.
• The README makes it clear that the system is “one-click managed” and involves both a backend automation engine and a GUI frontend that is built separately (with modern frameworks such as Flutter or QML via FluentUI).
Analyzing the File Structure — Key Components
• Core Engine & Modules:
– The “module” directory contains the automation’s business logic. It is subdivided into:
• “atom”: Low-level actions (click, swipe, image handling, OCR, etc.)
• “base”: Core utilities (decorators, timers, logging, and utility functions)
• “config”: Configuration management (using pydantic-based config files and watchers)
• “device”: Abstraction for device interaction (ADB, droidcast, scrcpy methods, emulator handling, etc.)
• “server”: A backend server component, likely to coordinate tasks, network requests, or service communications.
• “gui”: Houses the GUI bridging component; includes QML resources and FluentUI support – implying the front end can run independently for user interactions.
• “daemon” and “handler”: Background processing and exception handling/logging.
• GUI & Presentation Layer:
– The separate “fluentui” directory (with CMakeLists, QML, and example projects) and the “module/gui” folder clearly indicate the existence of a dedicated user interface layer.
– This layer is responsible for visual presentation, user task management, and providing a platform-independent front end (potentially built with Flutter as mentioned in the README).
• Tasks & Automation Scripts:
– The “tasks” directory contains many subdirectories that provide ready-to-run automation scripts for different game events. Each task folder includes configuration files, asset definitions (images, click positions, etc.) and a “script_task.py” module that integrates with the backend.
• Helper Tools and Deployment:
– The “bin” folder holds precompiled binaries for device interactions (e.g., scrcpy, droidcast, hermit).
– The “deploy” folder offers scripts to assist in deployment and environment setup.
– “dev_tools” includes scripts for maintenance tasks (generating requirements, asset extraction, etc.).
Defining Main Components
• Frontend GUI:
▪ Comprises “module/gui” and “fluentui”.
▪ It accepts user input; displays game state, settings, and task dashboards.
• Automation/Orchestration Engine:
▪ Core logic is in “module” (including submodules like atom, base, config, and daemon).
▪ It schedules and executes tasks, processes configuration files (and uses pydantic models), and manages the global task flow.
• Device Interaction Layer:
▪ Contains “module/device” and integrates with external binaries (from “bin”) such as adb, scrcpy, droidcast.
▪ Manages connections to game devices/emulators and executes touch/click events.
• Task Management Subsystem:
▪ Represented by the “tasks” folder.
▪ Each task (e.g., DailyTrifles, DemonEncounter, GuildBanquet, etc.) acts as a plug-in to the automation engine. They define specific sequences and asset interactions for each game event.
• Server/Communication Module:
▪ Located in “module/server” and possibly invoked via “server.py”.
▪ Handles any networking, remote command control, or inter-process coordination.
• Supporting Components:
▪ Logging, configuration watchers, and utility modules (provided in “module/config”, “module/logger”, etc.)
▪ Deployment and device helper scripts (in “deploy” and “dev_tools”).
Specifying Relationships & Data Flow
• The GUI layer sends user commands and configuration changes to the Core Engine.
• The Core Engine uses the configuration modules to load task parameters and triggers appropriate automation scripts from the “tasks” folder.
• For executing interactions, the engine calls the Device Interaction Layer which uses various helper executables (for click, swipe, OCR, etc.).
• The results and status updates flow back from the Device Layer to the Core Engine and then propagate to the GUI for display.
• The Server module may expose API endpoints or websockets to remotely issue commands or to monitor running tasks.
Architectural Patterns and Relevant Technologies
• Separation of concerns (frontend vs. backend vs. device communication): clearly separate automation, UI presentation, and low-level device handlers.
• Modular plug-in-like system for tasks; easy to add new game-specific features.
• Utilization of familiar frameworks and libraries:
▪ QML and FluentUI for GUI
▪ pydantic for configuration validation
▪ onnxruntime-based OCR (using ppocr-onnx) integrated for AI-assisted tasks
▪ ADB, scrcpy as external tools for device control.