-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathInt32AttributesLibrary.h
More file actions
161 lines (134 loc) · 5.87 KB
/
Int32AttributesLibrary.h
File metadata and controls
161 lines (134 loc) · 5.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
// Copyright 2015-2020 Piperift. All Rights Reserved.
#pragma once
#include <CoreMinimal.h>
#include <Kismet/BlueprintFunctionLibrary.h>
#include "Int32Attr.h"
#include "Int32AttributesLibrary.generated.h"
/**
*
*/
UCLASS()
class ATTRIBUTES_API UInt32AttributesLibrary : public UBlueprintFunctionLibrary
{
GENERATED_BODY()
public:
/** @return true when two Attributes are the same */
UFUNCTION(BlueprintPure, Category = Attributes, meta = (CompactNodeTitle = "=="))
static FORCEINLINE bool Is(const FInt32Attr& A, const FInt32Attr& B) { return A == B; }
/** @return true when two Attributes are not the same */
UFUNCTION(BlueprintPure, Category = Attributes, meta = (CompactNodeTitle = "!="))
static FORCEINLINE bool IsNot(const FInt32Attr& A, const FInt32Attr& B) { return A != B; }
/** @return true if two attributes have the same base value */
UFUNCTION(BlueprintPure, Category = Attributes)
static FORCEINLINE bool Equals(const FInt32Attr& A, const FInt32Attr& B)
{
return A.GetBaseValue() == B.GetBaseValue();
}
/**
* Get the final value of an attribute
* @param Attribute to get value from
* @return the final value
*/
UFUNCTION(BlueprintPure, Category = Attributes, meta = (Keywords = "get value int total final"))
static FORCEINLINE int32 GetValue(const FInt32Attr& Attribute) { return Attribute.GetValue(); }
// Get final value
UFUNCTION(BlueprintPure, Category = Attributes, meta = (DisplayName = "ToInt (Int32Attr)", CompactNodeTitle = "->", Keywords = "get value int", BlueprintAutocast))
static FORCEINLINE int32 Conv_AttributeToInt(const FInt32Attr& Attribute) { return GetValue(Attribute); }
// Get final value as int64
UFUNCTION(BlueprintPure, Category = Attributes, meta = (DisplayName = "ToInt64 (Int32Attr)", CompactNodeTitle = "->", Keywords = "get value int64", BlueprintAutocast))
static FORCEINLINE int64 Conv_AttributeToInt64(const FInt32Attr& Attribute) { return GetValue(Attribute); }
// Get final value as String
UFUNCTION(BlueprintPure, Category = Attributes, meta = (DisplayName = "ToString (Int32Attr)", CompactNodeTitle = "->", BlueprintAutocast))
static FORCEINLINE FString Conv_AttributeToString(const FInt32Attr& Attribute) {
return FString::SanitizeFloat(GetValue(Attribute));
}
/**
* Get the base value of an attribute
* @param Attribute to get base value from
* @return the base value
*/
UFUNCTION(BlueprintPure, Category = Attributes)
static FORCEINLINE int GetBase(const FInt32Attr& Attribute) { return Attribute.GetBaseValue(); }
/**
* Set the base value of an attribute
* @param Attribute to set base value at
* @param Value to set as the base value
*/
UFUNCTION(BlueprintCallable, Category = Attributes)
static void SetBase(UPARAM(ref) FInt32Attr & Attribute, int32 Value) { Attribute.SetBaseValue(Value); }
/**
* Adds a modifier to an attribute
* @param Attribute to be modified
* @param Modifier to apply to the attribute
* @param Category of the modifier (Optional)
*/
UFUNCTION(BlueprintCallable, Category = Attributes, meta = (AdvancedDisplay = "Category"))
static void AddModifier(UPARAM(ref) FInt32Attr& Attribute, const FAttrModifier& Modifier, const FAttrCategory Category)
{
Attribute.AddModifier(Modifier, Category);
}
/**
* Removes a modifier from an attribute
* @param Attribute to be modified
* @param Modifier to remove from the attribute
* @param Category of the modifier (Optional)
* @return true if any modifier was removed
*/
UFUNCTION(BlueprintCallable, Category = Attributes, meta=(AdvancedDisplay="Category,bRemoveFromAllCategories"))
static FORCEINLINE bool RemoveModifier(UPARAM(ref) FInt32Attr& Attribute, const FAttrModifier& Modifier, const FAttrCategory Category, bool bRemoveFromAllCategories = false)
{
return Attribute.RemoveModifier(Modifier, Category, bRemoveFromAllCategories);
}
/**
* Get all modifiers of a category, base mods will be returned if category is None
* @param Attribute to get modifiers from
* @return Modifiers of a category as an Array
*/
UFUNCTION(BlueprintPure, Category = Attributes, meta = (AdvancedDisplay = "Category"))
static void GetModifiers(const FInt32Attr& Attribute, const FAttrCategory Category, TArray<FAttrModifier>& Modifiers)
{
Modifiers = Attribute.GetModifiers(Category);
}
/**
* Get all categories where the attribute has any modifiers
* @param Attribute to get categories from
* @return Categories of an attribute as an Array
*/
UFUNCTION(BlueprintPure, Category = Attributes)
static void GetModifiedCategories(const FInt32Attr& Attribute, TArray<FAttrCategory>& Categories)
{
Attribute.GetModifiedCategories(Categories);
}
/**
* Remove all modifiers of an attribute
* @param Attribute to clean
*/
UFUNCTION(BlueprintCallable, Category = Attributes)
static void CleanModifiers(UPARAM(ref) FInt32Attr& Attribute)
{
return Attribute.CleanModifiers();
}
UFUNCTION(BlueprintCallable, Category = Attributes, meta = (AdvancedDisplay = "Category"))
static void CleanCategoryModifiers(UPARAM(ref) FInt32Attr& Attribute, const FAttrCategory Category)
{
Attribute.CleanCategoryModifiers(Category);
}
UFUNCTION(BlueprintCallable, Category = Attributes, meta = (AdvancedDisplay = "Category"))
static void BindOnModified(UPARAM(ref) FInt32Attr& Attribute, const FInt32ModifiedDelegate& Event)
{
Attribute.GetOnModified().AddUnique(Event);
}
UFUNCTION(BlueprintCallable, Category = Attributes, meta = (AdvancedDisplay = "Category"))
static void UnbindOnModified(UPARAM(ref) FInt32Attr& Attribute, const FInt32ModifiedDelegate& Event)
{
Attribute.GetOnModified().Remove(Event);
}
protected:
UFUNCTION(BlueprintPure, Category = Attributes)
static void Make(int32 BaseValue, FInt32Attr& IntAttr) { IntAttr = { BaseValue }; }
UFUNCTION(BlueprintPure, Category = Attributes)
static void Break(const FInt32Attr& IntAttr, int32& BaseValue, int32& Value) {
BaseValue = IntAttr.GetBaseValue();
Value = IntAttr.GetValue();
}
};