# captaintouch/captains_stargrid_palmos architecture

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

- Interactive diagram: https://gitdiagram.com/captaintouch/captains_stargrid_palmos
- Repository: https://github.com/captaintouch/captains_stargrid_palmos

## Overview

##### Main Components
- Game Engine Core – Represented mainly by the source files in the “sauce” directory. This includes:
- Main game loop and initialization (sauce/main.c)
- App coordination logic (sauce/appCoordinator.c/.h)
- Constants and device identification (sauce/constants.h, sauce/deviceInfo.c/.h)
- Game Logic – Encapsulated in the “sauce/game” subfolder which includes:
- Turn-based logic and session management (game.c, gamesession.c, gameActionLogic.c)
- Input processing (inputPen.c/h)
- Movement calculations and CPU logic (movement.c, cpuLogic.c)
- Grid handling (hexgrid.c/h) and minimap (minimap.c/h)
- Various game UI elements like the bottom menu and sprite/pawn actions (bottomMenu and pawnActionMenuViewModel)
- Graphics and Rendering Support – Provided by files like drawhelper.c/h and spriteLibrary.c/h, ensuring that game visuals are handled appropriately.
- Emulator Support – The “emu” directory (with cloudpilotStartDebug.cp) suggests that the project includes an emulator or debugging helper for Palm OS, which should be illustrated as an auxiliary component allowing developers to test and debug the game in a simulated environment.

##### Relationships and Data Flow
- The central game loop (from main.c) communicates with the App Coordinator, which manages state transitions and device-specific adaptations.
- The Game Logic components interact with the Graphics and Rendering components to update visuals based on game state changes.
- Input handling (inputPen) feeds into game session management and logic, updating grid positions, pawn movements, and UI actions.
- The resources are loaded and processed at startup or during runtime; the asset generation scripts indicate a build-time dependency that translates design assets into usable game assets.
- The Emulator component operates as a debug environment that interacts with the game core to simulate Palm OS behavior.

##### Architectural Patterns
- Modular separation – The project is clearly segmented into different modules: core app coordination, game-specific logic, and graphics. This follows principles of separation of concerns.
- Layered architecture – There is a separation between the input and logic layers (handling game actions and rules) and the presentation/rendering layer (drawing the grid, sprites, UI).
- Build/Resource pipeline – The presence of custom scripts for resource generation suggests a build-time process that converts raw assets into deployable formats.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Game Engine Core
    subgraph "Game Engine Core"
        GML["Main Game Loop & Initialization"]:::core
        AC["App Coordinator"]:::core
        CDI["Constants & Device Info"]:::core
    end

    %% Game Logic
    subgraph "Game Logic"
        TLS["Turn Logic & Session Management"]:::logic
        IP["Input Processing"]:::logic
        MCL["Movement & CPU Logic"]:::logic
        GM["Grid & Minimap"]:::logic
        UIC["UI Components"]:::logic
    end

    %% Graphics & Rendering
    subgraph "Graphics & Rendering"
        DH["Draw Helper"]:::graphics
        SL["Sprite Library"]:::graphics
    end

    %% Resources Integration
    subgraph "Resource Integration"
        GA["Graphic Assets"]:::resources
        GB["Generate Bitmaps Script"]:::resources
        GR["Generate Resource File Script"]:::resources
    end

    %% Emulator Support
    EM["Emulator Support"]:::emulator

    %% Relationships
    GML -->|"initiates"| AC
    AC -->|"coordinates"| TLS
    IP -->|"triggers"| TLS
    TLS -->|"updates"| GM
    TLS -->|"processes"| MCL
    GM -->|"renders"| DH
    GM -->|"renders"| SL
    UIC -->|"updates UI"| SL
    AC -->|"updates visuals"| DH
    GA -->|"supplies assets"| DH
    GA -->|"supplies assets"| SL
    GB -->|"generates"| GA
    GR -->|"generates"| GA
    EM -->|"debugs"| GML

    %% Styles
    classDef core fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef logic fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef graphics fill:#FFD700,stroke:#000,stroke-width:2px;
    classDef resources fill:#DA70D6,stroke:#000,stroke-width:2px;
    classDef emulator fill:#FF7F7F,stroke:#000,stroke-width:2px;

    %% Click Events for Game Engine Core
    click GML "https://github.com/captaintouch/captains_stargrid_palmos/blob/master/sauce/main.c"
    click AC "https://github.com/captaintouch/captains_stargrid_palmos/blob/master/sauce/appCoordinator.c"
    click CDI "https://github.com/captaintouch/captains_stargrid_palmos/blob/master/sauce/constants.h"

    %% Click Events for Game Logic
    click TLS "https://github.com/captaintouch/captains_stargrid_palmos/blob/master/sauce/game/game.c"
    click IP "https://github.com/captaintouch/captains_stargrid_palmos/blob/master/sauce/game/inputPen.c"
    click MCL "https://github.com/captaintouch/captains_stargrid_palmos/blob/master/sauce/game/movement.c"
    click GM "https://github.com/captaintouch/captains_stargrid_palmos/blob/master/sauce/game/hexgrid.c"
    click UIC "https://github.com/captaintouch/captains_stargrid_palmos/blob/master/sauce/game/bottomMenu.c"

    %% Click Events for Graphics & Rendering
    click DH "https://github.com/captaintouch/captains_stargrid_palmos/blob/master/sauce/game/drawhelper.c"
    click SL "https://github.com/captaintouch/captains_stargrid_palmos/blob/master/sauce/game/spriteLibrary.c"

    %% Click Events for Resources Integration
    click GA "https://github.com/captaintouch/captains_stargrid_palmos/tree/master/resources"
    click GB "https://github.com/captaintouch/captains_stargrid_palmos/blob/master/generateBitmaps.sh"
    click GR "https://github.com/captaintouch/captains_stargrid_palmos/blob/master/generateResourceFile.sh"

    %% Click Event for Emulator Support
    click EM "https://github.com/captaintouch/captains_stargrid_palmos/blob/master/emu/cloudpilotStartDebug.cp"
```
