ULimenPuzzleController
Overview
ULimenPuzzleController is an actor component that manages the state and logic of a puzzle. It listens for changes in puzzle elements, evaluates conditions based on these changes, and notifies when the puzzle is solved or any element is updated. This component is designed to be used with UPuzzleDefinition data assets to define the puzzle's structure and rules.
Properties
Type | Name | Access | Description |
|---|---|---|---|
FPuzzleStateDelegate | OnPuzzleStateChanged | BlueprintAssignable | Delegate called when the puzzle state changes. |
FPuzzleDelegate | OnPuzzleElementUpdated | BlueprintAssignable | Delegate called when any puzzle element is updated. |
TObjectPtr | PuzzleDefinition | EditAnywhere, Category="Puzzle" | The definition of the puzzle to be managed. |
Functions
Return Type | Signature | Description |
|---|---|---|
float | GetCompletionNormalized() const | Returns a normalized value representing the completion percentage of the puzzle. |
void | BeginPlay() override | Initializes the component and binds puzzle elements when the owning actor begins play. |
void | EndPlay(const EEndPlayReason::Type EndPlayReason) override | Resets the puzzle definition pointer when the owning actor ends play. |
void | AnyPuzzleElementChanged() | Recomputes the puzzle state and notifies listeners when any puzzle element changes. |
void | BindElements() | Binds to all |
bool | EvalElementOrNode(const FName& Id) | Evaluates whether a given element or node is active based on its ID. |
bool | EvalCached(const FName& Id) | Caches and evaluates the state of an element or node, using a cached value if available. |
void | Recompute() | Recomputes the puzzle's solved state by evaluating all elements and nodes. |
void | ResetTimerGate(FName NodeId) | Resets the timer gate for a specific node ID. |
bool | TimerGate(const FName& NodeId, const TArray & Inputs) | Evaluates a timer gate condition based on inputs from connected elements or nodes. |
void | AnyComponentActivated(UActorComponent* Component, bool bReset) | Handles the activation of any component and triggers a state recompute. |
void | AnyComponentDeactivated(UActorComponent* Component) | Handles the deactivation of any component and triggers a state recompute. |
Usage & Implementation Notes
Threading Constraints: This component operates on the game thread.
Replication Requirements: The
bSolvedproperty is replicated to ensure that all clients are aware of the puzzle's solved state.Memory Lifetime Management: The
PuzzleDefinitionPtris managed using a strong pointer to ensure it remains valid throughout the lifecycle of the component. Puzzle elements are stored as weak pointers to avoid memory leaks.Initialization Dependencies: This component requires a valid
UPuzzleDefinitionto function correctly, and it binds to puzzle elements in the world when the owning actor begins play.