PreviewBuilder
Summary
Section titled “Summary”PreviewBuilder
Purpose Manages the visual preview instance used during building placement. The class requires the core runtime objects up-front: BuildingSettings
, the GridTargetingState
, BuildingState
, and a GBLogger
. These are accepted in the constructor so the caller is explicit about required dependencies.
In addition, resolve_gb_dependencies(container)
exists to refresh or update dependencies from a GBCompositionContainer
if the container changes during runtime (rare for tests but supported). The GridTargetingState
is treated as the single source of truth for the positioner
— the preview will always query the latest positioner when creating the preview.
Methods
Section titled “Methods”func _init( p_building_settings: BuildingSettings, p_targeting_state: GridTargetingState, p_building_state: BuildingState, p_logger: GBLogger ) -> void
static func from_container( container: GBCompositionContainer ) -> PreviewBuilder
Factory: Create a PreviewBuilder from a composition container. This provides a DRY creation path used by systems/tests that have a
GBCompositionContainer
holding the required runtime objects.Args: p_building_settings: BuildingSettings - required settings (not always in container) container: GBCompositionContainer - used to resolve targeting_state, building_state, logger
Returns: PreviewBuilder - constructed and wired, or null on failure
func resolve_gb_dependencies( container: GBCompositionContainer ) -> bool
Refresh/resolve dependencies from the composition container. Returns: bool - True if dependencies were found, false otherwise.
func get_runtime_issues( ) -> Array[String]
Validates that all required dependencies are properly set. Returns: Array[String] - List of validation issues (empty if valid)
func initialize( p_building_settings: BuildingSettings, p_targeting_state: GridTargetingState, p_building_state: BuildingState, p_logger: GBLogger ) -> void
func create_preview( p_placeable: Placeable ) -> Node2D
Spawns a new preview for the given placeable. Clears the previous one if active.
func get_preview( ) -> Node2D
Get the object current previewed for placement
func clear_preview( )
Frees the active preview node.
func align_to_grid( collision_shape_global_position: Vector2 )
func update_position( p_position: Vector2 )
Repositions the preview in world space.
func has_active_preview( ) -> bool
Optional: Check if a preview is currently being shown.
Source
Section titled “Source”addons/grid_building/systems/building/components/preview_builder.gd
This API reference is automatically generated from the plugin source code. For implementation examples and usage guides, see the guides section.