Skip to content
This repository has been archived by the owner on May 3, 2019. It is now read-only.

Commit

Permalink
Merge pull request #19 from AaronShea/feature/jsonObj
Browse files Browse the repository at this point in the history
merge feature/json obj
  • Loading branch information
ashea-code committed Feb 27, 2015
2 parents e35078a + 4ddba67 commit d9b59ba
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 3 deletions.
4 changes: 3 additions & 1 deletion Source/Blu.Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ public Blu(TargetInfo Target)
"RHI",
"Slate",
"SlateCore",
"UMG"
"UMG",
"Json",
"JsonUtilities"
// ... add other public dependencies that you statically link with here ...
});

Expand Down
11 changes: 11 additions & 0 deletions Source/Blu/Private/BluBluprintFunctionLibrary.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "BluPrivatePCH.h"
#include "BluManager.h"
#include "Json.h"

UBluBlueprintFunctionLibrary::UBluBlueprintFunctionLibrary(const class FObjectInitializer& PCIP)
: Super(PCIP)
Expand All @@ -20,4 +21,14 @@ UBluEye* UBluBlueprintFunctionLibrary::NewBluEye(UObject* WorldContextObject)
void UBluBlueprintFunctionLibrary::RunBluEventLoop()
{
BluManager::doBluMessageLoop();
}

UBluJsonObj* UBluBlueprintFunctionLibrary::ParseJSON(const FString& JSONString)
{

UBluJsonObj* tempObj = NewObject<UBluJsonObj>(GetTransientPackage(), UBluJsonObj::StaticClass());
tempObj->init(JSONString);

return tempObj;

}
81 changes: 81 additions & 0 deletions Source/Blu/Private/BluJsonObj.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#include "BluPrivatePCH.h"
#include "Json.h"

UBluJsonObj::UBluJsonObj(const class FObjectInitializer& PCIP)
: Super(PCIP)
{

}

void UBluJsonObj::init(const FString &StringData)
{

StrData = *StringData;

TSharedRef<TJsonReader<TCHAR>> JsonReader = TJsonReaderFactory<TCHAR>::Create(StringData);
doParseJson(JsonReader);

}

FString UBluJsonObj::getStringValue(const FString &index)
{

return JsonParsed->GetStringField(index);

}

bool UBluJsonObj::getBooleanValue(const FString &index)
{

return JsonParsed->GetBoolField(index);

}

float UBluJsonObj::getNumValue(const FString &index)
{

return JsonParsed->GetNumberField(index);

}

UBluJsonObj* UBluJsonObj::getNestedObject(const FString &index)
{

TSharedPtr<FJsonObject> newJson = JsonParsed->GetObjectField(index);

if (!newJson.IsValid())
{
return NULL;
}

// Make our new temp obj
UBluJsonObj* tempObj = NewObject<UBluJsonObj>(GetTransientPackage(), UBluJsonObj::StaticClass());
tempObj->setJsonObj(newJson);

// return it
return tempObj;

}

void UBluJsonObj::setJsonObj(TSharedPtr<FJsonObject> NewJson)
{

// Set our new stored JSON object
JsonParsed = NewJson;

}

void UBluJsonObj::doParseJson(TSharedRef<TJsonReader<TCHAR>> JsonReader)
{

if (!FJsonSerializer::Deserialize(JsonReader, JsonParsed))
{
UE_LOG(LogBlu, Warning, TEXT("JSON STRING FAILED TO PARSE! WILL DEFAULT TO EMPTY OBJECT {}"));

// Make an empty json object to prevent crashing
doParseJson(TJsonReaderFactory<TCHAR>::Create("{}"));
}

}


1 change: 1 addition & 0 deletions Source/Blu/Private/BluPrivatePCH.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ DECLARE_LOG_CATEGORY_EXTERN(LogBlu, Log, All);
#include "BluManager.h"
#include "BluEye.h"
#include "RenderHandler.h"
#include "BluJsonObj.h"
#include "BluBlueprintFunctionLibrary.h"
6 changes: 4 additions & 2 deletions Source/Blu/Public/BluBlueprintFunctionLibrary.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#pragma once

#include "../Public/BluEye.h"
#include "BluBlueprintFunctionLibrary.generated.h"

UCLASS(ClassGroup = Blu, Blueprintable)
Expand All @@ -12,7 +11,10 @@ class BLU_API UBluBlueprintFunctionLibrary : public UBlueprintFunctionLibrary
UFUNCTION(BlueprintPure, meta = (HidePin = "WorldContextObject", DefaultToSelf = "WorldContextObject", FriendlyName = "Create BluEye", CompactNodeTitle = "BluEye", Keywords = "new create blu eye blui"), Category = Blu)
static UBluEye* NewBluEye(UObject* WorldContextObject);

UFUNCTION(BlueprintCallable, meta = (FriendlyName = "Run BLUI Tick", Keywords = "new create blu eye blui tick"), Category = Blu)
UFUNCTION(BlueprintCallable, meta = (FriendlyName = "Run BLUI Tick", Keywords = "blui blu eye blui tick"), Category = Blu)
static void RunBluEventLoop();

UFUNCTION(BlueprintCallable, meta = (FriendlyName = "Parse JSON String", Keywords = "blui blu eye json parse"), Category = Blu)
static UBluJsonObj* ParseJSON(const FString& JSONString);

};
36 changes: 36 additions & 0 deletions Source/Blu/Public/BluJsonObj.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#pragma once

#include "BluJsonObj.generated.h"

UCLASS(ClassGroup = Blu, Blueprintable)
class BLU_API UBluJsonObj : public UObject
{

GENERATED_UCLASS_BODY()

public:

UFUNCTION(BlueprintCallable, Category = "Blu")
FString getStringValue(const FString &index);

UFUNCTION(BlueprintCallable, Category = "Blu")
float getNumValue(const FString &index);

UFUNCTION(BlueprintCallable, Category = "Blu")
bool getBooleanValue(const FString &index);

UFUNCTION(BlueprintCallable, Category = "Blu")
UBluJsonObj* getNestedObject(const FString &index);

void init(const FString &dataString);
void setJsonObj(TSharedPtr<FJsonObject> NewJson);

private:

FString StrData;
TSharedPtr<FJsonObject> JsonParsed;

void doParseJson(TSharedRef<TJsonReader<TCHAR>> JsonReader);


};

0 comments on commit d9b59ba

Please sign in to comment.