# kerazli/dreamofthekingdom architecture

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

- Interactive diagram: https://gitdiagram.com/kerazli/dreamofthekingdom
- Repository: https://github.com/kerazli/dreamofthekingdom

## Overview

##### Main Components
a. Game Core / Engine – The entire project is built on Unity, so the Unity runtime and its inherent game loop serve as the overall framework.
b. Game Data and Configuration – Managed via the “Assets/GameData” folder (including CardData, CardEffect, Enemy, Events, Map, RoomData, TurnBase, Variable, etc.) along with ScriptableObject definitions in the “Assets/Scripts/Cards/ScriptObject” and related directories.
c. Card System – Located in the “Assets/Scripts/Cards” directory (both MonoBehaviour implementations and ScriptableObject assets). This includes the card definitions, deck management, drag handlers, and UI interactions.
d. Character and Combat – Found in “Assets/Scripts/Character” (for Player, Enemy, and Boss behavior), “Assets/Scripts/EnemyAction,” etc. These manage combat logic, enemy patterns, animations, and other character-specific functionalities.
f. UI Management – The “Assets/Scripts/UI” folder holds panels for gameplay (GamePlayPanel, MenuPanel, GameOverPanel, PickCardPanel, etc.) as well as UXML and USS files under “Assets/UI” for the visual interface.
g. Event System – With “Assets/Scripts/Event” (and its Editor, MonoBehaviour, and ScriptObject components), the game implements an event-driven system (for things like card plays, character state changes, turn notifications, etc.).
h. Animation & Visual Effects – Several directories (Assets/M STUDIO, Assets/Spine, Assets/Plugins/Demigiant/DOTween, and TextMesh Pro) support sophisticated animations, spine rigging, tweening animations, and UI text rendering. This forms the bridge between gameplay events and visual representation.
i. Addressable/Asset Management – The “Assets/AddressableAssetsData” organizes assets that can be dynamically loaded or updated, supporting efficient asset management at runtime.
j. Plugins and External Tools – Integration of DOTween, Spine (for skeletal animations), and TextMesh Pro enhance performance and visuals.

##### Relationships and Interactions
– The central Game Manager (in Assets/Scripts/Manager/GameManager.cs) coordinates overall game flow and communicates with component managers (CardManager, SceneLoadManager, CardLayoutManager, UIManager, etc.).
– The Card System interacts with the UI panels (via PickCardPanel, CardDragHandler) and the Game Data (ScriptableObjects storing card stats and effects) to deliver gameplay.
– The Character and Enemy modules work in tandem with the Event System: character actions trigger events (e.g., new turn events, damage calculations) that are logged and resolved by associated listeners.
– The Room/Map generator connects to the SceneLoadManager to transition between different game states and rooms.
– The Animation and Visual Effects components (using DOTween, Spine assets) are triggered by both the card and character systems to provide visual feedback.
– Asset and Addressable management ensure that resources like card art, animations, and UI assets are loaded efficiently.

##### Architectural Patterns and Design Principles
– Component-Based Design: Using Unity’s MonoBehaviour and ScriptableObjects to isolate logic (for cards, characters, events) helps in modularization.
– Event-Driven Architecture: The event system (with BaseEventListener and EventSO based components) decouples the triggers from responses.
– Manager Pattern: Centralized managers (GameManager, SceneLoadManager, CardManager, etc.) orchestrate interactions across components.
– Data-Driven Design: Extensive use of data assets (ScriptableObjects for CardData, RoomData, MapConfigSO, EnemyActionData, etc.) implies that many game rules and configurations are configurable without code changes.
– Use of External Libraries/Plugins to extend functionality (DOTween for animation tweening, Spine for skeletal animation, TextMesh Pro for UI text, etc.).

##### Detailed Element Inclusions
- “Game Manager” triggering events to “UI Manager” and “Animation Controller”.
- “Card Manager” interfacing with “Player Input” (UI) and “Game Data”.
- “Map/Room Generator” feeding data to the “SceneLoadManager”.
– Additionally, include configuration nodes (such as AddressableAssetsData and ProjectSettings) to show how assets and settings integrate with the runtime.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Core Engine Layer
    subgraph "Core Engine"
        engine["Game Core (Unity Engine)"]:::gameEngine
    end

    %% Managers Layer
    subgraph "Managers"
        gm["Game Manager"]:::manager
    end

    %% Gameplay Modules Layer
    subgraph "Gameplay Modules"
        gd["Game Data & Configuration"]:::gameplay
        cs["Card System"]:::gameplay
        char["Character"]:::gameplay
        enemy["Enemy Action"]:::gameplay
        room["Room/Map Management"]:::gameplay
        event["Event System"]:::gameplay
        addr["Addressable/Asset Management"]:::gameplay
    end

    %% Presentation & UI Layer
    subgraph "Presentation & UI"
        ui1["UI Scripts"]:::ui
        ui2["UI Assets"]:::ui
    end

    %% Animation & Visual Effects Layer
    subgraph "Animation & Visual Effects"
        mstudio["M STUDIO"]:::animation
        spine["Spine"]:::animation
        dotween["DOTween"]:::animation
        tmp["TextMesh Pro"]:::animation
    end

    %% External Tools Layer
    subgraph "External Tools"
        plugins["Plugins"]:::external
    end

    %% Connections
    engine --> gm
    gm --> cs
    gm --> char
    gm --> enemy
    gm --> room
    gm --> event
    gm --> ui1
    gm --> addr

    cs -->|"uses"| gd
    cs -->|"updates"| ui1

    char -->|"triggers"| event
    enemy -->|"triggers"| event

    room -->|"feeds state"| gm

    event -->|"notifies"| ui1
    event -->|"triggers"| dotween

    ui1 -->|"renders"| ui2

    dotween -->|"animates"| cs
    dotween -->|"animates"| char

    spine -->|"animates"| char
    spine -->|"animates"| enemy

    %% External Tools integration
    plugins -->|"supports"| dotween
    plugins -->|"supports"| spine
    plugins -->|"supports"| tmp

    %% Click Events
    click gd "https://github.com/kerazli/dreamofthekingdom/tree/master/Assets/GameData"
    click cs "https://github.com/kerazli/dreamofthekingdom/tree/master/Assets/Scripts/Cards"
    click char "https://github.com/kerazli/dreamofthekingdom/tree/master/Assets/Scripts/Character"
    click enemy "https://github.com/kerazli/dreamofthekingdom/tree/master/Assets/Scripts/EnemyAction"
    click room "https://github.com/kerazli/dreamofthekingdom/tree/master/Assets/Scripts/Rooms"
    click ui1 "https://github.com/kerazli/dreamofthekingdom/tree/master/Assets/Scripts/UI"
    click ui2 "https://github.com/kerazli/dreamofthekingdom/tree/master/Assets/UI"
    click event "https://github.com/kerazli/dreamofthekingdom/tree/master/Assets/Scripts/Event"
    click mstudio "https://github.com/kerazli/dreamofthekingdom/tree/master/Assets/M STUDIO"
    click spine "https://github.com/kerazli/dreamofthekingdom/tree/master/Assets/Spine"
    click dotween "https://github.com/kerazli/dreamofthekingdom/tree/master/Assets/Plugins/Demigiant/DOTween"
    click tmp "https://github.com/kerazli/dreamofthekingdom/tree/master/Assets/TextMesh Pro"
    click addr "https://github.com/kerazli/dreamofthekingdom/tree/master/Assets/AddressableAssetsData"
    click plugins "https://github.com/kerazli/dreamofthekingdom/tree/master/Assets/Plugins"

    %% Styles
    classDef gameEngine fill:#f9c,stroke:#333,stroke-width:2px;
    classDef manager fill:#ccf,stroke:#333,stroke-width:2px;
    classDef gameplay fill:#cfc,stroke:#333,stroke-width:2px;
    classDef ui fill:#fcf,stroke:#333,stroke-width:2px;
    classDef animation fill:#cff,stroke:#333,stroke-width:2px;
    classDef external fill:#ffc,stroke:#333,stroke-width:2px;
```
