Use ManipulationSystem static helpers for common operations:
1
2
3
4
5
6
7
8
9
10
11
12
var result = ManipulationSystem.try_move(entity, target_position)
# Returns: Dictionary with success status and any issues# Rotation var result = ManipulationSystem.try_rotate(entity, angle_degrees)
# Supports 90-degree increments or custom angles# Placement updatevar result = ManipulationSystem.try_place(entity, new_position)
# Demolitionvar result = ManipulationSystem.try_demolish(entity)
Required Components
Entities must have the following components for manipulation:
1
2
3
4
5
# Minimum required components for manipulation- ManipulationComponent # Tracks operation mode and state- GridPositionComponent # Current grid position- PlacementComponent # Placement state and status- PlaceableComponent # Placeable definition and settings
Manipulation Flow
1) Movement Flow
1
2
3
4
5
6
7
8
# Check if entity can moveif ManipulationSystem.can_move(entity):
# Attempt movementvar result = ManipulationSystem.try_move(entity, target_position)
if result.success:
# Listen for completion ManipulationSignalBus.entity_moved.emit(entity, target_position)
2) Rotation Flow
1
2
3
4
5
# Rotate by 90 degreesvar result = ManipulationSystem.try_rotate(entity, 90)
# Or use enum for cardinal directionsvar result = ManipulationSystem.try_rotate_to_cardinal(entity, Direction.NORTH)
3) Demolition Flow
1
2
3
4
5
6
# Initiate demolitionvar result = ManipulationSystem.try_demolish(entity)
if result.success:
# Demolition queued - listen for completion PlacementSignalBus.placement_demolished.emit(entity)
Operation States
ManipulationComponent tracks the current operation state:
1
2
3
4
5
6
7
enum OperationMode {
IDLE, # No active operation PREVIEW_MOVE, # Previewing potential move PREVIEW_ROTATE,# Previewing potential rotation EXECUTING, # Operation in progress CANCELING # Canceling current operation}
Constraint System
Manipulation can be constrained via templates:
1
2
3
4
5
6
# Load constraints from templatevar template: PlaceableTemplate = load("res://templates/building.tres")
var constraints = template.manipulation_constraints
# Apply to manipulationMovementManipulationSystem.apply_constraints(entity, constraints)
Common constraints:
Movement bounds: Limit how far an entity can move
Rotation limits: Restrict rotation angles
Overlap prevention: Block manipulation if collisions would result
Preview Integration
Manipulation workflows integrate with preview systems:
1
2
3
4
5
6
7
# Enable preview during manipulationPreviewSystem.enable_for_entity(entity)
# Update preview based on potential manipulationvar preview_state = PreviewSystem.calculate_preview(entity, target_position)
# Preview states: NEUTRAL | VALID | INVALID
Error Handling
1
2
3
4
5
6
7
8
9
10
11
var result = ManipulationSystem.try_move(entity, target_position)
ifnot result.success:
# Handle specific error typesmatch result.error_code:
ResultCode.OUT_OF_BOUNDS:
show_ui_message("Cannot move outside grid bounds")
ResultCode.COLLISION:
show_ui_message("Space is occupied")
ResultCode.INSUFFICIENT_RESOURCES:
show_ui_message("Not enough resources")
Recommended Flow
Ensure entity has ManipulationComponent + required placement/grid components.
Trigger operation via facade or specific manipulation system.
Listen to manipulation/placement signal buses for outcomes.
Reflect results in UI and selection state.
Test Verification
This guide’s manipulation workflows are validated by test suites: