diff --git a/Source/ComboInput/Private/Components/ComboManagerComponent.cpp b/Source/ComboInput/Private/Components/ComboManagerComponent.cpp index 51ded3c..83a1a9d 100644 --- a/Source/ComboInput/Private/Components/ComboManagerComponent.cpp +++ b/Source/ComboInput/Private/Components/ComboManagerComponent.cpp @@ -64,16 +64,22 @@ void UComboManagerComponent::ActivateComboInput(const UComboInputAsset *Input) const TObjectPtr CurrentNode = (this->ActiveNode ? this->ActiveNode : this->DefaultStartNode); checkf(CurrentNode, TEXT("No combo sequence nodes available.")); - if (CurrentNode->ComboBranch.Contains(Input)) + const FComboSequenceAction *ActionData = CurrentNode->ComboBranch.Find(Input); + // If this node has an action we can activate, then activate it. + if (ActionData && ActionData->ComboAction) { - const FComboSequenceAction &ActionData = CurrentNode->ComboBranch[Input]; - if (ActionData.ComboAction) - { - this->BeginNodeTransition(ActionData.NextNode); - this->BroadcastDelegates(ActionData.ComboAction, EComboActionTriggerEvent::Activated); - UE_LOG(LogComboManagerComponent, Verbose, TEXT("%s activated"), *ActionData.ComboAction->ActionName.ToString()); - } + this->BeginNodeTransition(ActionData->NextNode); + this->BroadcastDelegates(ActionData->ComboAction, EComboActionTriggerEvent::Activated); + UE_LOG(LogComboManagerComponent, Verbose, TEXT("%s activated"), *ActionData->ComboAction->ActionName.ToString()); } + // Otherwise, see if we have a fallback we can use. + else if (const TObjectPtr &ComboAction = *this->FallbackActions.Find(Input)) + { + this->ResetCombo(); + this->BroadcastDelegates(ComboAction, EComboActionTriggerEvent::Activated); + UE_LOG(LogComboManagerComponent, Verbose, TEXT("Fallback action %s activated"), *ComboAction->ActionName.ToString()); + } + // Simply do nothing if there is no action to be performed. else { UE_LOG(LogComboManagerComponent, Verbose, TEXT("No branch found for this action")); @@ -93,11 +99,7 @@ void UComboManagerComponent::BeginNodeTransition(const UComboSequenceNode *NextN this->ActiveNode = NextNode; this->GetWorld()->GetTimerManager().SetTimer(this->FinishTransitionTimer, this, &UComboManagerComponent::FinishTransition, 0.5f); - this->GetWorld()->GetTimerManager().SetTimer(this->DEBUG__ResetComboTimer, this, &UComboManagerComponent::DEBUG__ResetCombo, 1.0f); -} -void UComboManagerComponent::DEBUG__ResetCombo() -{ - this->ActiveNode = this->PreviousNode = nullptr; + this->GetWorld()->GetTimerManager().SetTimer(this->DEBUG__ResetComboTimer, this, &UComboManagerComponent::ResetCombo, 1.0f); } void UComboManagerComponent::FinishTransition() @@ -105,6 +107,12 @@ void UComboManagerComponent::FinishTransition() this->PreviousNode = this->ActiveNode; } +void UComboManagerComponent::ResetCombo() +{ + this->GetWorld()->GetTimerManager().ClearTimer(this->DEBUG__ResetComboTimer); + this->ActiveNode = this->PreviousNode = nullptr; +} + void UComboManagerComponent::BroadcastDelegates(const UComboAction *ComboAction, const EComboActionTriggerEvent &TriggerEvent) { diff --git a/Source/ComboInput/Public/Components/ComboManagerComponent.h b/Source/ComboInput/Public/Components/ComboManagerComponent.h index ef77664..1593cdb 100644 --- a/Source/ComboInput/Public/Components/ComboManagerComponent.h +++ b/Source/ComboInput/Public/Components/ComboManagerComponent.h @@ -66,6 +66,11 @@ protected: UPROPERTY(BlueprintReadOnly, EditDefaultsOnly) FComboOffsetMap OffsetMap; + // A list of inputs to map to actions by default. If the active combo sequence node + // doesn't handle this action, this list will be used as a fallback whenever possible. + UPROPERTY(BlueprintReadOnly, EditDefaultsOnly) + TMap, TObjectPtr> FallbackActions; + UPROPERTY(BlueprintReadOnly, EditDefaultsOnly) TMap, float> DEBUG__UnlockTimers; @@ -75,11 +80,11 @@ protected: private: void BeginNodeTransition(const class UComboSequenceNode *NextNode); void FinishTransition(); + void ResetCombo(); void BroadcastDelegates(const class UComboAction *ComboAction, const EComboActionTriggerEvent &TriggerEvent); void DEBUG__UnlockAction(TObjectPtr Unlock); - void DEBUG__ResetCombo(); const class UComboSequenceNode *ActiveNode = nullptr; const class UComboSequenceNode *PreviousNode = nullptr;