7#include "ArticyRuntimeModule.h"
8#include "Interfaces/ArticyReflectable.h"
9#if ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >0
10#include "AssetRegistry/AssetRegistryModule.h"
12#include "AssetRegistryModule.h"
14#include "ShadowStateManager.h"
15#include "ArticyExpressoScripts.h"
16#include "ArticyGlobalVariables.generated.h"
22#define ARTICY_VARIABLE_ACCESS(T) \
23 T& operator=(const T &NewValue) \
26 return Setter<TRemoveReference<decltype(*this)>::Type>(NewValue); \
28 const T& Get() const \
33 operator const T &() const \
47DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnGVChanged,
UArticyVariable*, Variable);
53template<
typename Type>
54struct ArticyShadowState
56 ArticyShadowState(
const uint32& level,
const Type& value) : Level(level), Value(value) { }
63struct ARTICYRUNTIME_API FArticyGvName
69 FArticyGvName() =
default;
70 FArticyGvName(
const FName FullVariableName);
71 FArticyGvName(
const FName VariableNamespace,
const FName VariableName);
73 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category =
"Articy")
75 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category =
"Articy")
77 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category =
"Articy")
87UCLASS(Abstract, BlueprintType)
97 UPROPERTY(BlueprintAssignable, Category =
"Callback")
100 template<typename Type>
111 template<
typename Type,
typename ValueType>
112 ValueType& Setter(
const ValueType &NewValue)
114 auto Instance =
static_cast<Type*
>(
this);
118 const auto& storeLevel = GetStoreShadowLevel();
119 const auto& shadowLevel = GetShadowLevel(Instance);
120 if(storeLevel > shadowLevel)
125 RegisterOnStorePop(Instance);
130 ensure(storeLevel == shadowLevel);
133 Instance->Value = NewValue;
135 OnVariableChanged.Broadcast(
this);
137 return Instance->Value;
140 template<
typename Type>
141 void PopState(Type* Instance)
143 if(ensure(GetStoreShadowLevel() == GetShadowLevel(Instance)))
144 Instance->Value = Instance->Shadows.Pop().Value;
147 template<
typename Type>
148 static uint32 GetShadowLevel(Type* Instance);
149 uint32 GetStoreShadowLevel()
const;
152 UPROPERTY(BlueprintReadOnly, Category =
"Articy")
160 template<typename Type>
161 void RegisterOnStorePop(Type* Instance);
172 typedef int UnderlyingType;
174 friend UArticyVariable;
180 ARTICY_VARIABLE_ACCESS(
int)
183 int& operator+=(
const int &Val) {
return *
this =
Value + Val; }
184 int& operator-=(
const int &Val) {
return *
this =
Value - Val; }
185 int& operator*=(
const int &Val) {
return *
this =
Value * Val; }
186 int& operator/=(
const int &Val) {
return *
this =
Value / Val; }
194 int& operator++() {
return *
this =
Value + 1; }
202 int& operator--() {
return *
this =
Value - 1; }
206 if (NewVal.
Type == ExpressoType::Float)
214 if (Val.
Type == ExpressoType::Float)
222 if (Val.
Type == ExpressoType::Float)
230 if (Val.
Type == ExpressoType::Float)
238 if (Val.
Type == ExpressoType::Float)
248 UFUNCTION(BlueprintCallable, Category =
"ValueAccess")
249 int
Set(
int NewValue) {
return *
this = NewValue; }
253 UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category =
"Articy")
266 return v1.Get() + v2.Get();
268static int operator+(
int k,
const UArticyInt& v)
272static int operator+(
const UArticyInt& v,
int k)
279 return v1.Get() - v2.Get();
281static int operator-(
int k,
const UArticyInt& v)
285static int operator-(
const UArticyInt& v,
int k)
292 return v1.Get() * v2.Get();
294static int operator*(
int k,
const UArticyInt& v)
298static int operator*(
const UArticyInt& v,
int k)
305 return v1.Get() / v2.Get();
307static int operator/(
int k,
const UArticyInt& v)
311static int operator/(
const UArticyInt& v,
int k)
324 typedef bool UnderlyingType;
326 friend UArticyVariable;
331 ARTICY_VARIABLE_ACCESS(
bool)
342 UFUNCTION(BlueprintCallable, Category =
"ValueAccess")
343 bool
Set(
bool NewValue) {
return *
this = NewValue; }
348 UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category =
"Articy")
363 typedef FString UnderlyingType;
365 friend UArticyVariable;
370 ARTICY_VARIABLE_ACCESS(FString)
379 if (NewValue.
Type == ExpressoType::Int)
380 return Value = ArticyHelpers::Uint64ToObjectString(NewValue.
GetInt());
385 bool operator ==(
const FString& text)
const {
return Value.Equals(text); }
386 bool operator !=(
const FString& text)
const {
return !this->operator==(text); }
387 bool operator ==(
const FString&& text)
const {
return Value.Equals(text); }
388 bool operator !=(
const FString&& text)
const {
return !this->operator==(text); }
389 bool operator ==(
const char*
const text)
const {
return Value.Equals(text); }
390 bool operator !=(
const char*
const text)
const {
return !this->operator==(text); }
396 UFUNCTION(BlueprintCallable, Category =
"ValueAccess")
397 FString
Set(FString NewValue) {
return *
this = NewValue; }
401 UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category =
"Articy")
415 UPROPERTY(VisibleAnywhere, Category =
"ArticyGlobalVariables")
416 TArray<UArticyVariable*> Variables;
423 UPROPERTY(BlueprintAssignable, Category =
"Callback")
426 UFUNCTION(BlueprintCallable, Category =
"ArticyGlobalVariables", meta = (keywords =
"global variables"))
427 const TArray<
UArticyVariable*> GetVariables()
const {
return Variables; }
429 UFUNCTION(BlueprintCallable, Category =
"ArticyGlobalVariables", meta =(DeterminesOutputType =
"Type", keywords =
"global variables"))
432 TArray<UObject*> subobjects;
433 GetDefaultSubobjects(subobjects);
434 TArray<UArticyVariable*> articyVars;
435 for (
int i = 0; i < subobjects.Num(); i++)
437 const bool bIsA = subobjects[i]->IsA(Type);
449 const TArray<T*> GetVariables()
451 TArray<UObject*> subobjects;
452 GetDefaultSubobjects(subobjects);
453 TArray<T*> articyVars;
454 for (
int i = 0; i < subobjects.Num(); i++)
456 T* isT = Cast<T>(subobjects[i]);
470 template <typename Type>
484 virtual FPrimaryAssetId GetPrimaryAssetId()
const override {
return FPrimaryAssetId(FName(TEXT(
"ArticyGlobalVariables")), GetFName()); }
501 UFUNCTION(BlueprintCallable, Category =
"Packages")
504 UFUNCTION(BlueprintCallable, Category=
"Getter")
507 UFUNCTION(BlueprintCallable, Category =
"Getter")
508 const TArray<UArticyBaseVariableSet*> GetVariableSets()
const {
return VariableSets; }
513 UFUNCTION(BlueprintCallable, Exec, Category =
"Articy")
516 UFUNCTION(BlueprintCallable, Category=
"Getter")
518 UFUNCTION(BlueprintCallable, Category=
"Getter")
520 UFUNCTION(BlueprintCallable, Category=
"Getter")
523 UFUNCTION(BlueprintCallable, Category=
"Setter")
525 UFUNCTION(BlueprintCallable, Category=
"Setter")
527 UFUNCTION(BlueprintCallable, Category=
"Setter")
530 UFUNCTION(BlueprintCallable, Category=
"Debug")
532 UFUNCTION(BlueprintCallable, Category=
"Debug")
548 TArray<UArticyBaseVariableSet*> VariableSets;
551 bool bLogVariableAccess =
false;
555 static TWeakObjectPtr<UArticyGlobalVariables> Clone;
558 static TMap<FName, TWeakObjectPtr<UArticyGlobalVariables>> OtherClones;
560 TArray<TMap<FArticyId, int>> VisitedNodes;
561 TArray<TMap<FArticyId, bool>> bIsFallbackEvaluation;
563 template <
typename ArticyVariableType,
typename VariablePayloadType>
564 void SetVariableValue(
const FName Namespace,
const FName Variable,
const VariablePayloadType Value);
565 template <
typename ArticyVariableType,
typename VariablePayloadType>
566 void SetVariableValue(
const FName FullVariableName,
const VariablePayloadType Value);
568 template<
typename ArticyVariableType,
typename VariablePayloadType>
569 const VariablePayloadType& GetVariableValue(
const FName Namespace,
const FName Variable,
bool& bSucceeded);
570 template<
typename ArticyVariableType,
typename VariablePayloadType>
571 const VariablePayloadType& GetVariableValue(
const FName FullVariableName,
bool& bSucceeded);
578template <
typename Type>
588 Setter<Type>(NewValue);
591 OnVariableChanged.AddDynamic(Set, &UArticyBaseVariableSet::BroadcastOnVariableChanged);
594template <
typename Type>
595uint32 UArticyVariable::GetShadowLevel(Type* Instance)
597 return Instance->Shadows.Num() > 0 ? Instance->Shadows.Last().Level : 0;
600template <
typename Type>
601void UArticyVariable::RegisterOnStorePop(Type* Instance)
603#if __cplusplus >= 202002L
604 Store->RegisterOnPopState([=,
this] { this->PopState(Instance); });
606 Store->RegisterOnPopState([=] { this->PopState(Instance); });
610template <
typename ArticyVariableType,
typename VariablePayloadType>
611void UArticyGlobalVariables::SetVariableValue(
const FName Namespace,
const FName Variable,
const VariablePayloadType Value)
616 UArticyVariable** basePtr = set->GetPropPtr<UArticyVariable*>(Variable);
620 ArticyVariableType* typedPtr =
dynamic_cast<ArticyVariableType*
>(*basePtr);
623 auto& propValue = (*typedPtr);
626 if (bLogVariableAccess)
628 UE_LOG(LogArticyRuntime, Display, TEXT(
"Set variable %s::%s : Success"), *Namespace.ToString(), *Variable.ToString());
636 if (bLogVariableAccess)
638 UE_LOG(LogArticyRuntime, Error, TEXT(
"Unable to find variable: %s::%s. Variable does not exist or wrong type assumed."), *Namespace.ToString(), *Variable.ToString());
642template<
typename ArticyVariableType,
typename VariablePayloadType>
643const VariablePayloadType& UArticyGlobalVariables::GetVariableValue(
const FName Namespace,
const FName Variable,
bool& bSucceeded)
648 UArticyVariable** basePtr = set->GetPropPtr<UArticyVariable*>(Variable);
650 ArticyVariableType* typedPtr =
dynamic_cast<ArticyVariableType*
>(*basePtr);
654 auto& propValue = (*typedPtr);
657 if (bLogVariableAccess)
659 UE_LOG(LogArticyRuntime, Display, TEXT(
"Get variable %s::%s : Success"), *Namespace.ToString(), *Variable.ToString());
662 return propValue.Get();
666 if(bLogVariableAccess)
668 UE_LOG(LogArticyRuntime, Error, TEXT(
"Unable to find variable: %s::%s"), *Namespace.ToString(), *Variable.ToString());
672 static VariablePayloadType empty = VariablePayloadType();
Definition ArticyFlowObject.h:23
Definition ArticyReflectable.h:24
Definition ShadowStateManager.h:24
A data asset class for managing alternative global variables in the Articy runtime.
Definition ArticyAlternativeGlobalVariables.h:19
Definition ArticyGlobalVariables.h:412
FOnGVChanged OnVariableChanged
Definition ArticyGlobalVariables.h:424
Definition ArticyGlobalVariables.h:320
bool Value
Definition ArticyGlobalVariables.h:349
bool Set(bool NewValue)
Definition ArticyGlobalVariables.h:343
Definition ArticyFlowPlayer.h:29
Definition ArticyGlobalVariables.h:479
static UArticyGlobalVariables * GetRuntimeClone(const UObject *WorldContext, UArticyAlternativeGlobalVariables *GVs)
Definition ArticyGlobalVariables.cpp:234
static UArticyGlobalVariables * GetMutableOriginal()
Definition ArticyGlobalVariables.cpp:195
void UnloadGlobalVariables()
Definition ArticyGlobalVariables.cpp:294
void PrintGlobalVariable(FArticyGvName GvName)
Definition ArticyGlobalVariables.cpp:328
void PushSeen()
Definition ArticyGlobalVariables.cpp:622
bool Fallback(const IArticyFlowObject *Object)
Definition ArticyGlobalVariables.cpp:554
void ResetVisited()
Definition ArticyGlobalVariables.cpp:454
void SetFallbackEvaluation(const IArticyFlowObject *Object, bool Value)
Definition ArticyGlobalVariables.cpp:592
const int32 & GetIntVariable(FArticyGvName GvName, bool &bSucceeded)
Definition ArticyGlobalVariables.cpp:389
void EnableDebugLogging()
Definition ArticyGlobalVariables.cpp:438
void SetStringVariable(FArticyGvName GvName, const FString Value)
Definition ArticyGlobalVariables.cpp:430
void DisableDebugLogging()
Definition ArticyGlobalVariables.cpp:446
static UArticyGlobalVariables * GetDefault(const UObject *WorldContext)
Definition ArticyGlobalVariables.cpp:131
void SetBoolVariable(FArticyGvName GvName, const bool Value)
Definition ArticyGlobalVariables.cpp:410
void SetIntVariable(FArticyGvName GvName, const int32 Value)
Definition ArticyGlobalVariables.cpp:420
int GetSeenCounter(const IArticyFlowObject *Object) const
Definition ArticyGlobalVariables.cpp:466
int SetSeenCounter(const IArticyFlowObject *Object, int Value)
Definition ArticyGlobalVariables.cpp:491
int IncrementSeenCounter(const IArticyFlowObject *Object)
Definition ArticyGlobalVariables.cpp:523
const bool & GetBoolVariable(FArticyGvName GvName, bool &bSucceeded)
Definition ArticyGlobalVariables.cpp:378
UArticyBaseVariableSet * GetNamespace(const FName Namespace)
Definition ArticyGlobalVariables.cpp:309
void PopSeen()
Definition ArticyGlobalVariables.cpp:639
const FString & GetStringVariable(FArticyGvName GvName, bool &bSucceeded)
Definition ArticyGlobalVariables.cpp:400
Definition ArticyGlobalVariables.h:168
int Value
Definition ArticyGlobalVariables.h:254
int Set(int NewValue)
Definition ArticyGlobalVariables.h:249
Definition ArticyGlobalVariables.h:359
FString Value
Definition ArticyGlobalVariables.h:402
FString Set(FString NewValue)
Definition ArticyGlobalVariables.h:397
Definition ArticyGlobalVariables.h:89
FOnGVChanged OnVariableChanged
Definition ArticyGlobalVariables.h:98
FName GVName
Definition ArticyGlobalVariables.h:153
const FName & GetGVName() const
Definition ArticyGlobalVariables.h:104
Definition ArticyGlobalVariables.h:55
The ExpressoType struct represents a flexible data type used in the Articy runtime.
Definition ArticyExpressoScripts.h:26
virtual int64 & GetInt()
Retrieves the int64 value of the ExpressoType.
Definition ArticyExpressoScripts.cpp:845
virtual double & GetFloat()
Retrieves the double value of the ExpressoType.
Definition ArticyExpressoScripts.cpp:859
virtual FString & GetString()
Retrieves the string value of the ExpressoType.
Definition ArticyExpressoScripts.cpp:873
enum ExpressoType::EType Type
The type of the ExpressoType.
virtual bool & GetBool()
Retrieves the boolean value of the ExpressoType.
Definition ArticyExpressoScripts.cpp:831
Definition ArticyGlobalVariables.h:64
const FName & GetVariable()
Definition ArticyGlobalVariables.cpp:82
void SetByNamespaceAndVariable(const FName VariableNamespace, const FName VariableName)
Definition ArticyGlobalVariables.cpp:55
const FName & GetNamespace()
Definition ArticyGlobalVariables.cpp:69
void SetByFullName(const FName FullVariableName)
Definition ArticyGlobalVariables.cpp:38
const FName & GetFullName()
Definition ArticyGlobalVariables.cpp:95