Add layers and tags updating

This commit is contained in:
Wojtek Figat
2021-02-22 11:22:44 +01:00
parent 6683cb299e
commit f3216a9c96
3 changed files with 23 additions and 20 deletions

View File

@@ -204,33 +204,23 @@ void GameSettings::Deserialize(DeserializeStream& stream, ISerializeModifier* mo
void LayersAndTagsSettings::Deserialize(DeserializeStream& stream, ISerializeModifier* modifier)
{
const auto tags = stream.FindMember("Tags");
if (tags != stream.MemberEnd())
if (tags != stream.MemberEnd() && tags->value.IsArray())
{
auto& tagsArray = tags->value;
ASSERT(tagsArray.IsArray());
Tags.Clear();
Tags.EnsureCapacity(tagsArray.Size());
// Note: we cannot remove tags at runtime so this should deserialize them in additive mode
// Tags are stored as tagIndex in actors so collection change would break the linkage
for (uint32 i = 0; i < tagsArray.Size(); i++)
{
auto& v = tagsArray[i];
if (v.IsString())
{
const String tag = v.GetText();
if (!Tags.Contains(tag))
Tags.Add(tag);
}
Tags.Add(v.GetText());
}
}
const auto layers = stream.FindMember("Layers");
if (layers != stream.MemberEnd())
if (layers != stream.MemberEnd() && layers->value.IsArray())
{
auto& layersArray = layers->value;
ASSERT(layersArray.IsArray());
for (uint32 i = 0; i < layersArray.Size() && i < 32; i++)
{
auto& v = layersArray[i];
@@ -239,5 +229,9 @@ void LayersAndTagsSettings::Deserialize(DeserializeStream& stream, ISerializeMod
else
Layers[i].Clear();
}
for (uint32 i = layersArray.Size(); i < 32; i++)
{
Layers[i].Clear();
}
}
}

View File

@@ -30,5 +30,6 @@ public:
static LayersAndTagsSettings* Get();
// [SettingsBase]
void Apply() override;
void Deserialize(DeserializeStream& stream, ISerializeModifier* modifier) final override;
};