Class CollisionTestSetup2D
- Namespace
- GridPlacement.GDScript
- Assembly
- MoonBark.GridPlacement.GDScript.dll
CollisionTestSetup2D [codeblock] var test_setup = CollisionTestSetup2D.new(collision_object, Vector2(16, 16)) if test_setup.validate_setup(): # Use test_setup.rect_collision_test_setups for collision testing pass [/codeblock]\n\nBuilds collision test parameters for a CollisionObject2D to enable placement indicators to perform accurate collision checks against object geometry.\n\n[b]Purpose:[/b] Converts CollisionObject2D shapes into testable RectCollisionTestingSetup instances for collision validation during placement operations.\n\n[b]Key Features:[/b] • Creates one RectCollisionTestingSetup per shape owner • Expands test areas using configurable shape_stretch_size • Supports CollisionShape2D and CollisionPolygon2D nodes • Comprehensive error reporting via issues array\n\n[b]Quick Start:[/b] [codeblock] var test_setup = CollisionTestSetup2D.new(collision_object, Vector2(16, 16)) if test_setup.validate_setup(): # Use test_setup.rect_collision_test_setups for collision testing pass [/codeblock]\n\n[b]Advanced Documentation:[/b] For detailed usage, API reference, and troubleshooting, see: https://gridbuilding.pages.dev/api/v5.0.0/CollisionTestSetup\n\n[b]Dependencies:[/b] RectCollisionTestingSetup, GBGeometryUtils
class CollisionTestSetup2D extends RefCounted
Properties
collision_object
The CollisionObject2D being analyzed for collision testing.
var collision_object: CollisionObject2D:
shape_stretch_size
Size to stretch collision shapes for comprehensive tile coverage. Recommended: Use your tile size (e.g., Vector2(16, 16) for 16x16 tiles). See advanced documentation for detailed sizing guidance.
var shape_stretch_size: Vector2
rect_collision_test_setups
Array of RectCollisionTestingSetup instances, one per shape owner. Use these setups to perform collision tests for placement indicators.
var rect_collision_test_setups: Array[RectCollisionTestingSetup]
issues
Issues discovered during collision test setup. Check this array after initialization to identify configuration problems.
var issues: Array[String] = []
no_issues
var no_issues = true
setups
var setups: Dictionary[Node2D, CollisionTestSetup2D] = {}
tile_set
var tile_set = targeting_state.get_target_map_tile_set()
collision_shape_stretch_amount
var collision_shape_stretch_amount = tile_set.tile_size * 2.0
shapes_by_owner
var shapes_by_owner: Dictionary[Node2D, Array] = GBGeometryUtils.get_all_collision_shapes_by_owner(test_node)
setups_dict
var setups_dict = create_test_setups_for_collision_owners(shapes_by_owner, targeting_state)
result
var result: Array[CollisionTestSetup2D] = []
owner_test_params_set
var owner_test_params_set: Array[RectCollisionTestingSetup] = []
shape_owner_ids
var shape_owner_ids = p_collision_object.get_shape_owners()
shape_owner_node
var shape_owner_node = p_collision_object.shape_owner_get_owner(shape_owner_id)
owner_shape_count
var owner_shape_count = p_collision_object.shape_owner_get_shape_count(shape_owner_id)
owned_shapes
var owned_shapes: Array[Shape2D] = []
found_shape
var found_shape = p_collision_object.shape_owner_get_shape(shape_owner_id, shape_index)
owner_testing_rect
var owner_testing_rect = _get_testing_rect_for_owner(shape_owner_node)
rect_test_parameters
var rect_test_parameters = RectCollisionTestingSetup.new(
shape
var shape = p_shape_owner.shape
shape_rect
var shape_rect = p_shape_owner.shape.get_rect()
adjusted_rect
var adjusted_rect = p_base_rect
polygon
var polygon: PackedVector2Array = p_shape_owner.polygon
polygon_rect
var polygon_rect: Rect2 = GBGeometryUtils.points_array_to_rect_2d(polygon, p_shape_owner.position)
adjusted_rect
var adjusted_rect = p_base_rect
origin
var origin = p_shape_owner_global_transform.get_origin()
adjusted_rect
var adjusted_rect = p_base_rect
Methods
add_issue
func add_issue(p_issue: String) -> void:
Parameters
p_issue
Returns
free_testing_nodes
func free_testing_nodes() -> void:
Returns
validate_setup
func validate_setup() -> bool:
Returns
create_test_setups_for_collision_owners
static func create_test_setups_for_collision_owners( owner_shapes: Dictionary[Node2D, Array],
create_test_setups_from_test_node
static func create_test_setups_from_test_node( test_node: Node2D,