# kleingeist37/godot-wang-converter architecture

> Architecture diagram of the GitHub repository kleingeist37/godot-wang-converter, 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/kleingeist37/godot-wang-converter
- Repository: https://github.com/kleingeist37/godot-wang-converter

## Overview

##### Project Type and Purpose
- This project is a conversion tool built with Godot (as evidenced by the project.godot file and numerous .tscn and .gd files). It is designed to convert user-imported tiles into a properly arranged Wang/DualMap TileSet.
- The tool focuses on taking a single tile input (assumed to be pixel perfect) and recreating the texture including steps such as filling borders, handling underlays, and managing alpha tolerances. This makes it primarily a UI-driven utility tool for game asset processing rather than a full-scale application with separate client-server components.

##### Analyzing the File Structure
- Top-Level Files:
- project.godot: Main project configuration for the Godot engine.
- LICENSE, README.md, and configuration files (like export_presets.cfg) indicate standard project metadata and export configurations.
- Directories:
- scenes: Contains various UI scenes, which include:
▪ error_panel (error handling UI component)
▪ texture_coord_button (UI element for texture coordinate manipulation)
▪ tile_type_button (UI component for selecting/processing tile types)
▪ wang_creator (central UI scene responsible for the tile set generation process, including additional scripts like ui_controller.gd and hbox_button_handler.gd)
- models: Contains data constructs (for instance, editor_enums.gd likely holds enumerations that manage editor states or tile types).
- singletons: Holds globally available scripts (editor_signals.gd) which likely facilitate inter-scene communication using Godot's autoload/singleton mechanism.
- sprites: Likely a directory holding graphical assets.

##### Key Components
a. User Interface Modules:
- UI Scenes: Break down the various scenes; include error_panel, texture_coord_button, tile_type_button, and the central wang_creator interface.
- UI Controllers and Handlers: These scripts (like ui_controller.gd and hbox_button_handler.gd in wang_creator) coordinate user interactions.

b. Core Conversion/Processing Logic:
- The conversion process that recreates the tile texture from the first imported tile.
- Logic for handling tile borders (the pixel-checking and alpha tolerance adjustments) likely spread across several scripts.

c. Data Models & Enumerations:
- The models directory (editor_enums.gd) where application-specific constants and enumerations are defined.

d. Global Event Handling:
- Singletons: editor_signals.gd, which likely ensures real-time communication between UI components or triggers conversion processes upon user actions.

e. Asset Management:
- The sprites directory holding tile images and any related assets used during conversion, as well as possibly some resources referenced in the scenes.

##### Relationships and Interactions
- Input Flow:
- User imports a tile image via the wang_creator scene.
- The imported tile is routed through UI controllers where any input configuration (like alpha tolerance factor adjustments) is set via widgets/buttons (texture_coord_button, tile_type_button).
- Processing Flow:
- Once the tile is imported, the conversion logic (possibly embedded in the wang_creator’s scripts) processes the image into a complete tile set using rules defined in the models.
- Singletons (editor_signals.gd) coordinate and signal between components to update the UI with error panels or conversion results.
- Output Flow:
- The newly generated tile set is previewed in real time by the UI, providing feedback through various panels.

##### Architectural Patterns & Design Principles
- Use of Godot’s Scene System: Each UI element is a separate scene (.tscn) promoting modularity. This reflects a component-based design.
- Singleton Pattern: The usage of the “singletons” directory indicates a global event/communication model.
- Separated Concerns: UI handling, conversion logic, and data models are clearly segmented into different directories and files.
- Signal-Based Communication: Likely relying on Godot’s signal system for decoupling UI events from processing logic.

## Diagram (Mermaid)

```mermaid
flowchart TD
    A("User"):::ui

    subgraph "UI Layer"
        WC("Wang Creator UI"):::ui
        UCH("UI Controllers & Handlers"):::ui
        TC("Texture Coordinate Button UI Component"):::ui
        TT("Tile Type Button UI Component"):::ui
        EP("Error Panel UI Component"):::ui
    end

    subgraph "Processing Layer"
        P("Tile Import & Processing Module"):::proc
        CO("Conversion Outcome Preview"):::ui
    end

    subgraph "Data & Global Layer"
        DM("Data Models & Enums"):::data
        GE("Global Event Handler"):::global
        AM("Asset Management"):::asset
    end

    A -->|"initiates"| WC
    WC -->|"handles"| UCH
    WC -->|"includes"| TC
    WC -->|"includes"| TT
    WC -->|"includes"| EP
    WC -->|"triggers"| P
    UCH -->|"signals"| GE
    P -->|"uses"| DM
    P -->|"communicates"| GE
    P -->|"renders"| CO
    WC -->|"loads assets from"| AM
    P -->|"accesses"| AM

    classDef ui fill:#AED6F1,stroke:#2980B9,stroke-width:2px;
    classDef proc fill:#F9E79F,stroke:#F1C40F,stroke-width:2px;
    classDef data fill:#D7BDE2,stroke:#8E44AD,stroke-width:2px;
    classDef global fill:#A9DFBF,stroke:#27AE60,stroke-width:2px;
    classDef asset fill:#F5CBA7,stroke:#E67E22,stroke-width:2px;

    click WC "https://github.com/kleingeist37/godot-wang-converter/blob/main/scenes/wang_creator/wang_creator.tscn"
    click WC "https://github.com/kleingeist37/godot-wang-converter/blob/main/scenes/wang_creator/ui_controller.gd"
    click WC "https://github.com/kleingeist37/godot-wang-converter/blob/main/scenes/wang_creator/hbox_button_handler.gd"
    click EP "https://github.com/kleingeist37/godot-wang-converter/blob/main/scenes/error_panel/error_panel.tscn"
    click EP "https://github.com/kleingeist37/godot-wang-converter/blob/main/scenes/error_panel/error_panel.gd"
    click TC "https://github.com/kleingeist37/godot-wang-converter/blob/main/scenes/texture_coord_button/texture_coord_btn.tscn"
    click TT "https://github.com/kleingeist37/godot-wang-converter/blob/main/scenes/tile_type_button/tile_type_button.tscn"
    click TT "https://github.com/kleingeist37/godot-wang-converter/blob/main/scenes/tile_type_button/tile_type_button.gd"
    click DM "https://github.com/kleingeist37/godot-wang-converter/blob/main/models/editor_enums.gd"
    click GE "https://github.com/kleingeist37/godot-wang-converter/blob/main/singletons/editor_signals.gd"
    click AM "https://github.com/kleingeist37/godot-wang-converter/tree/main/sprites"
```
