# jxng-min/knight-in-dungeon architecture

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

- Interactive diagram: https://gitdiagram.com/jxng-min/knight-in-dungeon
- Repository: https://github.com/jxng-min/knight-in-dungeon

## Overview

##### Project Type and Purpose
- This is a Unity-based game project with a strong focus on gameplay mechanics (inventory, shop, reinforcement systems) and UI (title, panels, animations).
- Its purpose is to deliver an engaging 2-player arcade environment, featuring various game components such as character equipment, inventory management, shop gacha systems, and reinforcement mechanics.

##### File Structure
- The project’s core is organized under the Assets directory with multiple subfolders:
- Scenes: Holds the game’s primary scenes (e.g., Title.unity).
- Scripts: Split into modules that reflect different game mechanics:
- “Etc” (common controllers such as TitleCtrl and Singleton classes).
- “Inventory”: Handles items, equipment, tooltips, and inventory slot logic.
- “Item”: Manages core item classes, data managers, and uses Scriptable Objects to define equipment assets.
- “Reinforcement”: Contains logic for game reinforcement mechanics.
- “Shop”: Implements the gacha, prize control, and shop logic.
- Prefabs: Contains preconfigured UI elements like inventory and shop slots.
- Animations: Organized for the Title scene, with panels for inventory, shop, reinforcement, upgrade, etc.
- Images, Sounds, Fonts, and Tiles: Provide the assets needed for visuals and audio.
- StreamingAssets: Contains JSON data (e.g., ItemData.json) which likely serves as a runtime configuration/data layer for item definitions.
- ProjectSettings and Package data: Manage Unity’s configuration and dependencies.

- Game Engine & Runtime:
- Unity Engine acts as the central runtime environment where scenes, assets, and scripts are executed.
- Scene Management:
- Title Scene: Entry point and main menu, triggered by TitleCtrl.cs, which transitions to other game states.
- Modules & Managers (within Scripts):
- Object Manager / Singleton Pattern: Centralized management of game objects available to multiple modules.
- Inventory System: Includes classes for InventoryBase, EquipmentInventory, ItemInventory, InventorySlot, and InventoryTooltip; interacts with inventory UI (prefabs and animations).
- Item System: Item.cs and related data managers, using Scriptable Objects as defined in asset folders to load equipment data.
- Shop System: Implements the gacha mechanism (Gacha.cs, GachaSlot.cs, PrizeCtrl.cs) for item acquisition.
- Reinforcement System: Reinforcer.cs controls mechanics for upgrading or “reinforcing” player attributes or equipment.
- UI/Animation Layer:
- Panels for Inventory, Shop, Reinforcement, and Upgrade with associated animations (Open and Close animations and Animation Controllers).
- Toggle controls for switching game states or panels (Game Toggle, Inventory Toggle, etc.).
- Data Layer:
- JSON data in StreamingAssets provides external configuration that the Item Data Manager reads at runtime.

##### Relationships and Interactions
- The Title scene orchestrates transitions to various game systems. For instance, the TitleCtrl.cs may trigger UI panels.
- The Inventory, Shop, and Reinforcement modules communicate with their respective UI elements through prefabs and animation controllers.
- The ItemDataManager uses Scriptable Objects (seen in the “Item/Scriptable Objects” folder) and the JSON file to load item definitions into the game.
- Central managers (using the Singleton pattern) coordinate between modules ensuring that state changes or data updates (like inventory modifications) are reflected across systems.

##### Architectural Patterns and Design Principles
- Modular Design: Each gameplay aspect (inventory, shop, reinforcement) is separated into its own folder with dedicated scripts to promote separation of concerns.
- Use of Scriptable Objects: For data management and decoupling item definitions from code.
- Singleton Pattern: For central object management, ensuring that managers can be accessed globally.
- MVC-Like Separation: While Unity projects tend to mix view and logic, you still see clear separation with UI controllers, data managers, and gameplay logic scripts.
- Asset-Driven Architecture: Large folders for images, animations, and prefabs indicate an approach where assets drive visual and interactive aspects of the game.

## Diagram (Mermaid)

```mermaid
flowchart TD
    UE["Unity Engine"]:::unity

    subgraph "Scene Management"
        TS["Title Scene (Entry Point)"]:::scene
        TC["Title Controller"]:::scene
        subgraph "Core Managers"
            OM["Object Manager"]:::core
            SN["Singleton"]:::core
        end
    end

    subgraph "Game Modules"
        INV["Inventory Module"]:::module
        ITM["Item Module"]:::module
        SHOP["Shop Module"]:::module
        REINF["Reinforcement Module"]:::module
    end

    subgraph "UI/Animation Layer"
        UIP["UI Prefabs"]:::ui
        ANIM["Animation Controllers"]:::ui
    end

    subgraph "Data Layer"
        JSON["Item Data JSON"]:::data
        SO_ITEM["Scriptable Objects (Item)"]:::data
        SO_SHOP["Scriptable Objects (Shop)"]:::data
    end

    UE -->|"initializes"| TS
    TS -->|"triggers"| TC
    TC -->|"uses"| OM
    TC -->|"uses"| SN
    TC -->|"activates"| INV
    TC -->|"activates"| ITM
    TC -->|"activates"| SHOP
    TC -->|"activates"| REINF

    INV -->|"updates"| UIP
    INV -->|"animates"| ANIM
    ITM -->|"loads"| SO_ITEM
    ITM -->|"reads"| JSON
    SHOP -->|"loads"| SO_SHOP
    SHOP -->|"updates"| UIP
    SHOP -->|"animates"| ANIM
    REINF -->|"updates"| UIP
    REINF -->|"animates"| ANIM

    classDef unity fill:#A0D1DC,stroke:#333,stroke-width:2px;
    classDef scene fill:#F9E79F,stroke:#333,stroke-width:2px;
    classDef core fill:#D7BDE2,stroke:#333,stroke-width:2px;
    classDef module fill:#AED6F1,stroke:#333,stroke-width:2px;
    classDef ui fill:#A3E4D7,stroke:#333,stroke-width:2px;
    classDef data fill:#F5B7B1,stroke:#333,stroke-width:2px;

    click TS "https://github.com/jxng-min/knight-in-dungeon/blob/main/Assets/01. Scenes/Title.unity"
    click TC "https://github.com/jxng-min/knight-in-dungeon/blob/main/Assets/02. Scripts/Etc/TitleCtrl.cs"
    click OM "https://github.com/jxng-min/knight-in-dungeon/blob/main/Assets/02. Scripts/Etc/ObjectManager.cs"
    click SN "https://github.com/jxng-min/knight-in-dungeon/blob/main/Assets/02. Scripts/Etc/Singleton.cs"
    click INV "https://github.com/jxng-min/knight-in-dungeon/tree/main/Assets/02. Scripts/Inventory"
    click ITM "https://github.com/jxng-min/knight-in-dungeon/tree/main/Assets/02. Scripts/Item"
    click SHOP "https://github.com/jxng-min/knight-in-dungeon/tree/main/Assets/02. Scripts/Shop"
    click REINF "https://github.com/jxng-min/knight-in-dungeon/blob/main/Assets/02. Scripts/Reinforcement/Reinforcer.cs"
    click UIP "https://github.com/jxng-min/knight-in-dungeon/blob/main/Assets/03. Prefabs"
    click ANIM "https://github.com/jxng-min/knight-in-dungeon/tree/main/Assets/05. Animations/Title"
    click JSON "https://github.com/jxng-min/knight-in-dungeon/blob/main/Assets/StreamingAssets/ItemData.json"
    click SO_ITEM "https://github.com/jxng-min/knight-in-dungeon/tree/main/Assets/02. Scripts/Item/Scriptable Objects"
    click SO_SHOP "https://github.com/jxng-min/knight-in-dungeon/tree/main/Assets/02. Scripts/Shop/Scriptable Objects"
```
