# r00tcrop/transport-fever-2-grid architecture

> Architecture diagram of the GitHub repository r00tcrop/transport-fever-2-grid, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/r00tcrop/transport-fever-2-grid
- Repository: https://github.com/r00tcrop/transport-fever-2-grid

## Overview

Grid is a Transport Fever 2 mod for measuring and planning on terrain. The player opens its bottom-bar button and changes settings in a popup; the game-script GUI context propagates those settings, tracks the grid’s anchor, and updates terrain polygons. The README also documents shared setting defaults, emphasized lines, persistence/state synchronization, and debug logging. The source excerpts were unavailable, so relationships below rely on the README; links marked dashed are unverified implementation connections.

Main entry points: [`res/config/game_script/grid_overlay.lua`](https://github.com/r00tcrop/transport-fever-2-grid/blob/main/res/config/game_script/grid_overlay.lua) (Game-script update loop), [`res/scripts/grid_overlay/menu.lua`](https://github.com/r00tcrop/transport-fever-2-grid/blob/main/res/scripts/grid_overlay/menu.lua) (Grid button and popup), [`res/scripts/grid_overlay/config.lua`](https://github.com/r00tcrop/transport-fever-2-grid/blob/main/res/scripts/grid_overlay/config.lua) (Setting values and defaults), [`res/scripts/grid_overlay/zones.lua`](https://github.com/r00tcrop/transport-fever-2-grid/blob/main/res/scripts/grid_overlay/zones.lua) (Terrain zones)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["Player interface"]
  node_menu["Grid button and popup<br/>[menu.lua]"]
  node_style["Button and popup styles<br/>[grid_overlay.lua]"]
end

subgraph group_runtime["Grid runtime"]
  node_game_script["Game-script update loop<br/>[grid_overlay.lua]"]
  node_anchor["Grid anchor<br/>[anchor.lua]"]
  node_geometry["Grid-line polygons<br/>[geometry.lua]"]
  node_zones["Terrain zones<br/>[zones.lua]"]
end

subgraph group_settings["Settings and localization"]
  node_config["Setting values and defaults<br/>[config.lua]"]
  node_mod_settings["Initial mod settings<br/>[mod.lua]"]
  node_strings["Translated text<br/>[strings.lua]"]
end

subgraph group_support["Diagnostics and styling"]
  node_logging["Logging<br/>[logging.lua]"]
  node_debugpanel["Debug panel<br/>[debugpanel.lua]"]
end

node_player(("Player"))
node_game{{"Game engine"}}

node_player -->|"opens and configures"| node_menu
node_menu -->|"adds button to"| node_game
node_config -->|"provides settings"| node_menu
node_config -->|"provides defaults"| node_mod_settings
node_menu -->|"sends setting events"| node_game_script
node_game_script -.->|"tracks grid position"| node_anchor
node_game_script -.->|"updates grid lines"| node_geometry
node_game_script -->|"writes terrain polygons"| node_zones
node_zones -->|"draws on terrain"| node_game
node_game_script -->|"saves and loads state"| node_game
node_game_script -.->|"logs runtime activity"| node_logging
node_debugpanel -.->|"shows debug output"| node_logging

click node_menu "https://github.com/r00tcrop/transport-fever-2-grid/blob/main/res/scripts/grid_overlay/menu.lua"
click node_style "https://github.com/r00tcrop/transport-fever-2-grid/blob/main/res/config/style_sheet/grid_overlay.lua"
click node_game_script "https://github.com/r00tcrop/transport-fever-2-grid/blob/main/res/config/game_script/grid_overlay.lua"
click node_anchor "https://github.com/r00tcrop/transport-fever-2-grid/blob/main/res/scripts/grid_overlay/anchor.lua"
click node_geometry "https://github.com/r00tcrop/transport-fever-2-grid/blob/main/res/scripts/grid_overlay/geometry.lua"
click node_zones "https://github.com/r00tcrop/transport-fever-2-grid/blob/main/res/scripts/grid_overlay/zones.lua"
click node_config "https://github.com/r00tcrop/transport-fever-2-grid/blob/main/res/scripts/grid_overlay/config.lua"
click node_mod_settings "https://github.com/r00tcrop/transport-fever-2-grid/blob/main/mod.lua"
click node_strings "https://github.com/r00tcrop/transport-fever-2-grid/blob/main/strings.lua"
click node_logging "https://github.com/r00tcrop/transport-fever-2-grid/blob/main/res/scripts/grid_overlay/logging.lua"
click node_debugpanel "https://github.com/r00tcrop/transport-fever-2-grid/blob/main/res/scripts/grid_overlay/debugpanel.lua"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_menu,node_style toneBlue
class node_game_script,node_anchor,node_geometry,node_zones toneAmber
class node_config,node_mod_settings,node_strings toneMint
class node_logging,node_debugpanel toneRose
class node_player,node_game toneIndigo
```

## Components

### Player interface

- [Grid button and popup](https://github.com/r00tcrop/transport-fever-2-grid/blob/main/res/scripts/grid_overlay/menu.lua): `res/scripts/grid_overlay/menu.lua`
- [Button and popup styles](https://github.com/r00tcrop/transport-fever-2-grid/blob/main/res/config/style_sheet/grid_overlay.lua): `res/config/style_sheet/grid_overlay.lua`

### Grid runtime

- [Game-script update loop](https://github.com/r00tcrop/transport-fever-2-grid/blob/main/res/config/game_script/grid_overlay.lua): `res/config/game_script/grid_overlay.lua`
- [Grid anchor](https://github.com/r00tcrop/transport-fever-2-grid/blob/main/res/scripts/grid_overlay/anchor.lua): `res/scripts/grid_overlay/anchor.lua`
- [Grid-line polygons](https://github.com/r00tcrop/transport-fever-2-grid/blob/main/res/scripts/grid_overlay/geometry.lua): `res/scripts/grid_overlay/geometry.lua`
- [Terrain zones](https://github.com/r00tcrop/transport-fever-2-grid/blob/main/res/scripts/grid_overlay/zones.lua): `res/scripts/grid_overlay/zones.lua`

### Settings and localization

- [Setting values and defaults](https://github.com/r00tcrop/transport-fever-2-grid/blob/main/res/scripts/grid_overlay/config.lua): `res/scripts/grid_overlay/config.lua`
- [Initial mod settings](https://github.com/r00tcrop/transport-fever-2-grid/blob/main/mod.lua): `mod.lua`
- [Translated text](https://github.com/r00tcrop/transport-fever-2-grid/blob/main/strings.lua): `strings.lua`

### Diagnostics and styling

- [Logging](https://github.com/r00tcrop/transport-fever-2-grid/blob/main/res/scripts/grid_overlay/logging.lua): `res/scripts/grid_overlay/logging.lua`
- [Debug panel](https://github.com/r00tcrop/transport-fever-2-grid/blob/main/res/scripts/grid_overlay/debugpanel.lua): `res/scripts/grid_overlay/debugpanel.lua`

### Other components

- **Player**
- **Game engine**

## Connections

- Player → Grid button and popup: opens and configures (evidence: `README.md`)
- Grid button and popup → Game engine: adds button to (evidence: `README.md`)
- Setting values and defaults → Grid button and popup: provides settings (evidence: `README.md`)
- Setting values and defaults → Initial mod settings: provides defaults (evidence: `README.md`)
- Grid button and popup → Game-script update loop: sends setting events (evidence: `README.md`)
- Game-script update loop → Grid anchor: tracks grid position
- Game-script update loop → Grid-line polygons: updates grid lines
- Game-script update loop → Terrain zones: writes terrain polygons (evidence: `README.md`)
- Terrain zones → Game engine: draws on terrain (evidence: `README.md`)
- Game-script update loop → Game engine: saves and loads state (evidence: `README.md`)
- Game-script update loop → Logging: logs runtime activity
- Debug panel → Logging: shows debug output
