# rickyc0/dnd-game architecture

> Architecture diagram of the GitHub repository rickyc0/dnd-game, 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/rickyc0/dnd-game
- Repository: https://github.com/rickyc0/dnd-game

## Overview

##### Main Components – Break down the project into its key functional areas
- Game Engine: Located in “components/GameEngine”, this is the central piece that manages the game loop, state transitions, input handling, and screen management (MainMenu, GameScreen, OptionsScreen, etc.). It also interfaces with the AssetManager for loading audio, images, and configuration data.
- Characters Module: The “components/Characters” folder implements various character types with builders (NimbleBuilder, TankBuilder, BullyBuilder) and director/observer patterns (CharacterDirector, CharacterObserver) that construct and monitor character behavior.
- Items and ItemContainers: The “components/Items” and “components/ItemContainers” directories define various equipable items (Armor, Weapon, Belt, Ring, etc.) and containers (Backpack, TreasureChest, WornItems) for managing inventory.
- Maps and Map-Related Components: Within “components/Maps” the game’s spatial and level data are managed using maps, doors, levers, pillars, etc. A separate “SavedMaps” directory holds JSON representations of maps.
- Functionalities: Found in “components/Functionalities”, these provide supporting algorithms such as dice rolling (the “Dice” component), likely used for random events or combat.
- Logging: The “components/Log” folder implements an observer pattern to handle debugging and real-time logging events.
- Assets: The “assets” directory holds non-code resources such as audio files, fonts, and images required for game visuals and sound.
- Documentation & Build System: With files like CMakeLists.txt and Doxyfile, there’s an emphasis on automated builds and generated documentation—helpful when integrating with development tools.

##### Relationships/Interactions
- The Game Engine acts as the central coordinator. It uses state patterns (State, StateMachine) to transition between states such as Main Menu, Character Creator, Map Editor, and in-game levels.
- Within the game loop, the Engine directs calls to the InputManager (for key/button presses) and then updates/refreshes the appropriate screen (GameScreen, WelcomeScreen, etc.).
- The Characters module is created using the Builder and Director patterns. The Engine calls the CharacterCreator and, through the appropriate builder (e.g., NimbleBuilder), constructs player or non-player characters. Observers monitor changes and update the Log.
- The Items, ItemContainers, and Map modules interact seamlessly – items can be placed within containers that characters can equip, and maps are loaded/edited and integrated via MapLoader/MapEditor.
- The AssetManager provides a single point of resource access for all screens and modules.

##### Architectural Patterns and Design Principles
- Separation of Concerns: Each component/category (Characters, Items, Maps, Log, etc.) is encapsulated in its own folder to keep functionality modular.
- Use of Design Patterns: The Builder pattern (for creating various character types), Observer pattern (for monitoring state changes in characters, maps, logs), and State Machine (for navigating game states) are clearly in use.
- Modularity and Extensibility: The clear folder structure (with dedicated directories for various game aspects) shows that new components (e.g., future Map Loader functionality) can be added without major rework.

##### Including Specific Technologies/Frameworks
- CMake (for build configuration)
- Standard C++ libraries and possibly external audio/image libraries (since assets are provided)

##### Specific Elements
- Use of design patterns by noting “Builder Pattern” next to the Characters block, “Observer Pattern” next to Log or MapObserver.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Core Engine Components
    subgraph "Core Engine"
        GE["Game Engine"]:::engine
        IM["Input Manager"]:::module
        SM["State Machine"]:::module
        AM["Asset Manager"]:::module
    end

    %% UI Screens
    subgraph "UI Screens"
        MM["Main Menu"]:::screen
        GS["Game Screen"]:::screen
        OS["Options Screen"]:::screen
    end

    %% Gameplay Modules
    subgraph "Gameplay Modules"
        CHAR["Characters Module\n(Builder Pattern)"]:::module
        ITEMS["Items"]:::module
        CONTAINERS["Item Containers"]:::module
        MAPS["Maps & Map Components"]:::module
        SAVED["Saved Maps (JSON)"]:::data
        DICE["Dice Functionality"]:::module
        LOG["Logging\n(Observer Pattern)"]:::module
    end

    %% Resources
    subgraph "Resources"
        ASSETS["Assets"]:::resource
    end

    %% Documentation & Build System
    subgraph "Docs & Build System"
        CMAKE["CMakeLists.txt"]:::resource
        DOXY["Doxyfile"]:::resource
        DOCSDIR["docs"]:::resource
    end

    %% Relationships / Flows
    GE -->|"processInput"| IM
    GE -->|"stateTransitions"| SM
    GE -->|"loadResources"| AM

    GE -->|"renders"| MM
    GE -->|"renders"| GS
    GE -->|"renders"| OS

    MM -->|"select:CharacterCreator"| CHAR
    MM -->|"select:MapEditor"| MAPS

    GE -->|"createsCharacters"| CHAR
    CHAR -->|"notifies"| LOG

    CHAR -->|"equips"| ITEMS
    ITEMS -->|"storedIn"| CONTAINERS
    CONTAINERS -->|"equips"| CHAR

    GE -->|"managesMaps"| MAPS
    MAPS -->|"load/save"| SAVED

    GE -->|"triggersDiceRoll"| DICE
    DICE -->|"updates"| LOG

    AM -->|"fetches"| ASSETS

    %% Click Events
    click GE "https://github.com/rickyc0/dnd-game/tree/main/components/GameEngine"
    click CHAR "https://github.com/rickyc0/dnd-game/tree/main/components/Characters"
    click ITEMS "https://github.com/rickyc0/dnd-game/tree/main/components/Items"
    click CONTAINERS "https://github.com/rickyc0/dnd-game/tree/main/components/ItemContainers"
    click MAPS "https://github.com/rickyc0/dnd-game/tree/main/components/Maps"
    click DICE "https://github.com/rickyc0/dnd-game/tree/main/components/Functionalities"
    click LOG "https://github.com/rickyc0/dnd-game/tree/main/components/Log"
    click ASSETS "https://github.com/rickyc0/dnd-game/tree/main/assets"
    click CMAKE "https://github.com/rickyc0/dnd-game/blob/main/CMakeLists.txt"
    click DOXY "https://github.com/rickyc0/dnd-game/tree/main/Doxyfile"
    click DOCSDIR "https://github.com/rickyc0/dnd-game/tree/main/docs"

    %% Styles
    classDef engine fill:#ffcc00,stroke:#333,stroke-width:2px;
    classDef module fill:#99ccff,stroke:#333,stroke-width:2px;
    classDef screen fill:#ccffcc,stroke:#333,stroke-width:2px;
    classDef resource fill:#ff9999,stroke:#333,stroke-width:2px;
    classDef data fill:#d9d9d9,stroke:#333,stroke-width:2px;
```
