The Main Orchestrator
Relevant source files
Purpose and Scope
Section titled “Purpose and Scope”mod_main.gd is the central orchestration layer for Taj’s Mod. It serves as the single entry point that:
- Installs all script extensions during
_init() - Coordinates 10+ feature manager components
- Builds and manages the settings UI
- Handles input routing and game patching
- Bridges between the mod loader and game engine
For information about individual feature managers coordinated by this orchestrator, see Utility Manager Components. For details on the command palette system it initializes, see Command Palette System.
Sources: mod_main.gd L1-L68
Lifecycle and Initialization
Section titled “Lifecycle and Initialization”Two-Phase Initialization Pattern
Section titled “Two-Phase Initialization Pattern”sequenceDiagram
participant ModLoader
participant mod_main
participant Script Extensions
participant ConfigManager
participant Early Managers
participant Scene Tree
participant Main Scene
participant SettingsUI
participant Late Managers
ModLoader->>mod_main: _init()
mod_main->>Script Extensions: install_script_extension() x10
note over Script Extensions: globals.gd
mod_main->>mod_main: _load_version()
mod_main->>ConfigManager: new ConfigManager()
mod_main->>Early Managers: Initialize early managers
note over Early Managers: ScreenshotManager
Scene Tree->>mod_main: _ready()
mod_main->>mod_main: Setup ColorPickerPanel
mod_main->>ConfigManager: Load config & apply
mod_main->>mod_main: Apply wire color overrides
mod_main->>mod_main: Inject BIN window patch
mod_main->>Scene Tree: Listen for node_added
mod_main->>mod_main: call_deferred("_check_existing_main")
Scene Tree->>mod_main: node_added("Main")
mod_main->>mod_main: await timer(0.5)
mod_main->>mod_main: _setup_for_main(main_node)
mod_main->>SettingsUI: new SettingsUI(hud)
mod_main->>SettingsUI: add_mod_button()
mod_main->>Late Managers: Initialize late managers
note over Late Managers: GotoGroupManager
mod_main->>mod_main: _build_settings_menu()
mod_main->>mod_main: Apply initial visuals
Sources: mod_main.gd L72-L163
Phase 1: _init() - Core Setup
Section titled “Phase 1: _init() - Core Setup”The _init() method executes before the scene tree is available and handles:
| Initialization Task | Code Reference | Purpose |
|---|---|---|
| Script Extension Installation | mod_main.gd L73-L82 | Inject mod behavior into base game classes |
| Version Loading | mod_main.gd L86 | Read version from manifest.json |
| ConfigManager Creation | mod_main.gd L89 | Initialize settings persistence layer |
| Early Manager Setup | mod_main.gd L92-L113 | Create managers that don’t depend on scene tree |
Early managers initialized in _init():
ScreenshotManager- requires config but not scene tree (set later)PaletteController- added as child nodeWireClearHandler- needs config referenceFocusHandler- audio managementWireColorOverrides- color data holder (applied in_ready())
Sources: mod_main.gd L72-L113
Phase 2: _ready() - Scene Tree Integration
Section titled “Phase 2: _ready() - Scene Tree Integration”The _ready() method executes when the scene tree is available:
| Initialization Task | Code Reference | Purpose |
|---|---|---|
| Shared Color Picker Setup | mod_main.gd L118-L142 | Create reusable color picker overlay |
| Wire Color Application | mod_main.gd L144-L147 | Apply custom wire colors to Data.connectors |
| Screenshot Tree Binding | mod_main.gd L150 | Bind screenshot manager to scene tree |
| Node Limit Application | mod_main.gd L153-L155 | Set Globals.custom_node_limit from config |
| BIN Window Patching | mod_main.gd L158 | Inject THE BIN window into game |
| Main Scene Listener | mod_main.gd L162-L163 | Wait for Main scene to load |
Sources: mod_main.gd L115-L163
Phase 3: _setup_for_main() - Late Initialization
Section titled “Phase 3: _setup_for_main() - Late Initialization”Triggered when the Main scene node is added to the tree (after 0.5s delay):
flowchart TD Setup["_setup_for_main(main_node)"] HUD["Get HUD node"] Check["Already<br>setup?"] Done["return"] UI["new SettingsUI(hud)"] Managers["Initialize late managers"] Menu["_build_settings_menu()"] Apply["Apply initial state"] Disco["DisconnectedHighlighter"] Goto["GotoGroupManager"] ZOrder["NodeGroupZOrderFix"] BuyMax["BuyMaxManager"] NotifLog["NotificationLogPanel"] Sticky["StickyNoteManager"] Upgrade["UpgradeManager"] Visual["_apply_extra_glow()"] Opacity["_apply_ui_opacity()"] States["Apply config states"] SelectAll["Globals.select_all_enabled"] Visibility["Feature visibility toggles"] Setup --> HUD HUD --> Check Check --> Done Check --> UI UI --> Managers Managers --> Menu Menu --> Apply Managers --> Disco Managers --> Goto Managers --> ZOrder Managers --> BuyMax Managers --> NotifLog Managers --> Sticky Managers --> Upgrade Apply --> Visual Apply --> Opacity Apply --> States States --> SelectAll States --> Visibility
Sources: mod_main.gd L278-L340
Manager Coordination Architecture
Section titled “Manager Coordination Architecture”Manager Component Registry
Section titled “Manager Component Registry”mod_main.gd maintains references to all feature managers as instance variables:
flowchart TD
ModMain["mod_main instance"]
Config["config<br>(ConfigManager)"]
UI["ui<br>(SettingsUI)"]
Picker["shared_color_picker<br>(ColorPickerPanel)"]
Palette["palette_controller<br>(PaletteController)"]
WireClear["wire_clear_handler<br>(WireClearHandler)"]
Screenshot["screenshot_manager<br>(ScreenshotManager)"]
WireColors["wire_colors<br>(WireColorOverrides)"]
Goto["goto_group_manager<br>(GotoGroupManager)"]
GotoPanel["goto_group_panel<br>(GotoGroupPanel)"]
ZOrder["node_group_z_fix<br>(NodeGroupZOrderFix)"]
BuyMax["buy_max_manager<br>(BuyMaxManager)"]
Upgrade["upgrade_manager<br>(UpgradeManager)"]
Cheat["cheat_manager<br>(CheatManager)"]
Focus["focus_handler<br>(FocusHandler)"]
Disco["disconnected_highlighter<br>(DisconnectedNodeHighlighter)"]
Sticky["sticky_note_manager<br>(StickyNoteManager)"]
NotifLog["notification_log_panel<br>(NotificationLogPanel)"]
ModMain --> Config
ModMain --> UI
ModMain --> Picker
ModMain --> Palette
ModMain --> WireClear
ModMain --> Screenshot
ModMain --> WireColors
ModMain --> Goto
ModMain --> GotoPanel
ModMain --> ZOrder
ModMain --> BuyMax
ModMain --> Upgrade
ModMain --> Cheat
ModMain --> Focus
ModMain --> Disco
ModMain --> Sticky
ModMain --> NotifLog
subgraph subGraph5 ["Utility & Enhancement"]
Focus
Disco
Sticky
NotifLog
end
subgraph subGraph4 ["Gameplay & Automation"]
BuyMax
Upgrade
Cheat
end
subgraph subGraph3 ["Navigation & Organization"]
Goto
GotoPanel
ZOrder
end
subgraph subGraph2 ["Visual & Media"]
Screenshot
WireColors
end
subgraph subGraph1 ["Command & Input"]
Palette
WireClear
end
subgraph subGraph0 ["Configuration & Core"]
Config
UI
Picker
end
Sources: mod_main.gd L33-L48
Manager Initialization Pattern
Section titled “Manager Initialization Pattern”Each manager follows a consistent setup pattern:
| Setup Step | Example (GotoGroupManager) | Code Reference |
|---|---|---|
| 1. Null check | if goto_group_manager != null | mod_main.gd L393-L394 |
| 2. Instantiate | goto_group_manager = GotoGroupManagerScript.new() | mod_main.gd L356 |
| 3. Name node | goto_group_manager.name = "GotoGroupManager" | mod_main.gd L357 |
| 4. Add to tree | add_child(goto_group_manager) | mod_main.gd L358 |
| 5. Setup call | goto_group_manager.setup(...) | Varies by manager |
| 6. Log initialization | ModLoaderLog.info(...) | mod_main.gd L386 |
Sources: mod_main.gd L344-L460
Settings UI Construction
Section titled “Settings UI Construction”Tab-Based Organization
Section titled “Tab-Based Organization”The _build_settings_menu() method constructs a four-tab settings panel:
flowchart TD Build["_build_settings_menu()"] Gen["General Tab"] Vis["Visuals Tab"] Cheat["Cheats Tab"] Debug["Debug Tab"] GenToggles["Feature Toggles"] NodeLimit["Node Limit Slider"] Screenshot["Screenshot Section"] Focus["Focus Mute Section"] WireDrop["Wire Drop Menu"] SixInput["6-Input Containers ⟳"] CmdPalette["Command Palette"] RightClick["Right-click Clear"] SelectAll["Ctrl+A Select All"] GotoBtn["Go To Group Button"] BuyMaxBtn["Buy Max Button"] ZOrderFix["Group Z-Order Fix"] SliderScroll["Disable Slider Scroll"] ToastLog["Toast History Panel"] DiscoHighlight["Highlight Disconnected"] WireColorSec["Wire Color Section"] GlowSec["Extra Glow Section"] OpacitySlider["UI Opacity Slider"] GlowToggle["Extra Glow Toggle"] GlowSub["Glow Sub-Settings"] Intensity["Intensity Slider"] Strength["Strength Slider"] Bloom["Bloom Slider"] Sensitivity["Sensitivity Slider"] WireToggle["Custom Wire Colors Toggle"] Categories["Wire Categories"] Speeds["⚡ Speeds"] Resources["💰 Resources"] Hacking["🔓 Hacking"] DataTypes["📊 Data Types"] AI["🧠 AI / Neural"] Boosts["🚀 Boosts"] Other["📦 Other"] CheatMgr["CheatManager.build_cheats_tab()"] ResetBtn["Reset All Settings Button"] BootScreen["Custom Boot Screen ⟳"] DebugToggle["Enable Debug Logging"] DebugInfo["Log Debug Info Button"] DebugLabel["Debug Log Label"] Build --> Gen Build --> Vis Build --> Cheat Build --> Debug Gen --> GenToggles Gen --> NodeLimit Gen --> Screenshot Gen --> Focus GenToggles --> WireDrop GenToggles --> SixInput GenToggles --> CmdPalette GenToggles --> RightClick GenToggles --> SelectAll GenToggles --> GotoBtn GenToggles --> BuyMaxBtn GenToggles --> ZOrderFix GenToggles --> SliderScroll GenToggles --> ToastLog GenToggles --> DiscoHighlight Vis --> WireColorSec Vis --> GlowSec Vis --> OpacitySlider GlowSec --> GlowToggle GlowSec --> GlowSub GlowSub --> Intensity GlowSub --> Strength GlowSub --> Bloom GlowSub --> Sensitivity WireColorSec --> WireToggle WireColorSec --> Categories Categories --> Speeds Categories --> Resources Categories --> Hacking Categories --> DataTypes Categories --> AI Categories --> Boosts Categories --> Other Cheat --> CheatMgr Debug --> ResetBtn Debug --> BootScreen Debug --> DebugToggle Debug --> DebugInfo Debug --> DebugLabel
Sources: mod_main.gd L462-L688
Settings Toggle Tracking
Section titled “Settings Toggle Tracking”The _settings_toggles dictionary tracks all CheckButton references for synchronization:
| Dictionary Key | Purpose | Code Reference |
|---|---|---|
"wire_drop_menu_enabled" | Wire drop menu toggle | mod_main.gd L467 |
"six_input_containers" | Container input count | mod_main.gd L474 |
"command_palette_enabled" | Command palette toggle | mod_main.gd L480 |
"right_click_clear_enabled" | Right-click wire clear | mod_main.gd L487 |
"select_all_enabled" | Ctrl+A select all | mod_main.gd L494 |
"goto_group_enabled" | Go to group button | mod_main.gd L500 |
"buy_max_enabled" | Buy max button | mod_main.gd L506 |
"z_order_fix_enabled" | Z-order fix | mod_main.gd L520 |
"disable_slider_scroll" | Slider scroll blocking | mod_main.gd L527 |
"notification_log_enabled" | Toast history panel | mod_main.gd L532 |
"highlight_disconnected_enabled" | Disconnected highlighting | mod_main.gd L710 |
"mute_on_focus_loss" | Focus-based muting | mod_main.gd L558 |
"disable_controller_input" | Controller blocking | mod_main.gd L566 |
"custom_boot_screen" | Boot screen patch | mod_main.gd L649 |
The sync_settings_toggle() method allows command palette commands to update toggle UI state:
Sources: mod_main.gd L61
Restart-Required Settings
Section titled “Restart-Required Settings”Settings marked with ⟳ require restart and are tracked in _restart_original_values:
flowchart TD User["User changes setting"] Save["config.set_value()"] Check["_check_restart_required()"] Compare["Compare to original values"] ShowBanner["ui.show_restart_banner()"] HideBanner["ui.hide_restart_banner()"] User --> Save Save --> Check Check --> Compare Compare --> ShowBanner Compare --> HideBanner
Sources: mod_main.gd L62
Continuous Processing and Input Handling
Section titled “Continuous Processing and Input Handling”_process() Loop - Persistent Patching
Section titled “_process() Loop - Persistent Patching”The _process() method runs every frame and handles:
| Task | Condition | Code Reference |
|---|---|---|
| Desktop script patching | !_desktop_patched | mod_main.gd L180-L181 |
| Node label update | Always (when UI visible) | mod_main.gd L184 |
| Boot screen patching | custom_boot_screen enabled | mod_main.gd L187-L190 |
Desktop patching continuously attempts to patch the Desktop script until successful, handling game state changes that may reset the script.
Sources: mod_main.gd L178-L190
_input() Event Routing
Section titled “_input() Event Routing”Input handling implements three blocking/filtering layers:
flowchart TD Input["_input(event)"] Controller["disable_controller_input<br>enabled?"] CheckJoypad["Is joypad<br>event?"] BlockController["set_input_as_handled()"] Slider["disable_slider_scroll<br>enabled?"] Done["return"] CheckWheel["Is wheel event?"] CheckHover["Mouse over<br>slider?"] BlockSlider["set_input_as_handled()"] UIClick["UI visible?"] CheckClick["Left click?"] CheckOutside["Click outside<br>UI panel?"] CloseUI["ui.set_visible(false)"] Input --> Controller Controller --> CheckJoypad CheckJoypad --> BlockController CheckJoypad --> Slider Controller --> Slider BlockController --> Done Slider --> CheckWheel CheckWheel --> CheckHover CheckHover --> BlockSlider CheckHover --> UIClick CheckWheel --> UIClick Slider --> UIClick BlockSlider --> Done UIClick --> Done UIClick --> CheckClick CheckClick --> CheckOutside CheckOutside --> CloseUI CheckOutside --> Done CheckClick --> Done CloseUI --> Done
Sources: mod_main.gd L192-L226
Slider Hover Detection
Section titled “Slider Hover Detection”The _get_hovered_slider() and _find_slider_at_point() methods perform recursive tree traversal to find sliders under the cursor:
Algorithm:
- Traverse scene tree in reverse order (topmost nodes first)
- Recursively check children
- Test if node is HSlider or VSlider
- Verify control is visible and contains mouse point
- Validate all ancestors are visible
Sources: mod_main.gd L228-L258
Public API Methods
Section titled “Public API Methods”Configuration Interfaces
Section titled “Configuration Interfaces”Methods exposed for external control (e.g., from command palette):
| Method Signature | Purpose | Code Reference |
|---|---|---|
set_node_limit(value: int) | Update node limit and UI | mod_main.gd L1033-L1039 |
set_extra_glow(enabled: bool) | Toggle glow and update UI | mod_main.gd L1042-L1048 |
sync_settings_toggle(config_key: String) | Sync toggle from config | mod_main.gd L1150-L1154 |
Sources: mod_main.gd L1033-L1154
UI Integration Callbacks
Section titled “UI Integration Callbacks”| Callback | Trigger | Code Reference |
|---|---|---|
_on_node_added(node: Node) | Scene tree node added | mod_main.gd L271-L276 |
_on_notification_received(icon, text) | Signals.notify emitted | mod_main.gd L1144-L1146 |
_on_picker_color_changed(c: Color) | Shared color picker changed | mod_main.gd L174-L176 |
Sources: mod_main.gd L174-L176
Wire Color System Integration
Section titled “Wire Color System Integration”Wire Color Management Flow
Section titled “Wire Color Management Flow”sequenceDiagram
participant User
participant mod_main
participant WireColorOverrides
participant ColorPickerPanel
participant ConfigManager
participant Scene Tree
User->>mod_main: Click color button
mod_main->>mod_main: _open_color_picker()
mod_main->>ColorPickerPanel: set_color(current)
mod_main->>mod_main: picker_canvas.visible = true
loop [User adjusts color]
User->>ColorPickerPanel: Drag picker
ColorPickerPanel->>mod_main: color_changed signal
mod_main->>mod_main: _on_picker_color_changed()
mod_main->>WireColorOverrides: set_color_from_rgb()
mod_main->>ConfigManager: Save to config
User->>mod_main: Click outside picker
mod_main->>mod_main: _close_color_picker()
User->>mod_main: Click "Apply Colors"
mod_main->>mod_main: _refresh_all_connectors()
mod_main->>Scene Tree: get_nodes_in_group("connector")
mod_main->>mod_main: Update Connector.color
mod_main->>mod_main: connector.draw_update()
mod_main->>mod_main: Find connector buttons
mod_main->>mod_main: update_connector_button()
end
Sources: mod_main.gd L165-L176
Wire Color Categories
Section titled “Wire Color Categories”The wire color section organizes 50+ resource types into 7 collapsible categories:
| Category Emoji | Category Name | Resource IDs | Code Reference |
|---|---|---|---|
| ⚡ | Speeds | download_speed, upload_speed, clock_speed, etc. | mod_main.gd L789 |
| 💰 | Resources | money, research, token, power, etc. | mod_main.gd L790 |
| 🔓 | Hacking | hack_power, virus, trojan, etc. | mod_main.gd L791 |
| 📊 | Data Types | bool, char, int, float, string, etc. | mod_main.gd L792 |
| 🧠 | AI / Neural | ai, neuron_text, neuron_image, etc. | mod_main.gd L793 |
| 🚀 | Boosts | boost_component, boost_research, overclock, etc. | mod_main.gd L794 |
| 📦 | Other | heat, storage, litecoin, bitcoin, etc. | mod_main.gd L795 |
Each category creates a collapsible section with color pickers for each wire type using _add_wire_category() and _add_wire_color_picker().
Sources: mod_main.gd L786-L810
State Variables
Section titled “State Variables”UI State Tracking
Section titled “UI State Tracking”| Variable | Type | Purpose | Code Reference |
|---|---|---|---|
mod_dir_path | String | Unpacked mod directory path | mod_main.gd L51 |
mod_version | String | Version from manifest.json | mod_main.gd L52 |
_desktop_patched | bool | Desktop script patching status | mod_main.gd L53 |
_node_info_label | Label | Node count display reference | mod_main.gd L54 |
_debug_log_label | Label | Debug log display reference | mod_main.gd L55 |
_debug_mode | bool | Verbose logging toggle | mod_main.gd L56 |
_node_limit_slider | HSlider | Node limit slider reference | mod_main.gd L57 |
_node_limit_value_label | Label | Node limit value display | mod_main.gd L58 |
_extra_glow_toggle | CheckButton | Glow toggle reference | mod_main.gd L59 |
_extra_glow_sub | MarginContainer | Glow sub-settings container | mod_main.gd L60 |
_settings_toggles | Dictionary | Map of config keys to CheckButtons | mod_main.gd L61 |
_restart_original_values | Dictionary | Original values for restart-required settings | mod_main.gd L62 |
Sources: mod_main.gd L51-L62
Shared Color Picker State
Section titled “Shared Color Picker State”| Variable | Type | Purpose | Code Reference |
|---|---|---|---|
shared_color_picker | ColorPickerPanel | Reusable color picker instance | mod_main.gd L65 |
picker_canvas | CanvasLayer | Overlay layer for picker (z=100) | mod_main.gd L66 |
_current_picker_callback | Callable | Callback for color changes | mod_main.gd L67 |
The shared color picker architecture allows multiple wire color buttons to use a single picker instance, reducing memory overhead and ensuring consistent UI.
Sources: mod_main.gd L65-L67
Helper Methods
Section titled “Helper Methods”Debug Logging System
Section titled “Debug Logging System”_add_debug_log(message: String, force: bool = false) provides conditional logging:
flowchart TD Call["_add_debug_log(msg, force)"] Check["_debug_mode<br>OR force?"] Skip["return"] Timestamp["Get timestamp"] Log["ModLoaderLog.info()"] CheckLabel["_debug_log_label<br>exists?"] Append["Append to label"] Done["return"] Trim["Lines > 21?"] Slice["Keep last 21 lines"] Call --> Check Check --> Skip Check --> Timestamp Timestamp --> Log Log --> CheckLabel CheckLabel --> Append CheckLabel --> Done Append --> Trim Trim --> Slice Trim --> Done Slice --> Done
Sources: mod_main.gd L968-L982
Visual Effect Application
Section titled “Visual Effect Application”| Method | Effect Applied | Target Node | Code Reference |
|---|---|---|---|
_apply_extra_glow(enabled) | Glow environment settings | WorldEnvironment in Main | mod_main.gd L1050-L1067 |
_apply_ui_opacity(value) | UI transparency | HUD/Main/MainContainer | mod_main.gd L1069-L1078 |
Glow parameters when enabled:
glow_intensity- from config key"glow_intensity"glow_strength- from config key"glow_strength"glow_bloom- from config key"glow_bloom"glow_hdr_threshold- from config key"glow_sensitivity"
Sources: mod_main.gd L1050-L1078
Version Loading
Section titled “Version Loading”_load_version() reads the mod version from manifest.json:
- Construct path:
mod_dir_path + "/manifest.json" - Open file with
FileAccess.open() - Parse JSON with
JSON.parse() - Extract
"version_number"field - Store in
mod_versionvariable
Sources: mod_main.gd L957-L966
Integration with Command Palette
Section titled “Integration with Command Palette”Screenshot Command Registration
Section titled “Screenshot Command Registration”The orchestrator registers custom screenshot commands that use ScreenshotManager:
flowchart TD Register["_register_palette_screenshot_command()"] Cmd1["cmd_take_screenshot"] Cmd2["cmd_open_screenshot_folder"] Cmd3["cmd_screenshot_selection"] Run1["sm.take_screenshot()"] Run2["sm.open_screenshot_folder()"] Run3["sm.take_screenshot_selection()"] CanRun["can_run check:<br>Globals.selections.size() > 0"] Register --> Cmd1 Register --> Cmd2 Register --> Cmd3 Cmd1 --> Run1 Cmd2 --> Run2 Cmd3 --> Run3 Cmd3 --> CanRun
Each command is registered with:
- Unique ID
- Category path:
["Taj's Mod", "Screenshots"] - Keywords for fuzzy search
- Icon path
- Badge:
"SAFE" - Run callback (captures
screenshot_managerreference) - Optional
can_runpredicate
Sources: mod_main.gd L1192-L1229
Summary
Section titled “Summary”mod_main.gd implements a hub-and-spoke orchestration pattern with:
- Two-phase initialization: Script extensions in
_init(), scene-dependent setup in_ready()and_setup_for_main() - Manager coordination: Centralized references to 10+ feature managers
- Settings UI construction: Tab-based interface with 40+ configuration options
- Input routing: Three-layer filtering (controller blocking, slider scroll blocking, UI click-outside)
- Persistent patching: Frame-by-frame patching in
_process()to handle game state changes - Shared resources: Single color picker instance for all wire color customization
- Public API: Methods for command palette integration and external control
The orchestrator serves as the single source of truth for mod state and ensures proper initialization order across all components.