Documentation for the Unreal C++ Plugin
Loading...
Searching...
No Matches
ApexLibrary.h
Go to the documentation of this file.
1// Copyright 2022 PixoVR Corp. All Rights Reserved.
2
3#pragma once
4
5#include "CoreMinimal.h"
6#include "Kismet/BlueprintFunctionLibrary.h"
7#include "VaRestJsonValue.h"
8#include "Dom/JsonValue.h"
9#include "ApexJSON.h"
10#include "XAPIExtension.h"
11#include "VaRestSubsystem.h"
12#include "ApexLibrary.generated.h"
13
17UCLASS()
18class APEXSDK_API UApexLibrary : public UBlueprintFunctionLibrary
19{
20 GENERATED_BODY()
21
22public: // Data related type functions
23
24 UFUNCTION(BlueprintCallable, Category = "Apex|API")
25 static FXAPIExtension CreateExtensionData(const TMap<FString, UVaRestJsonValue*>& Data);
26
27 UFUNCTION(BlueprintCallable, Category = "Apex|API")
28 static UVaRestJsonValue* JsonValueFromString(FString String);
29
30public:
31
32 static TArray<TSharedPtr<FJsonValue>> ConvertToJsonValueStringArray(const TArray<FString>& Array)
33 {
34 TArray<TSharedPtr<FJsonValue>> ConvertedArray;
35 for (const FString& Item : Array)
36 {
37 TSharedPtr<FJsonValueString> ItemPtr(new FJsonValueString(Item));
38 ConvertedArray.Add(ItemPtr);
39 }
41 return ConvertedArray;
42 }
43
44 static TArray<TSharedPtr<FJsonValue>> ConvertToJsonValueObjectArray(const TArray<FJsonable>& Array)
45 {
46 TArray<TSharedPtr<FJsonValue>> ConvertedArray;
47 for (const FJsonable& Item : Array)
48 {
49 TSharedPtr<FJsonValueObject> ItemPtr(new FJsonValueObject(Item.ToJsonObject()));
50 ConvertedArray.Add(ItemPtr);
51 }
53 return ConvertedArray;
54 }
55
56 static bool TryFillFromStringField(const TSharedPtr<FJsonObject>& JObject, const FString Field, FString& ValueToFill)
57 {
58 if (JObject->HasField(Field))
59 {
60 ValueToFill = JObject->GetStringField(Field);
61 return true;
62 }
63
64 return false;
65 }
66
67 static bool TryFillFromBoolField(const TSharedPtr<FJsonObject>& JObject, const FString Field, bool& ValueToFill)
68 {
69 if (JObject->HasField(Field))
70 {
71 ValueToFill = JObject->GetBoolField(Field);
72 return true;
73 }
74
75 return false;
76 }
77
78 static bool TryFillFromNumberField(const TSharedPtr<FJsonObject>& JObject, const FString Field, float& ValueToFill)
79 {
80 if (JObject->HasField(Field))
81 {
82 ValueToFill = JObject->GetNumberField(Field);
83 return true;
84 }
85
86 return false;
87 }
88
89 static bool TryFillFromIntegerField(const TSharedPtr<FJsonObject>& JObject, const FString Field, int& ValueToFill)
90 {
91 if (JObject->HasField(Field))
92 {
93 ValueToFill = JObject->GetIntegerField(Field);
94 return true;
95 }
96
97 return false;
98 }
99
100 static bool TryFillFromObjectField(const TSharedPtr<FJsonObject>& JObject, const FString Field, FJsonable& ValueToFill)
101 {
102 if (JObject->HasField(Field))
103 {
104 ValueToFill.FromJsonObject(JObject->GetObjectField(Field));
105 return true;
106 }
107
108 return false;
109 }
110
111 static bool TryFillFromObjectArrayField(const TSharedPtr<FJsonObject>& JObject, const FString Field, TArray<FJsonable>& ArrayToFill)
112 {
113 if (JObject->HasField(Field))
114 {
115 TArray<TSharedPtr<FJsonValue>> Array = JObject->GetArrayField(Field);
116 FJsonable Jsonable;
117 for (TSharedPtr<FJsonValue> Value : Array)
118 {
119 Jsonable.FromJsonObject(Value->AsObject());
120 ArrayToFill.Add(Jsonable);
121 }
122 return true;
123 }
124
125 return false;
126 }
127
128 static bool TryFillFromStringArrayField(const TSharedPtr<FJsonObject>& JObject, const FString Field, TArray<FString>& ArrayToFill)
129 {
130 if (JObject->HasField(Field))
131 {
132 TArray<TSharedPtr<FJsonValue>> Array = JObject->GetArrayField(Field);
133 for (TSharedPtr<FJsonValue> Value : Array)
134 {
135 ArrayToFill.Add(Value->AsString());
137 return true;
138 }
139
140 return false;
141 }
142
143 static bool TryFillFromNumberArrayField(const TSharedPtr<FJsonObject>& JObject, const FString Field, TArray<float>& ArrayToFill)
144 {
145 if (JObject->HasField(Field))
146 {
147 TArray<TSharedPtr<FJsonValue>> Array = JObject->GetArrayField(Field);
148 for (TSharedPtr<FJsonValue> Value : Array)
149 {
150 ArrayToFill.Add(Value->AsNumber());
152 return true;
153 }
154
155 return false;
156 }
157
158 static bool TryFillFromIntegerArrayField(const TSharedPtr<FJsonObject>& JObject, const FString Field, TArray<int>& ArrayToFill)
159 {
160 if (JObject->HasField(Field))
161 {
162 TArray<TSharedPtr<FJsonValue>> Array = JObject->GetArrayField(Field);
163 for (TSharedPtr<FJsonValue> Value : Array)
164 {
165 ArrayToFill.Add(Value->AsNumber());
167 return true;
168 }
169
170 return false;
171 }
172
173 static bool TryFillFromBoolArrayField(const TSharedPtr<FJsonObject>& JObject, const FString Field, TArray<bool>& ArrayToFill)
174 {
175 if (JObject->HasField(Field))
176 {
177 TArray<TSharedPtr<FJsonValue>> Array = JObject->GetArrayField(Field);
178 for (TSharedPtr<FJsonValue> Value : Array)
179 {
180 ArrayToFill.Add(Value->AsBool());
182 return true;
183 }
184
185 return false;
186 }
187
188 static UVaRestSubsystem* GetRestSubsystem()
189 {
190 static UVaRestSubsystem* VaRestSubsystem = GEngine->GetEngineSubsystem<UVaRestSubsystem>();
191 return VaRestSubsystem;
192 }
193
194 static FString GetApexSDKVersion();
195};
UCLASS()
Definition ApexLibrary.h:21
static bool TryFillFromObjectArrayField(const TSharedPtr< FJsonObject > &JObject, const FString Field, TArray< FJsonable > &ArrayToFill)
static TArray< TSharedPtr< FJsonValue > > ConvertToJsonValueObjectArray(const TArray< FJsonable > &Array)
Definition ApexLibrary.h:52
static bool TryFillFromIntegerArrayField(const TSharedPtr< FJsonObject > &JObject, const FString Field, TArray< int > &ArrayToFill)
static bool TryFillFromNumberArrayField(const TSharedPtr< FJsonObject > &JObject, const FString Field, TArray< float > &ArrayToFill)
static bool TryFillFromIntegerField(const TSharedPtr< FJsonObject > &JObject, const FString Field, int &ValueToFill)
Definition ApexLibrary.h:97
static bool TryFillFromObjectField(const TSharedPtr< FJsonObject > &JObject, const FString Field, FJsonable &ValueToFill)
static TArray< TSharedPtr< FJsonValue > > ConvertToJsonValueStringArray(const TArray< FString > &Array)
Definition ApexLibrary.h:40
static bool TryFillFromBoolField(const TSharedPtr< FJsonObject > &JObject, const FString Field, bool &ValueToFill)
Definition ApexLibrary.h:75
static bool TryFillFromNumberField(const TSharedPtr< FJsonObject > &JObject, const FString Field, float &ValueToFill)
Definition ApexLibrary.h:86
static bool TryFillFromStringField(const TSharedPtr< FJsonObject > &JObject, const FString Field, FString &ValueToFill)
Definition ApexLibrary.h:64
static bool TryFillFromBoolArrayField(const TSharedPtr< FJsonObject > &JObject, const FString Field, TArray< bool > &ArrayToFill)
static UVaRestSubsystem * GetRestSubsystem()
static bool TryFillFromStringArrayField(const TSharedPtr< FJsonObject > &JObject, const FString Field, TArray< FString > &ArrayToFill)
USTRUCT()
Definition ApexJSON.h:13
virtual void FromJsonObject(const TSharedPtr< FJsonObject > &JObject)
Definition ApexJSON.h:18
USTRUCT(BlueprintType)