<aside> 💡 RhythmCore is the central framework for rhythm game logic in Magic Tiles Core, providing state machine management, tile lifecycle, scoring systems, and timing synchronization. It uses a 15-state machine to manage game flow from initialization through gameplay, death/revival, and cleanup.

</aside>

🏗️ Architecture Overview

graph TB
    RhythmContext[RhythmContext<br/>Central Coordinator] --> RhythmGame[RhythmGame<br/>Game Controller]
    RhythmContext --> RhythmConfig[RhythmConfig<br/>Settings ScriptableObject]
    RhythmContext --> RhythmMatch[RhythmMatch<br/>Scoring System]
    RhythmContext --> StateMachine[RhythmStateMachine<br/>State Flow Manager]
    
    RhythmGame --> TileContext[TileContext<br/>Tile State & Data]
    TileContext --> RhythmTile[RhythmTile<br/>Visual Tile Component]
    
    RhythmTile --> RhythmTileHandler[RhythmTileHandler<br/>Tile Behavior Handler]
    RhythmTile --> BaseTileInput[BaseTileInput<br/>Input Component]
    BaseTileInput --> IInputHandler[IInputHandler<br/>Input Interface]
    
    RhythmContext -.->|Events| RhythmGame
    RhythmContext -.->|Pool Management| RhythmTile
    RhythmContext -.->|Audio Sync| RhythmGame
    
    classDef core fill:#e3f2fd
    classDef tile fill:#f3e5f5
    classDef system fill:#fff3e0
    
    class RhythmContext,RhythmGame core
    class TileContext,RhythmTile,RhythmTileHandler tile
    class RhythmConfig,RhythmMatch,StateMachine system

RhythmContext - Central Coordinator

RhythmGame - Game Controller

RhythmTile - Visual Component

TileContext - Data Bridge

📊 State Machine

graph TB
    A[GAME_NONE]
    
    subgraph init["Initialization"]
    B[GAME_INITED]
    C[GAME_SONG_LOADED]
    D[GAME_PREPARE]
    end
    
    E[GAME_READY]
    
    subgraph play["GAME PLAY"]
    F[GAME_START]
    G[GAME_PLAY]
    H[GAME_PAUSE]
    I[GAME_DIE]
    J[GAME_REWIND]
    K[GAME_REVIVE]
    L[GAME_END]
    M[GAME_SHUTDOWN]
    end
    
    A --> B --> C --> D --> E --> F --> G
    G --> H --> G
    G --> I --> J --> K --> G
    G --> L --> M
    I --> L
    
    classDef init fill:#e3f2fd
    classDef gameplay fill:#c8e6c9
    classDef death fill:#ffcdd2
    classDef end1 fill:#fff3e0
    
    class A,B,C,D,E,F init
    class G,H gameplay
    class I,J,K death
    class L,M end1

State Categories

State Transitions

🔄 Tile Lifecycle

graph LR
    A[TileContext Created]
    B[AttachView]
    
    subgraph init["RhythmTile Callback"]
    direction TB
    C[OnAttach]
    F[RefreshTileStatus<br/>None, Progress, Miss / End]
    G[OnDetach]
    end
    
    H[RemoveView]
    
    A --> B --> C --> F --> G --> H
    
    classDef creation fill:#e3f2fd
    classDef active fill:#c8e6c9
    classDef cleanup fill:#fff3e0
    
    class A,B,C creation
    class C,F,G active
    class H cleanup

Lifecycle Phases

Tile Status

Object Pooling

🚀 Implementation Flow

High-level flow of implementing a rhythm game:

graph TB
    A[Create Game Class<br/>Extend RhythmGame] --> B[Create Tile Class<br/>Extend RhythmTile]
    B --> C[Create Config Asset<br/>RhythmConfig ScriptableObject]
    C --> D[Setup Pools<br/>Tile & VFX PoolGroups]
    D --> E[Build Scene<br/>Game Object + UI]
    E --> F[Load Song<br/>JSON Data]
    F --> G[Initialize<br/>context.Init]
    G --> H[Start Game<br/>State Transitions]
    H --> I[Gameplay Loop<br/>Spawn/Update/Input]
    
    classDef setup fill:#e3f2fd
    classDef runtime fill:#fff3e0
    
    class A,B,C,D,E setup
    class F,G,H,I runtime

Initialization Sequence