Files
Fortis/Source/FORTIS_Taktika/Public/ResComStateManager.h
T
2022-05-26 18:32:27 +05:00

57 lines
1019 B
C++

// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
template<typename EnumType>
class ResComStateManager
{
protected:
TArray<EnumType> stateHistory;
EnumType nullobj;
public:
ResComStateManager() : nullobj(EnumType())
{
}
bool SetState(const EnumType& newState)
{
if (GetState() == newState)
return false;
stateHistory.Push(newState);
return true;
}
const EnumType& GetState() const
{
return static_cast<bool>(stateHistory.Num()) ? stateHistory[stateHistory.Num() - 1] : nullobj;
}
bool SetPrevState()
{
if (stateHistory.Num() < 2)
return false;
stateHistory.Pop();
return true;
}
const EnumType& GetPreviousState() const
{
return (stateHistory.Num() > 1) ? stateHistory[stateHistory.Num() - 2] : GetState();
}
void ClearAllStatesBesideLast()
{
auto lastState = GetState();
stateHistory.Empty();
SetState(lastState);
}
const TArray<EnumType>& GetHistory() const
{
return stateHistory;
}
};