# slartibartfass2/dunetowerdefense architecture

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

- Interactive diagram: https://gitdiagram.com/slartibartfass2/dunetowerdefense
- Repository: https://github.com/slartibartfass2/dunetowerdefense

## Overview

##### Main Components
- Core Module:
- Contains the game’s logic and assets.
- Houses packages for various aspects of the game including game state (GameHandler, GamePhase), asset management (AssetLoader and related classes), entity definitions (towers, hostile units, portals, etc.), game screens (MainMenuScreen, GameScreen, CreditsScreen, etc.), HUD components (ToolBar, TowerSelectButton, etc.), math utilities (Vector2, Vector3, DuneTDMath), pathfinding logic, configuration (Configuration class), saving functionality (SaveGame), and more.
- Desktop Module:
- Provides the platform-specific entry point.
- Contains the DesktopLauncher that bootstraps the game (likely initializes resources and starts the core game loop).
- Assets Directory:
- Configuration & Build Tools:
- Files such as build.gradle, gradle.properties, settings.gradle and various checkstyle configurations that help define and enforce the build and coding standards.
- Testing & Resources:
- A complete test suite under core/src/test which validates functional components (game logic, entity behavior, pathfinding, etc.).

##### Key Relationships and Interactions
- The Desktop Launcher (in the desktop module) acts as the entry point:
- It initializes the game by creating an instance of the core game and passing configuration (from config files and property files).
- The Core Engine:
- The GameHandler coordinates the overall game loop, delegating responsibilities such as state management, invoking inputs (using listeners under screens/listeners), and rendering screens.
- Game screens (like Main Menu, Game Screen, Credits Screen, etc.) respond to user input and update HUD components.
- Asset management is performed through dedicated loaders that read and process data from the assets folder.
- Entities and Controllers:
- The game entities (towers, hostile units, portals) are managed via controllers (EntityController, HostileUnitController, etc.).
- Pathfinding and game math utilities (the math and vectors packages) help drive in-game movement and collision.
- Configuration:
- A centralized configuration (configuration objects) controls game settings, making it easier to adjust parameters such as screen resolutions (as noted in the README) and other game mechanics.
- Testing:
- The test packages illustrate a commitment to quality, with unit tests ensuring that controllers, game state transitions, and utility functions perform correctly.

##### Architectural Patterns and Design Principles
- Separation of Concerns:
- There’s a clear demarcation between the game’s core logic (inside the core module) and the platform-specific startup (in the desktop module).
- Modular Structure:
- The game is divided among assets, game logic, UI handling, input processing, and utility functions (e.g., pathfinding, math), which makes maintenance and possible future extensions easier.
- MVC-like Behavior (or a variant):
- GameScreens and HUD classes handle presentation.
- GameHandler and controllers manage the game’s logic and state.
- Asset loaders, configuration files, and entity classes serve as the model.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global Components
    DLA["Desktop Launcher"]:::desktop
    CA["Core Game Engine"]:::core
    AR["Assets Repository"]:::assets
    CB["Configuration & Build Tools"]:::config
    TS["Test Suite"]:::test

    %% Core Game Engine Sub-components
    subgraph "Core Game Engine"
        GH["Game Loop (GameHandler)"]:::core
        SC["Screens (MainMenu, GameScreen, Credits)"]:::core
        HL["HUD & Input Listeners"]:::core
        EC["Entities & Controllers"]:::core
        AM["Asset Manager"]:::core
        GU["Game Utilities (Math, Vectors, Pathfinding)"]:::core
        CM["Configuration Management"]:::core
    end

    %% Relationships between Components
    DLA -->|"initializes"| GH
    GH -->|"updates"| SC
    HL -->|"sendsEventsTo"| GH
    EC -->|"manages"| AR
    AR -->|"suppliesAssetsTo"| AM
    CM -->|"loadsSettingsFor"| GH
    EC -->|"supports"| HL
    GU -->|"assists"| EC

    CB -->|"providesParamsTo"| CM
    TS -->|"validates"| CA

    %% Click Events
    click DLA "https://github.com/slartibartfass2/dunetowerdefense/blob/main/desktop/src/io/swapastack/dunetd/desktop/DesktopLauncher.java"
    click CA "https://github.com/slartibartfass2/dunetowerdefense/tree/main/core"
    click AR "https://github.com/slartibartfass2/dunetowerdefense/tree/main/core/assets"
    click CB "https://github.com/slartibartfass2/dunetowerdefense/blob/main/core/src/io/swapastack/dunetd/config/Configuration.java"
    click TS "https://github.com/slartibartfass2/dunetowerdefense/tree/main/core/src/test"

    %% Styles
    classDef desktop fill:#ADD8E6,stroke:#00008B,stroke-width:2px;
    classDef core fill:#90EE90,stroke:#006400,stroke-width:2px;
    classDef assets fill:#FFD700,stroke:#DAA520,stroke-width:2px;
    classDef config fill:#D8BFD8,stroke:#8A2BE2,stroke-width:2px;
    classDef test fill:#FFB6C1,stroke:#FF69B4,stroke-width:2px;
```
