Skip to content

The Main Orchestrator

Relevant source files

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


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

mod_main.gd L271-L340

The _init() method executes before the scene tree is available and handles:

Initialization TaskCode ReferencePurpose
Script Extension Installationmod_main.gd L73-L82Inject mod behavior into base game classes
Version Loadingmod_main.gd L86Read version from manifest.json
ConfigManager Creationmod_main.gd L89Initialize settings persistence layer
Early Manager Setupmod_main.gd L92-L113Create 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 node
  • WireClearHandler - needs config reference
  • FocusHandler - audio management
  • WireColorOverrides - 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 TaskCode ReferencePurpose
Shared Color Picker Setupmod_main.gd L118-L142Create reusable color picker overlay
Wire Color Applicationmod_main.gd L144-L147Apply custom wire colors to Data.connectors
Screenshot Tree Bindingmod_main.gd L150Bind screenshot manager to scene tree
Node Limit Applicationmod_main.gd L153-L155Set Globals.custom_node_limit from config
BIN Window Patchingmod_main.gd L158Inject THE BIN window into game
Main Scene Listenermod_main.gd L162-L163Wait 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


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

Each manager follows a consistent setup pattern:

Setup StepExample (GotoGroupManager)Code Reference
1. Null checkif goto_group_manager != nullmod_main.gd L393-L394
2. Instantiategoto_group_manager = GotoGroupManagerScript.new()mod_main.gd L356
3. Name nodegoto_group_manager.name = "GotoGroupManager"mod_main.gd L357
4. Add to treeadd_child(goto_group_manager)mod_main.gd L358
5. Setup callgoto_group_manager.setup(...)Varies by manager
6. Log initializationModLoaderLog.info(...)mod_main.gd L386

Sources: mod_main.gd L344-L460


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

The _settings_toggles dictionary tracks all CheckButton references for synchronization:

Dictionary KeyPurposeCode Reference
"wire_drop_menu_enabled"Wire drop menu togglemod_main.gd L467
"six_input_containers"Container input countmod_main.gd L474
"command_palette_enabled"Command palette togglemod_main.gd L480
"right_click_clear_enabled"Right-click wire clearmod_main.gd L487
"select_all_enabled"Ctrl+A select allmod_main.gd L494
"goto_group_enabled"Go to group buttonmod_main.gd L500
"buy_max_enabled"Buy max buttonmod_main.gd L506
"z_order_fix_enabled"Z-order fixmod_main.gd L520
"disable_slider_scroll"Slider scroll blockingmod_main.gd L527
"notification_log_enabled"Toast history panelmod_main.gd L532
"highlight_disconnected_enabled"Disconnected highlightingmod_main.gd L710
"mute_on_focus_loss"Focus-based mutingmod_main.gd L558
"disable_controller_input"Controller blockingmod_main.gd L566
"custom_boot_screen"Boot screen patchmod_main.gd L649

The sync_settings_toggle() method allows command palette commands to update toggle UI state:

Sources: mod_main.gd L61

mod_main.gd L1149-L1154

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

mod_main.gd L1159-L1174


The _process() method runs every frame and handles:

TaskConditionCode Reference
Desktop script patching!_desktop_patchedmod_main.gd L180-L181
Node label updateAlways (when UI visible)mod_main.gd L184
Boot screen patchingcustom_boot_screen enabledmod_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 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

The _get_hovered_slider() and _find_slider_at_point() methods perform recursive tree traversal to find sliders under the cursor:

Algorithm:

  1. Traverse scene tree in reverse order (topmost nodes first)
  2. Recursively check children
  3. Test if node is HSlider or VSlider
  4. Verify control is visible and contains mouse point
  5. Validate all ancestors are visible

Sources: mod_main.gd L228-L258


Methods exposed for external control (e.g., from command palette):

Method SignaturePurposeCode Reference
set_node_limit(value: int)Update node limit and UImod_main.gd L1033-L1039
set_extra_glow(enabled: bool)Toggle glow and update UImod_main.gd L1042-L1048
sync_settings_toggle(config_key: String)Sync toggle from configmod_main.gd L1150-L1154

Sources: mod_main.gd L1033-L1154

CallbackTriggerCode Reference
_on_node_added(node: Node)Scene tree node addedmod_main.gd L271-L276
_on_notification_received(icon, text)Signals.notify emittedmod_main.gd L1144-L1146
_on_picker_color_changed(c: Color)Shared color picker changedmod_main.gd L174-L176

Sources: mod_main.gd L174-L176

mod_main.gd L271-L276

mod_main.gd L1144-L1146


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

mod_main.gd L849-L910

mod_main.gd L913-L950

The wire color section organizes 50+ resource types into 7 collapsible categories:

Category EmojiCategory NameResource IDsCode Reference
Speedsdownload_speed, upload_speed, clock_speed, etc.mod_main.gd L789
💰Resourcesmoney, research, token, power, etc.mod_main.gd L790
🔓Hackinghack_power, virus, trojan, etc.mod_main.gd L791
📊Data Typesbool, char, int, float, string, etc.mod_main.gd L792
🧠AI / Neuralai, neuron_text, neuron_image, etc.mod_main.gd L793
🚀Boostsboost_component, boost_research, overclock, etc.mod_main.gd L794
📦Otherheat, 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

mod_main.gd L813-L910


VariableTypePurposeCode Reference
mod_dir_pathStringUnpacked mod directory pathmod_main.gd L51
mod_versionStringVersion from manifest.jsonmod_main.gd L52
_desktop_patchedboolDesktop script patching statusmod_main.gd L53
_node_info_labelLabelNode count display referencemod_main.gd L54
_debug_log_labelLabelDebug log display referencemod_main.gd L55
_debug_modeboolVerbose logging togglemod_main.gd L56
_node_limit_sliderHSliderNode limit slider referencemod_main.gd L57
_node_limit_value_labelLabelNode limit value displaymod_main.gd L58
_extra_glow_toggleCheckButtonGlow toggle referencemod_main.gd L59
_extra_glow_subMarginContainerGlow sub-settings containermod_main.gd L60
_settings_togglesDictionaryMap of config keys to CheckButtonsmod_main.gd L61
_restart_original_valuesDictionaryOriginal values for restart-required settingsmod_main.gd L62

Sources: mod_main.gd L51-L62

VariableTypePurposeCode Reference
shared_color_pickerColorPickerPanelReusable color picker instancemod_main.gd L65
picker_canvasCanvasLayerOverlay layer for picker (z=100)mod_main.gd L66
_current_picker_callbackCallableCallback for color changesmod_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

mod_main.gd L118-L142


_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

MethodEffect AppliedTarget NodeCode Reference
_apply_extra_glow(enabled)Glow environment settingsWorldEnvironment in Mainmod_main.gd L1050-L1067
_apply_ui_opacity(value)UI transparencyHUD/Main/MainContainermod_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

_load_version() reads the mod version from manifest.json:

  1. Construct path: mod_dir_path + "/manifest.json"
  2. Open file with FileAccess.open()
  3. Parse JSON with JSON.parse()
  4. Extract "version_number" field
  5. Store in mod_version variable

Sources: mod_main.gd L957-L966


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_manager reference)
  • Optional can_run predicate

Sources: mod_main.gd L1192-L1229


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.