# 4d4mszweda/wizardsofcode architecture

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

- Interactive diagram: https://gitdiagram.com/4d4mszweda/wizardsofcode
- Repository: https://github.com/4d4mszweda/wizardsofcode

## Overview

##### Main Components
- Game Engine & Core: At the core, the project is powered by Godot (evidenced by the project.godot file). All scenes (.tscn) and scripts (.gd) ultimately run within the Godot engine’s framework.
- Gameplay Scenes and Modules: The project is modularized into multiple gameplay scenes found in the “scenes” folder. Key subdirectories include:
– Battle (scenes/battle): Contains the battle logic and scene.
– Card UI (scenes/card_ui & script_templates): Manages the card mechanics and visual states (with additional support from “characters/warrior/cards” for card functionalities).
– Map & Environment (scenes/map): Contains the game’s map and procedural generation logic.
– Player & Enemy: The “scenes/player” and “scenes/enemy” directories (plus the “enemies” folder with specific enemy types) encapsulate the actor behaviors and AI.
– Additional game screens: For rewards (battle_rewards), shop (scenes/shop), therapy, treasure, and various UI panels (scenes/ui).
- Custom Resources & Data: The “custom_resources” folder bundles key scripts defining gameplay data types like cards, battle stats, character stats, and effects.
- Global Services: The “global” folder contains shared functionalities (event handling, sound and music players, screen shaker, etc.) that are accessible throughout the application.
- Assets/Media: The “art” folder holds various audio files, shader, and visual assets.

##### Relationships and Interactions
- Gameplay Modules: Indicate that during battles the Battle Scene interacts with the Card UI, which in turn utilizes card scripts (from both characters and custom_resources) to determine player actions.
- Global Event Handling: Connect both the battle scenes and UI screens to the Global Services which manage events, sound effects, and music (global/events.gd, global/music_player.tscn).
- Data Flow: Show that custom resource scripts (in custom_resources) feed into both gameplay logic (in battles, characters, enemies) and UI representation (in scenes/card_ui and scenes/ui).

##### Architectural Patterns
- Modular Scene-based Architecture: Each major game feature is encapsulated in its own scene, supporting Godot’s node-based design. Indicate clear boundaries between UI, gameplay logic, and asset management.
- Reusable Components: The use of custom resources (e.g., card.gd, battle_stats.gd) and script templates (in script_templates) suggests a design that favors reusability and extensibility.
– Presentation Layer (UI scenes, card visualization, main menu, etc.),
– Business/Game Logic (battle scenes, enemy AI, run mechanics),
– Data Layer (custom resources and configuration like *.tres files),
– Global Utilities (event management, sound, and music players).

##### Relevant Technologies and Frameworks
- Godot Engine: This is the backbone for the entire project.
- GDScript: Most logic is implemented using GDScript (.gd files) evident from the scripts across various modules.
- Godot Scenes & Nodes: The extensive use of scenes (.tscn files) highlights a node-based design approach.

##### Final Advice
- Then, within each module, break down key components (e.g., in Battle, highlight the battle scene, battle stats resources, and enemy controllers).
- Be meticulous with connecting lines to illustrate how these systems interact, making sure you capture both one-to-many relationships and data flow directions.

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["Godot Engine Core"]:::core

    subgraph "Godot Scenes"
        subgraph "Battle System"
            BS1["Battle Gameplay Logic"]:::logic
            BS2["Battle Data/Resources"]:::data
            BS1 -->|"uses"| BS2
        end
        subgraph "Card UI Module"
            CUI1["Visual & Interaction Logic"]:::ui
            CUI2["Card State Management"]:::ui
            CUI3["Card Script Templates"]:::data
            CUI4["Card Data"]:::data
            CUI1 -->|"triggers"| CUI2
            CUI1 -->|"references"| CUI3
            CUI1 -->|"updates"| CUI4
        end
        subgraph "Map & Environment"
            ME1["Map Scene & Generation"]:::logic
        end
        subgraph "Player & Enemy"
            PE1["Player Components"]:::logic
            PE2["Enemy Components"]:::logic
            PE1 -->|"interacts"| PE2
        end
        subgraph "Additional Game Screens/UI"
            UI1["Battle Rewards"]:::ui
            UI2["Shop Screen"]:::ui
            UI3["Therapy & Treasure Scenes"]:::ui
            UI4["Various UI Panels"]:::ui
        end
    end

    CR["Custom Resources & Data"]:::data
    GS["Global Services"]:::global
    AM["Assets/Media"]:::assets

    %% Connections from Core to Scenes
    A -->|"loads"| BS1
    A -->|"loads"| CUI1
    A -->|"loads"| ME1
    A -->|"loads"| PE1
    A -->|"loads"| UI1

    %% Data flow from Custom Resources
    CR -->|"feeds"| BS1
    CR -->|"feeds"| CUI1
    CR -->|"feeds"| PE1
    CR -->|"feeds"| PE2

    %% Global Services connections
    BS1 -->|"events"| GS
    CUI1 -->|"events"| GS
    ME1 -->|"events"| GS
    PE1 -->|"events"| GS
    PE2 -->|"events"| GS
    UI1 -->|"events"| GS

    %% Assets fed into Global Services
    AM -->|"supplies"| GS

    %% UI interactions within scenes
    CUI1 -->|"updates"| UI4
    UI1 -->|"navigates"| UI4

    %% Class Definitions
    classDef core fill:#ffccff,stroke:#333,stroke-width:2px;
    classDef ui fill:#add8e6,stroke:#0000ff,stroke-width:2px,rx:5,ry:5;
    classDef logic fill:#90ee90,stroke:#008000,stroke-width:2px,stroke-dasharray: 5 5;
    classDef data fill:#ffcc99,stroke:#ffa500,stroke-width:2px;
    classDef global fill:#dda0dd,stroke:#800080,stroke-width:2px,stroke-dasharray: 2 2;
    classDef assets fill:#ffff99,stroke:#cccc00,stroke-width:2px;

    %% Click Events
    click A "https://github.com/4d4mszweda/wizardsofcode/blob/main/project.godot"
    click BS1 "https://github.com/4d4mszweda/wizardsofcode/blob/main/scenes/battle/battle.tscn"
    click BS2 "https://github.com/4d4mszweda/wizardsofcode/tree/main/battles/"
    click CUI1 "https://github.com/4d4mszweda/wizardsofcode/blob/main/scenes/card_ui/card_ui.tscn"
    click CUI2 "https://github.com/4d4mszweda/wizardsofcode/blob/main/scenes/card_ui/card_state_machine.gd"
    click CUI3 "https://github.com/4d4mszweda/wizardsofcode/blob/main/script_templates/Node/card_template.gd"
    click CUI4 "https://github.com/4d4mszweda/wizardsofcode/tree/main/characters/warrior/cards"
    click ME1 "https://github.com/4d4mszweda/wizardsofcode/blob/main/scenes/map/map.tscn"
    click PE1 "https://github.com/4d4mszweda/wizardsofcode/blob/main/scenes/player/player.tscn"
    click PE2 "https://github.com/4d4mszweda/wizardsofcode/blob/main/scenes/enemy/enemy.tscn"
    click UI1 "https://github.com/4d4mszweda/wizardsofcode/blob/main/scenes/battle_rewards/battle_rewards.tscn"
    click UI2 "https://github.com/4d4mszweda/wizardsofcode/blob/main/scenes/shop/shop.tscn"
    click UI3 "https://github.com/4d4mszweda/wizardsofcode/blob/main/scenes/therapy/therapy.tscn"
    click UI4 "https://github.com/4d4mszweda/wizardsofcode/tree/main/scenes/ui"
    click CR "https://github.com/4d4mszweda/wizardsofcode/tree/main/custom_resources"
    click GS "https://github.com/4d4mszweda/wizardsofcode/tree/main/global"
    click AM "https://github.com/4d4mszweda/wizardsofcode/tree/main/art"
```
