{lyn7065} adding ProcPrefab Prefab::Tempate flag method (#4765)

* {lyn7065} adding ProcPrefab Prefab::Tempate flag method

Signed-off-by: jackalbe <23512001+jackalbe@users.noreply.github.com>

* updated based on comments

Signed-off-by: jackalbe <23512001+jackalbe@users.noreply.github.com>

* moved validation logic to IsValid()

Signed-off-by: jackalbe <23512001+jackalbe@users.noreply.github.com>

* added more guards around the source string


Signed-off-by: jackalbe <23512001+jackalbe@users.noreply.github.com>
This commit is contained in:
Allen Jackson
2021-10-20 12:22:11 -05:00
committed by GitHub
parent c6afb1f0a3
commit 900aa4e5bc
3 changed files with 65 additions and 1 deletions
@@ -66,7 +66,16 @@ namespace AzToolsFramework
bool Template::IsValid() const
{
return !m_prefabDom.IsNull() && !m_filePath.empty();
if (m_prefabDom.IsNull() || m_filePath.empty())
{
return false;
}
else if (!m_prefabDom.IsObject())
{
return false;
}
auto source = m_prefabDom.FindMember(PrefabDomUtils::SourceName);
return (source != m_prefabDom.MemberEnd());
}
bool Template::IsLoadedWithErrors() const
@@ -175,6 +184,26 @@ namespace AzToolsFramework
return findInstancesResult->get();
}
bool Template::IsProcedural() const
{
if (m_isProcedural.has_value())
{
return m_isProcedural.value();
}
else if (!IsValid())
{
return false;
}
auto source = m_prefabDom.FindMember(PrefabDomUtils::SourceName);
if (!source->value.IsString())
{
return false;
}
AZ::IO::PathView path(source->value.GetString());
m_isProcedural = AZStd::make_optional(path.Extension().Match(".procprefab"));
return m_isProcedural.value();
}
const AZ::IO::Path& Template::GetFilePath() const
{
return m_filePath;
@@ -65,6 +65,9 @@ namespace AzToolsFramework
const AZ::IO::Path& GetFilePath() const;
void SetFilePath(const AZ::IO::PathView& path);
// To tell if this Template was created from an product asset
bool IsProcedural() const;
private:
// Container for keeping links representing the Template's nested instances.
Links m_links;
@@ -80,6 +83,9 @@ namespace AzToolsFramework
// Flag to tell if this Template has changes that have yet to be saved to file.
bool m_isDirty = false;
// Flag to tell if this Template was generated outside the Editor
mutable AZStd::optional<bool> m_isProcedural;
};
} // namespace Prefab
} // namespace AzToolsFramework