GGua REFERENCE日本語GitHub ↗
DOCS / GODOT SAMPLE

Godot main.gd

examples/godot-gdscript/scripts/main.gd is a compact reference that combines Control-tree construction, automatic collection, the Inspector bridge, and visual end-to-end fixtures.

View the complete source on GitHub ↗

Central object

Create the adaptergdscript
const GuaAutoAdapterScript := preload(
  "res://addons/gua/gua_auto_adapter.gd"
)
var ui := GuaAutoAdapterScript.new()

ui is the boundary between the Godot Control tree and the Gua runtime. Pass the root to attach, then call update as frames advance.

Top-level variables

NameType / defaultPurpose
start_inspector_bridge_on_readybool / trueWhether to start the in-game WebSocket bridge from _ready.
inspector_bridge_portint / 8765The port used by Inspector and MCP. GUA_BRIDGE_PORT can override it.
uiGuaAutoAdapterCollects Controls, dispatches requests, and publishes snapshots.
loadingbool / falseSelects the logical title or loading screen.
title_labelLabelThe title heading, reflected as a semantic text node.
start_buttonButtonThe primary action; its pressed signal calls _show_loading.
settings_buttonButtonA second button used to demonstrate collection of multiple actions.
loading_labelLabelThe loading text revealed after the start action.
visual_e2eboolEnabled by GUA_VISUAL_E2E=1 to add visual-test controls and capture.
v2_e2eboolEnabled by GUA_V2_E2E=1 to add protocol-v2 form fixtures.
visual_e2e_update_elapsedfloat / 0.0Throttles visual-E2E updates to roughly 0.1-second intervals.

Lifecycle functions

FunctionWhenGua responsibility
_ready()Scene readyReads environment, builds UI, attaches the adapter, publishes once, and starts the bridge.
_process(delta)Every frameCalls ui.update(_current_screen()) with the latest Control state.
_current_screen()Before updateMaps loading to the logical screen name title or loading.

UI construction and operations

FunctionPurpose
_build_ui()Creates the normal Labels and Buttons, including layout and signals.
_build_visual_e2e_controls()Adds a sensitive LineEdit, CheckBox, and OptionButton for visual comparison and redaction tests.
_build_v2_e2e_controls()Adds TextEdit, selection, tab, and scroll targets for protocol-v2 operations.
_show_loading()Updates visibility and enabled state after start, then publishes immediately.
_capture_visual_e2e()Waits for rendered frames, then explicitly publishes a viewport PNG.
_start_inspector_bridge()Starts the in-game bridge and prints either its URL or an actionable warning.