More refactoring on Animation Queue Changed
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
|
||||
#include "AnimQueue.h"
|
||||
#include "UtilityLibrary.h"
|
||||
|
||||
FlxAnimationStep::FlxAnimationStep(uint64 hash, std::string_view body) {
|
||||
Finished = false;
|
||||
@@ -9,16 +10,14 @@ FlxAnimationStep::FlxAnimationStep(uint64 hash, std::string_view body) {
|
||||
Blueprint = UlxAnimationStepLibrary::AnimationStepGetString(*this, "bp");
|
||||
}
|
||||
|
||||
static bool ClearProperties(const FString& prefix, UObject* obj) {
|
||||
static void ClearProperties(const FString& prefix, UObject* obj, FProperty *except) {
|
||||
UClass* uclass = obj->GetClass();
|
||||
if (prefix.IsEmpty()) {
|
||||
return false;
|
||||
}
|
||||
FName prefixlo(prefix);
|
||||
FName prefixhi(prefix + TEXT("\xFFFF"));
|
||||
for (TFieldIterator<FProperty> It(uclass); It; ++It)
|
||||
{
|
||||
FProperty* fprop = *It;
|
||||
if (fprop == except) continue;
|
||||
bool match1 = (fprop->GetFName().Compare(prefixlo) > 0);
|
||||
bool match2 = (fprop->GetFName().Compare(prefixhi) < 0);
|
||||
if (match1 && match2) {
|
||||
@@ -26,7 +25,6 @@ static bool ClearProperties(const FString& prefix, UObject* obj) {
|
||||
fprop->ClearValue(pptr);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
#pragma optimize("", off)
|
||||
@@ -70,25 +68,66 @@ static bool SetProperty(const FString& prefix, UObject* obj, const FlxAnimationF
|
||||
}
|
||||
|
||||
#pragma optimize("", off)
|
||||
bool FlxAnimationStep::Unpack(const FString& prefix, UObject* into) const {
|
||||
UClass* uclass = into->GetClass();
|
||||
std::string_view body((const char*)(Body.GetData()), Body.Num());
|
||||
static FStructProperty *FindAnimationStepProperty(UClass *uclass, const FString &prefix) {
|
||||
FName nname(prefix + TEXT("Animation Step"));
|
||||
FStructProperty* fprop = FindFProperty<FStructProperty>(uclass, nname);
|
||||
if (fprop == nullptr) return nullptr;
|
||||
if (fprop->Struct != TBaseStructure<FlxAnimationStep>::Get()) return nullptr;
|
||||
return fprop;
|
||||
}
|
||||
|
||||
#pragma optimize("", off)
|
||||
void UlxAnimationStepLibrary::UnpackAnimationStep(bool &bChanged, FString &Action, const FlxAnimationStep& step, UObject* target, const FString& prefix) {
|
||||
bChanged = false;
|
||||
Action = TEXT("");
|
||||
|
||||
if (prefix.IsEmpty()) {
|
||||
UlxUtilityLibrary::Assert(false, TEXT("You may not pass an empty string for prefix"));
|
||||
return;
|
||||
}
|
||||
|
||||
UClass* uclass = target->GetClass();
|
||||
std::string_view body((const char*)(step.Body.GetData()), step.Body.Num());
|
||||
FlxAnimationStepDecoder decoder(body);
|
||||
bool ok = ClearProperties(prefix, into);
|
||||
|
||||
FStructProperty* stepproperty = FindAnimationStepProperty(uclass, prefix);
|
||||
if (stepproperty == nullptr) {
|
||||
UE_LOG(LogBlueprint, Error, TEXT("Target object: %s Prefix: %s"), *(target->GetName()), *prefix);
|
||||
UlxUtilityLibrary::Assert(false, TEXT("Target object does not have an variable named '<prefix> Animation Step'"));
|
||||
return;
|
||||
}
|
||||
|
||||
FlxAnimationStep* stepstorage = stepproperty->ContainerPtrToValuePtr<FlxAnimationStep>(target);
|
||||
uint64 oldhash = stepstorage->Hash;
|
||||
|
||||
FlxAnimationField actionfield;
|
||||
actionfield.Name = "action";
|
||||
actionfield.Persistent = false;
|
||||
actionfield.Type = SimpleDynamicTag::STRING;
|
||||
actionfield.S = "unknown";
|
||||
|
||||
// Decode everything. If an action field is found, save it for later.
|
||||
ClearProperties(prefix, target, stepproperty);
|
||||
while (!decoder.AtEOF()) {
|
||||
FlxAnimationField field = decoder.ReadField();
|
||||
if (Finished && !field.Persistent) continue;
|
||||
ok &= SetProperty(prefix, into, field);
|
||||
if ((field.Type == SimpleDynamicTag::STRING) && (field.Name == "action")) {
|
||||
actionfield.S = field.S;
|
||||
continue;
|
||||
}
|
||||
if (step.Finished && !field.Persistent) continue;
|
||||
SetProperty(prefix, target, field);
|
||||
}
|
||||
if (Finished) {
|
||||
FlxAnimationField field;
|
||||
field.Name = "action";
|
||||
field.Persistent = false;
|
||||
field.Type = SimpleDynamicTag::STRING;
|
||||
field.S = "idle";
|
||||
ok &= SetProperty(prefix, into, field);
|
||||
}
|
||||
return ok;
|
||||
|
||||
// Store the action field.
|
||||
if (step.Finished) actionfield.S = "idle";
|
||||
SetProperty(prefix, target, actionfield);
|
||||
|
||||
// Store the whole step.
|
||||
*stepstorage = step;
|
||||
|
||||
// Return the correct values.
|
||||
Action = FString(actionfield.S.size(), (const UTF8CHAR*)actionfield.S.data());
|
||||
bChanged = (step.Hash != oldhash);
|
||||
}
|
||||
|
||||
FString UlxAnimationStepLibrary::AnimationStepDebugString(const FlxAnimationStep& step) {
|
||||
@@ -96,10 +135,6 @@ FString UlxAnimationStepLibrary::AnimationStepDebugString(const FlxAnimationStep
|
||||
return FlxAnimationStepDecoder::DebugString(step.Finished, step.Finished, step.Hash, body);
|
||||
}
|
||||
|
||||
void UlxAnimationStepLibrary::UnpackAnimationStep(UObject* into, const FlxAnimationStep& step, const FString& prefix) {
|
||||
step.Unpack(prefix, into);
|
||||
}
|
||||
|
||||
static FlxAnimationField FindAnimationFieldLL(const FlxAnimationStep& step, std::string_view name) {
|
||||
std::string_view body((const char*)(step.Body.GetData()), step.Body.Num());
|
||||
FlxAnimationStepDecoder decoder(body);
|
||||
|
||||
Reference in New Issue
Block a user