Class AdjacentToCategoryRule
- Namespace
- GridPlacement.GDScript
- Assembly
- MoonBark.GridPlacement.GDScript.dll
Rule that requires an object placement to have at least one adjacent cell containing a placed object whose [ScenePlacementEntry.profiles] include the [member required_profile].\n\nUses [AdjacencyEvaluator] for shared adjacency logic (converged with [AdjacencyRequiredRule] in the terrain domain). Object-domain adjacency checks the scene tree for [PlaceableInstance] components via physics point queries at neighbor cells.\n\nExample: a fence placeable tagged "fence" requires at least one adjacent cell occupied by another "fence"-tagged object.
class AdjacentToCategoryRule extends TileCheckRule
Properties
required_profile
The category tag that must be matched by at least one neighboring cell.
@export var required_profile: PlacementProfile
min_neighbors
Minimum number of matching neighbor cells required.
@export_range(1, 8) var min_neighbors: int = 1
include_diagonal
Whether to include diagonal neighbors in the search.
@export var include_diagonal: bool = false
error_message
Descriptive error message shown when validation fails.
@export var error_message: String = "Must be placed adjacent to an existing object of the same category."
result
var result = RuleResult.new(self)
target_map
var target_map = _grid_targeting_state.target_map
dirs
var dirs: Array[Vector2i] = [
footprint_cells
var footprint_cells: Array[Vector2i] = get_tile_positions()
total_matches
var total_matches = 0
checked_cells
var checked_cells: Dictionary = {}
neighbor
var neighbor = cell + dir
global_pos
var global_pos = p_map.to_global(p_map.map_to_local(p_cell))
world_2d
var world_2d = p_map.get_world_2d()
space_state
var space_state = world_2d.direct_space_state
query
var query = PhysicsPointQueryParameters2D.new()
results
var results = space_state.intersect_point(query)
collider
var collider = res.get("collider")
placeable_instance
var placeable_instance: PlaceableInstance = PlacementSearchUtils.find_first(collider, PlaceableInstance)
ppath
var ppath: String = placeable_instance.get("placeable_path", "")
placeable
var placeable: ScenePlacementEntry = load(ppath) as ScenePlacementEntry
Methods
get_supported_actions
func get_supported_actions() -> Array[int]:
Returns
validate_placement
func validate_placement() -> RuleResult: