Add tag native serialization
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#include "Tags.h"
|
||||
#include "Engine/Core/Types/String.h"
|
||||
#include "Engine/Core/Types/StringView.h"
|
||||
#include "Engine/Serialization/SerializationFwd.h"
|
||||
|
||||
Array<String> Tags::List;
|
||||
#if !BUILD_RELEASE
|
||||
@@ -24,8 +25,23 @@ bool Tag::operator!=(const StringView& other) const
|
||||
return ToString() != other;
|
||||
}
|
||||
|
||||
void FLAXENGINE_API Serialization::Serialize(ISerializable::SerializeStream& stream, const Tag& v, const void* otherObj)
|
||||
{
|
||||
if (v.Index != -1)
|
||||
stream.String(v.ToString());
|
||||
else
|
||||
stream.String("", 0);
|
||||
}
|
||||
|
||||
void FLAXENGINE_API Serialization::Deserialize(ISerializable::DeserializeStream& stream, Tag& v, ISerializeModifier* modifier)
|
||||
{
|
||||
v = Tags::Get(stream.GetText());
|
||||
}
|
||||
|
||||
Tag Tags::Get(const StringView& tagName)
|
||||
{
|
||||
if (tagName.IsEmpty())
|
||||
return Tag();
|
||||
Tag tag = List.Find(tagName);
|
||||
if (tag.Index == -1 && tagName.HasChars())
|
||||
{
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#include "Engine/Core/Types/BaseTypes.h"
|
||||
#include "Engine/Core/Collections/Array.h"
|
||||
#include "Engine/Core/ISerializable.h"
|
||||
|
||||
/// <summary>
|
||||
/// Gameplay tag that represents a hierarchical name of the form 'X.Y.Z' (namespaces separated with a dot). Tags are defined in project LayersAndTagsSettings asset but can be also created from code.
|
||||
@@ -60,6 +61,18 @@ inline uint32 GetHash(const Tag& key)
|
||||
return (uint32)key.Index;
|
||||
}
|
||||
|
||||
// @formatter:off
|
||||
namespace Serialization
|
||||
{
|
||||
inline bool ShouldSerialize(const Tag& v, const void* otherObj)
|
||||
{
|
||||
return !otherObj || v != *(Tag*)otherObj;
|
||||
}
|
||||
void FLAXENGINE_API Serialize(ISerializable::SerializeStream& stream, const Tag& v, const void* otherObj);
|
||||
void FLAXENGINE_API Deserialize(ISerializable::DeserializeStream& stream, Tag& v, ISerializeModifier* modifier);
|
||||
}
|
||||
// @formatter:on
|
||||
|
||||
/// <summary>
|
||||
/// Gameplay tags utilities.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user