# ducknok/turnbased architecture

> Architecture diagram of the GitHub repository ducknok/turnbased, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ducknok/turnbased
- Repository: https://github.com/ducknok/turnbased

## Overview

##### Project’s Core Components
- Unity Engine & Runtime: Represent the overall Unity engine that provides the underlying framework (rendering, physics, input, asset loading, etc.).
- Game Scenes: Highlight key scenes (found in the “Assets/Scenes” folder, e.g., “SampleScene.unity” and “Player”) that load and run the game.
- Input Management: Specify the “Assets/Input” folder where the InputManager and input actions (Control.inputactions) are defined. This drives player commands.
- Game Assets & Prefabs: Include a container for art and animations (Assets/Animation, Assets/Animator, Assets/Assets, Assets/Prefabs, Assets/Resources) that supply visual, UI, and interactive components.
- Game Logic & State Machines: Emphasize the game’s turn-based combat system with components from “Assets/Script”. For example, you have:
- CombatStateMachine (managing overall turn-based flow)
- EnemyStateMachine and HeroStateMachine (controlling enemy and player behaviors)
- Specific scripts for Attacks (both melee and skills) and DamagePopup
- Managers and Utilities: Include manager scripts from “Assets/Script/Manager” (such as ActionManager, CameraShakeManager, GameAssets, etc.) that encapsulate common game-wide functionality.
- Third-Party Plugins & Libraries: Identify the use of DOTween (found in Assets/Plugins/Demigiant/DOTween) for tweening/animation and TextMesh Pro for text rendering (in Assets/TextMesh Pro). These play key roles in animation and UI delights.

##### Relationships and Interactions
- The Input Management component sends events to the PlayerController (Assets/Script/HeroStateMachine/Player) and through the CombatStateMachine to trigger transitions between game states.
- The State Machines (CombatStateMachine, EnemyStateMachine, HeroStateMachine) interact with each other and with various UI components (GUI items, panels) to update the status of characters and display information (see Assets/Prefabs/GUI).
- The Animation controllers and related prefabs (Assets/Animation, Assets/Animator, Prefabs for characters and attacks) are tied to the visual presentation of actions that are driven by the state machines.
- Manager modules (like ActionManager and CameraShakeManager) work across the game logic to coordinate user actions, animations, and scene transitions.
- Third-party libraries such as DOTween interact through the Manager and Animation components to provide smooth transitions and effects.

##### Architectural Patterns and Design Principles
- State Machine Pattern: Clearly, various state machines drive turn-based combat and enemy/hero behaviors.
- MVC or Component-Based Design: Unity’s approach is naturally component-based. Indicate how scripts (logic) and prefabs (UI/art) interconnect.
- Separation of Concerns: Distinguish clearly between the Input/GUI layer, game logic (combat, state machine), and the visual/animation layers.
- Modular and Extensible Design: The use of separate folders for Attacks, Manager, and State Machines shows a modular strategy.

- Unity Engine (with its Scene, Asset, and ProjectSettings structure)
- DOTween for tweening and animation effects
- TextMesh Pro for advanced text rendering
- Use of Unity’s Input System (with .inputactions file) to handle user inputs

## Diagram (Mermaid)

```mermaid
flowchart TD
    UE["Unity Engine & Runtime"]:::engine
    GS["Game Scenes"]:::scene
    IM["Input Management"]:::input

    UE --> GS
    GS --> IM

    subgraph "Game Logic & State Machines"
        CSM["Combat State Machine"]:::logic
        ESM["Enemy State Machine"]:::logic
        HSM["Hero State Machine"]:::logic
        AS["Attack Scripts"]:::logic
        DP["Damage Popup"]:::logic
    end

    IM -->|"triggers"| HSM
    HSM -->|"initiates"| CSM
    CSM -->|"coordinates with"| ESM
    CSM -->|"executes"| AS
    CSM -->|"displays"| DP

    MU["Managers and Utilities"]:::manager
    CSM -->|"integrates with"| MU

    subgraph "Third-Party Plugins"
        DOT["DOTween"]:::plugin
        TMP["TextMesh Pro"]:::plugin
    end

    MU -->|"utilizes"| DOT
    MU -->|"renders via"| TMP

    subgraph "Game Assets & Prefabs"
        AN["Animation"]:::assets
        AT["Animator"]:::assets
        GA["General Assets"]:::assets
        PF["Prefabs"]:::assets
        RS["Resources"]:::assets
    end

    CSM -->|"updates"| PF
    MU -->|"controls animations"| AN
    AT -->|"drives visuals"| PF

    %% Click Events
    click GS "https://github.com/ducknok/turnbased/tree/main/Assets/Scenes"
    click IM "https://github.com/ducknok/turnbased/tree/main/Assets/Input"
    click CSM "https://github.com/ducknok/turnbased/tree/main/Assets/Script/CombatStateMachine"
    click ESM "https://github.com/ducknok/turnbased/tree/main/Assets/Script/EnemyStateMachine"
    click HSM "https://github.com/ducknok/turnbased/tree/main/Assets/Script/HeroStateMachine"
    click AS "https://github.com/ducknok/turnbased/tree/main/Assets/Script/Attacks"
    click DP "https://github.com/ducknok/turnbased/tree/main/Assets/Script/DamagePopup"
    click MU "https://github.com/ducknok/turnbased/tree/main/Assets/Script/Manager"
    click DOT "https://github.com/ducknok/turnbased/tree/main/Assets/Plugins/Demigiant/DOTween"
    click TMP "https://github.com/ducknok/turnbased/tree/main/Assets/TextMesh Pro"
    click AN "https://github.com/ducknok/turnbased/tree/main/Assets/Animation"
    click AT "https://github.com/ducknok/turnbased/tree/main/Assets/Animator"
    click GA "https://github.com/ducknok/turnbased/tree/main/Assets/Assets"
    click PF "https://github.com/ducknok/turnbased/tree/main/Assets/Prefabs"
    click RS "https://github.com/ducknok/turnbased/tree/main/Assets/Resources"

    %% Style Classes
    classDef engine fill:#ffcccc,stroke:#cc0000,stroke-width:2px;
    classDef scene fill:#ccffcc,stroke:#006600,stroke-width:2px;
    classDef input fill:#ffffcc,stroke:#999900,stroke-width:2px;
    classDef logic fill:#cce5ff,stroke:#003366,stroke-width:2px;
    classDef assets fill:#e6ccff,stroke:#663399,stroke-width:2px;
    classDef manager fill:#ffefd5,stroke:#d2691e,stroke-width:2px;
    classDef plugin fill:#d0e6a5,stroke:#557a2b,stroke-width:2px;
```
