Implemented fallback actions, so combo inputs that aren't mapped to the current combo sequence node, or any node, can still have an action associated with them.

This commit is contained in:
Jamie Greunbaum 2023-09-17 12:25:04 -04:00
parent b24d7af1a3
commit 1d2dcdd693
2 changed files with 27 additions and 14 deletions

View File

@ -64,16 +64,22 @@ void UComboManagerComponent::ActivateComboInput(const UComboInputAsset *Input)
const TObjectPtr<const UComboSequenceNode> CurrentNode = (this->ActiveNode ? this->ActiveNode : this->DefaultStartNode); const TObjectPtr<const UComboSequenceNode> CurrentNode = (this->ActiveNode ? this->ActiveNode : this->DefaultStartNode);
checkf(CurrentNode, TEXT("No combo sequence nodes available.")); 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]; this->BeginNodeTransition(ActionData->NextNode);
if (ActionData.ComboAction) 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<const UComboAction> &ComboAction = *this->FallbackActions.Find(Input))
{ {
this->BeginNodeTransition(ActionData.NextNode); this->ResetCombo();
this->BroadcastDelegates(ActionData.ComboAction, EComboActionTriggerEvent::Activated); this->BroadcastDelegates(ComboAction, EComboActionTriggerEvent::Activated);
UE_LOG(LogComboManagerComponent, Verbose, TEXT("%s activated"), *ActionData.ComboAction->ActionName.ToString()); UE_LOG(LogComboManagerComponent, Verbose, TEXT("Fallback action %s activated"), *ComboAction->ActionName.ToString());
}
} }
// Simply do nothing if there is no action to be performed.
else else
{ {
UE_LOG(LogComboManagerComponent, Verbose, TEXT("No branch found for this action")); 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->ActiveNode = NextNode;
this->GetWorld()->GetTimerManager().SetTimer(this->FinishTransitionTimer, this, &UComboManagerComponent::FinishTransition, 0.5f); this->GetWorld()->GetTimerManager().SetTimer(this->FinishTransitionTimer, this, &UComboManagerComponent::FinishTransition, 0.5f);
this->GetWorld()->GetTimerManager().SetTimer(this->DEBUG__ResetComboTimer, this, &UComboManagerComponent::DEBUG__ResetCombo, 1.0f); this->GetWorld()->GetTimerManager().SetTimer(this->DEBUG__ResetComboTimer, this, &UComboManagerComponent::ResetCombo, 1.0f);
}
void UComboManagerComponent::DEBUG__ResetCombo()
{
this->ActiveNode = this->PreviousNode = nullptr;
} }
void UComboManagerComponent::FinishTransition() void UComboManagerComponent::FinishTransition()
@ -105,6 +107,12 @@ void UComboManagerComponent::FinishTransition()
this->PreviousNode = this->ActiveNode; 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) void UComboManagerComponent::BroadcastDelegates(const UComboAction *ComboAction, const EComboActionTriggerEvent &TriggerEvent)
{ {

View File

@ -66,6 +66,11 @@ protected:
UPROPERTY(BlueprintReadOnly, EditDefaultsOnly) UPROPERTY(BlueprintReadOnly, EditDefaultsOnly)
FComboOffsetMap OffsetMap; 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<const class UComboInputAsset>, TObjectPtr<const class UComboAction>> FallbackActions;
UPROPERTY(BlueprintReadOnly, EditDefaultsOnly) UPROPERTY(BlueprintReadOnly, EditDefaultsOnly)
TMap<TObjectPtr<const class UComboInputAsset>, float> DEBUG__UnlockTimers; TMap<TObjectPtr<const class UComboInputAsset>, float> DEBUG__UnlockTimers;
@ -75,11 +80,11 @@ protected:
private: private:
void BeginNodeTransition(const class UComboSequenceNode *NextNode); void BeginNodeTransition(const class UComboSequenceNode *NextNode);
void FinishTransition(); void FinishTransition();
void ResetCombo();
void BroadcastDelegates(const class UComboAction *ComboAction, const EComboActionTriggerEvent &TriggerEvent); void BroadcastDelegates(const class UComboAction *ComboAction, const EComboActionTriggerEvent &TriggerEvent);
void DEBUG__UnlockAction(TObjectPtr<const class UComboInputAsset> Unlock); void DEBUG__UnlockAction(TObjectPtr<const class UComboInputAsset> Unlock);
void DEBUG__ResetCombo();
const class UComboSequenceNode *ActiveNode = nullptr; const class UComboSequenceNode *ActiveNode = nullptr;
const class UComboSequenceNode *PreviousNode = nullptr; const class UComboSequenceNode *PreviousNode = nullptr;