BuildingSystem
Summary
Section titled “Summary”Manages placement of objects in the game world.
Handles preview, placement validation, and build actions. Uses tile collision indicators to show valid/invalid spots before placement. Checks all rules before adding objects to the world and emits signals for build success or failure.
Constants
Section titled “Constants”const WARNING_INVALID_PLACEABLE = “Invalid placeable resource. Can’t instantiate. [%s]”
Tracks drag events for build button. InputEventScreenDrag instance used to track drag events for build actions. Updated as the user drags to new tiles during multi-build mode.
const WARNING_NO_PREVIEW = “No preview instance created to instantiate yet. Returning null.”
Properties
Section titled “Properties”placement_polygons: Array[CollisionPolygon2D]
Drag build manager for multi-tile placement.
Instantiates building objects for placement.
Tracks tiles where placement has been attempted during current drag session
Collision polygons for placement indicators.
preview_layer: int
Preview layer index for buildable/unbuildable tiles.
selected_placeable: Placeable
Currently selected placeable resource.
indicators_group: Node2D
Parent node for collision indicators.
Methods
Section titled “Methods”get_building_state( )
The report of the active ongoing placement
legacy accessors expected in some validator/integration tests
get_targeting_state( )
check_ready_to_build( ) -> bool
Returns true if system is ready to build. Checks if the system is ready to build by validating the selected placeable and build context. Returns true if all build requirements are met and no issues are found.
is_in_build_mode( ) -> bool
Returns true if the building system is currently in build mode. Checks the current mode state to determine if build mode is active.
exit_build_mode( ) -> void
Exits build mode and cleans up all build-related elements. Sets the mode to OFF, clears the preview, and tears down indicators.
resolve_gb_dependencies( p_container: GBCompositionContainer ) -> void
try_build( ) -> PlacementReport
Attempts to place a building at the current preview location if all placement rules pass. Validates all placement rules and emits success or failure signals based on the result. Returns the built Node2D if successful, null otherwise.
is_drag_building( ) -> bool
Determine whether or not the building system is currently drag building through the DragBuildManager
try_build_at_position( p_global_position: Vector2 ) -> Node2D
Legacy API compatibility method for tests Attempts to place a building at the specified position Temporarily moves the targeting system to the position, attempts placement, then restores position
enter_build_mode( p_placeable: Placeable ) -> PlacementReport
Sets up a preview instance for the selected placeable. Switches to build mode, clears previous preview, and creates a new preview instance. Returns true if setup is successful.
p_placeable
: Placeable - Placeable resource to create preview forclear_preview( )
Removes the current preview instance. Removes the current preview instance and resets placement manager state. Called when exiting build mode or clearing preview.
instance_preview( p_placeable: Placeable ) -> Node2D
Creates a preview instance with limited functionality. Strips scripts not needed for preview and replaces root node script if set in config. Used for visual feedback before placement.
p_placeable
: Placeable - Placeable resource to create preview instance forget_runtime_issues( ) -> Array[String]
Validates that all required dependencies are set. This is called automatically when entering build mode, but can also be called manually after scene loads to check if all dependencies are properly configured. Returns list of validation issues (empty if valid).
get_builder_owner( ) -> GBOwner
Get the current GBOwner of the building object which is the root node of the GBOwner in the active GBOwnerContext that is assigned to the BuildingState
start_drag( )
Starts drag-building mode. Initiates drag-building mode if enabled in settings. Sets up drag manager and starts tracking drag events.
stop_drag( )
Stops drag-building mode. Ends drag-building mode if enabled in settings. Stops drag manager and drag event tracking. Private helper to stop drag operation when multi-build is enabled.
report_built( p_report: PlacementReport ) -> void
Reports a successful build action through the BuildingState
report_failure( p_report: PlacementReport ) -> void
Reports a failed build action through the BuildingState
get_lazy_drag_manager( ) -> DragBuildManager
Private lazy getter for drag build manager. Creates and configures the manager if it doesn’t exist.
return
: DragBuildManager - The drag build manager instance
Source
Section titled “Source”addons/grid_building/systems/building/building_system.gd
This page was auto-generated from GDScript source. Edit the source file to improve documentation.
Generated on 2025-09-07