# loki79uk/fs25_universalautoload architecture

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

- Interactive diagram: https://gitdiagram.com/loki79uk/fs25_universalautoload
- Repository: https://github.com/loki79uk/fs25_universalautoload

## Overview

##### Project type and purpose
- This is a Farming Simulator 25 “Universal Autoload” mod, implemented in Lua, XML and DDS assets.
- It plugs into the FS25 game engine to automatically detect and load bales, pallets, logs, etc., and provides an in-game GUI for configuring load zones.

##### File structure
- Top-level files:
- UniversalAutoload.lua & UniversalAutoloadInstaller.lua – core entry points that register the mod with FS25’s mod loader.
- modDesc.xml – metadata that the game reads to discover and load the mod.
- Directories:
- events/ – event classes for each user or game action (e.g. StartLoading, StopLoading, RaiseActive).
- gui/ – GUI layout (.xml) and controller (.lua) for shop and global settings menus.
- xml/ – default settings definitions.
- language/ – localization files for each supported language.

##### Insights from README
- Event-driven design: buyers and workshop sessions generate events to adjust or save the autoload configuration.
- Config persistence: settings are saved in mod settings XML (on server in multiplayer).
- Key workflows: purchasing a vehicle, editing load zones in the shop GUI, running the game, auto-detection of loading zones, and saving/loading of configurations.
- Known quirks: rebuying vehicle to trigger defaults, Unicode path issues, multiplayer server-side save.

a. Main components
- FS25 Game Engine (host)
- UniversalAutoload Mod (plugin)
– Installer Module (UniversalAutoloadInstaller.lua)
– Core Logic (UniversalAutoload.lua + scripts/)
– Event Handlers (events/)
– GUI Layer (gui/)
– Trigger Definitions (triggers/)
– Configuration Store (xml/UniversalAutoloadDefaults.xml + mod settings XML)
– Localization (language/)
b. Relationships & interactions
- On game start → Game Engine reads modDesc.xml → loads Installer → registers triggers and event hooks.
- Shop GUI ←→ Player input events → Event Handlers update Configuration Store.
- When player mounts a vehicle or enters loading mode → Core Logic queries Trigger volumes → updates UI/debug overlay.
- Configuration Store saved/loaded via FS API calls triggered by events (purchase, apply button).
- Multithreading/server: clients send config changes → server’s Configuration Store is updated → broadcast to other clients.
c. Architectural patterns
- Event-Driven Architecture: decouples UI, core logic and persistence via custom event classes.
- MVC-like separation in GUI folder: XML defines view, Lua controllers handle logic.
- Plugin architecture: mod loaded dynamically by FS25 engine.
d. Key technologies & frameworks
- Lua 5.x (FS25 mod API)
- FS25 I3D for 3D triggers
- XML for GUI layouts, localization and default settings

##### Be thorough but focused
- Interactions between them, not every single file.
- Don’t over-complicate: grouping related files into modules (e.g., “Event Handlers”) is sufficient.

## Diagram (Mermaid)

```mermaid
graph TD
    FS["FS25 Game Engine & API"]:::yellow
    modDesc["modDesc.xml"]:::green
    subgraph "UniversalAutoload Mod"
        Installer["UniversalAutoloadInstaller.lua"]:::blue
        subgraph "Core Logic"
            CoreLua["UniversalAutoload.lua"]:::blue
            BBox["scripts/BoundingBox.lua"]:::green
            LoadingVol["scripts/LoadingVolume.lua"]:::green
        end
        Events["Event Handlers"]:::blue
        subgraph "GUI Layer"
            view1["gui/GlobalSettingsMenuUALSettings.xml"]:::green
            view2["gui/ModSettingsMenu.xml"]:::green
            view3["gui/ShopConfigMenuUALSettings.xml"]:::green
            ctrl1["gui/GlobalSettingsMenuUALSettings.lua"]:::blue
            ctrl2["gui/ModSettingsMenu.lua"]:::blue
            ctrl3["gui/ShopConfigMenuUALSettings.lua"]:::blue
        end
        subgraph "Trigger Definitions"
            TriggersI3D["triggers/UniversalAutoloadTriggers.i3d"]:::green
            TriggersShapes["triggers/UniversalAutoloadTriggers.i3d.shapes"]:::green
        end
        subgraph "Configuration Store"
            Defaults["xml/UniversalAutoloadDefaults.xml"]:::green
        end
        subgraph "Localization"
            Localization["language/"]:::green
        end
        subgraph "Asset Bundle"
            Icons["icons/"]:::green
            menuMod["gui/menu_modSettings.dds"]:::green
            menuUal["gui/menu_ual.dds"]:::green
            iconUal["icon_UniversalAutoload.dds"]:::green
        end
    end

    %% Initialization Flow
    FS -->|"reads modDesc.xml"| modDesc
    modDesc -->|"loads Installer"| Installer
    Installer -->|"registerTriggers()"| TriggersI3D
    Installer -->|"registerShapes()"| TriggersShapes
    Installer -->|"registerEvent(StartLoadingEvent)"| Events

    %% Core Logic and Triggers
    CoreLua -->|"uses BoundingBox"| BBox
    CoreLua -->|"uses LoadingVolume"| LoadingVol
    CoreLua -->|"queries triggers"| TriggersI3D
    CoreLua -->|"queries shapes"| TriggersShapes

    %% GUI to Events to Store
    ctrl3 -->|"onApply()"| Events
    ctrl2 -->|"onSaveSettings()"| Events
    ctrl1 -->|"onGlobalSave()"| Events
    Events -->|"saveModSettings()"| Defaults

    %% Multiplayer Flow
    Events -->|"broadcastConfig"| FS
    FS -->|"syncConfig"| ctrl1
    FS -->|"syncConfig"| ctrl2
    FS -->|"syncConfig"| ctrl3

    %% Legend (as subgraph)
    subgraph Legend
        A["Yellow=Engine/API"]:::yellow
        B["Blue=Mod Modules"]:::blue
        C["Green=Assets/Data"]:::green
    end

    %% Click Events
    click Installer "https://github.com/loki79uk/fs25_universalautoload/blob/main/UniversalAutoloadInstaller.lua"
    click CoreLua "https://github.com/loki79uk/fs25_universalautoload/blob/main/UniversalAutoload.lua"
    click BBox "https://github.com/loki79uk/fs25_universalautoload/blob/main/scripts/BoundingBox.lua"
    click LoadingVol "https://github.com/loki79uk/fs25_universalautoload/blob/main/scripts/LoadingVolume.lua"
    click Events "https://github.com/loki79uk/fs25_universalautoload/tree/main/events/"
    click view1 "https://github.com/loki79uk/fs25_universalautoload/blob/main/gui/GlobalSettingsMenuUALSettings.xml"
    click view2 "https://github.com/loki79uk/fs25_universalautoload/blob/main/gui/ModSettingsMenu.xml"
    click view3 "https://github.com/loki79uk/fs25_universalautoload/blob/main/gui/ShopConfigMenuUALSettings.xml"
    click ctrl1 "https://github.com/loki79uk/fs25_universalautoload/blob/main/gui/GlobalSettingsMenuUALSettings.lua"
    click ctrl2 "https://github.com/loki79uk/fs25_universalautoload/blob/main/gui/ModSettingsMenu.lua"
    click ctrl3 "https://github.com/loki79uk/fs25_universalautoload/blob/main/gui/ShopConfigMenuUALSettings.lua"
    click TriggersI3D "https://github.com/loki79uk/fs25_universalautoload/blob/main/triggers/UniversalAutoloadTriggers.i3d"
    click TriggersShapes "https://github.com/loki79uk/fs25_universalautoload/blob/main/triggers/UniversalAutoloadTriggers.i3d.shapes"
    click Defaults "https://github.com/loki79uk/fs25_universalautoload/blob/main/xml/UniversalAutoloadDefaults.xml"
    click Localization "https://github.com/loki79uk/fs25_universalautoload/tree/main/language/"
    click Icons "https://github.com/loki79uk/fs25_universalautoload/tree/main/icons/"
    click menuMod "https://github.com/loki79uk/fs25_universalautoload/blob/main/gui/menu_modSettings.dds"
    click menuUal "https://github.com/loki79uk/fs25_universalautoload/blob/main/gui/menu_ual.dds"
    click iconUal "https://github.com/loki79uk/fs25_universalautoload/blob/main/icon_UniversalAutoload.dds"

    classDef yellow fill:#f9f871,stroke:#333,stroke-width:1px
    classDef blue fill:#87cefa,stroke:#333,stroke-width:1px
    classDef green fill:#98fb98,stroke:#333,stroke-width:1px
```
