Working loading, Saving and default config functions
This commit is contained in:
parent
996dd0a232
commit
5c9a3256d6
6 changed files with 335 additions and 97 deletions
|
@ -53,6 +53,34 @@ public:
|
|||
|
||||
template <typename T>
|
||||
T GetValue() const;
|
||||
|
||||
// Equality operators
|
||||
bool operator==(const FHLConfigValue& Other) const
|
||||
{
|
||||
if (Type != Other.Type)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (Type)
|
||||
{
|
||||
case EConfigValueType::Int:
|
||||
return IntValue == Other.IntValue;
|
||||
case EConfigValueType::Float:
|
||||
return FloatValue == Other.FloatValue;
|
||||
case EConfigValueType::Bool:
|
||||
return BoolValue == Other.BoolValue;
|
||||
case EConfigValueType::String:
|
||||
return StringValue == Other.StringValue;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool operator!=(const FHLConfigValue& Other) const
|
||||
{
|
||||
return !(*this == Other);
|
||||
}
|
||||
};
|
||||
|
||||
// Specializations of the templated getter
|
||||
|
@ -83,3 +111,27 @@ inline FString FHLConfigValue::GetValue<FString>() const
|
|||
ensure(Type == EConfigValueType::String);
|
||||
return StringValue;
|
||||
}
|
||||
|
||||
// Hash function
|
||||
FORCEINLINE uint32 GetTypeHash(const FHLConfigValue& Value)
|
||||
{
|
||||
uint32 Hash = GetTypeHash(Value.GetType());
|
||||
|
||||
switch (Value.GetType())
|
||||
{
|
||||
case EConfigValueType::Int:
|
||||
Hash = HashCombine(Hash, GetTypeHash(Value.GetValue<int32>()));
|
||||
break;
|
||||
case EConfigValueType::Float:
|
||||
Hash = HashCombine(Hash, GetTypeHash(Value.GetValue<float>()));
|
||||
break;
|
||||
case EConfigValueType::Bool:
|
||||
Hash = HashCombine(Hash, GetTypeHash(Value.GetValue<bool>()));
|
||||
break;
|
||||
case EConfigValueType::String:
|
||||
Hash = HashCombine(Hash, GetTypeHash(Value.GetValue<FString>()));
|
||||
break;
|
||||
}
|
||||
|
||||
return Hash;
|
||||
}
|
||||
|
|
45
Source/HarmonyLink/Public/Structs/SettingsProfile.h
Normal file
45
Source/HarmonyLink/Public/Structs/SettingsProfile.h
Normal file
|
@ -0,0 +1,45 @@
|
|||
// Copyright (C) 2024 Jordon Brooks
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "HLConfigValue.h"
|
||||
|
||||
#include "SettingsProfile.generated.h"
|
||||
|
||||
USTRUCT(BlueprintType)
|
||||
struct FSettingsProfile
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
UPROPERTY()
|
||||
FName SectionName;
|
||||
|
||||
UPROPERTY()
|
||||
TMap<FName, FHLConfigValue> Settings;
|
||||
|
||||
// Equality operators
|
||||
bool operator==(const FSettingsProfile& Other) const
|
||||
{
|
||||
return SectionName == Other.SectionName && Settings.OrderIndependentCompareEqual(Other.Settings);
|
||||
}
|
||||
|
||||
bool operator!=(const FSettingsProfile& Other) const
|
||||
{
|
||||
return !(*this == Other);
|
||||
}
|
||||
};
|
||||
|
||||
// Hash function
|
||||
FORCEINLINE uint32 GetTypeHash(const FSettingsProfile& Profile)
|
||||
{
|
||||
uint32 Hash = GetTypeHash(Profile.SectionName);
|
||||
|
||||
for (const auto& Pair : Profile.Settings)
|
||||
{
|
||||
Hash = HashCombine(Hash, GetTypeHash(Pair.Key));
|
||||
Hash = HashCombine(Hash, GetTypeHash(Pair.Value));
|
||||
}
|
||||
|
||||
return Hash;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue