Allow other root XML than entity
.
Implements a `GetOnlyChild()`, following discussion at https://irclogs.wildfiregames.com/%230ad-dev/2022-05-06-QuakeNet-%230ad-dev.log. Differential revision: https://code.wildfiregames.com/D4738 Comments by: @phosit, @Stan, @vladislavbelov, @wraitii This was SVN commit r27323.
This commit is contained in:
parent
5044850f93
commit
ded41eab31
@ -248,7 +248,7 @@ void CMapGeneratorWorker::SetProgress(int progress)
|
||||
|
||||
CParamNode CMapGeneratorWorker::GetTemplate(const std::string& templateName)
|
||||
{
|
||||
const CParamNode& templateRoot = m_TemplateLoader.GetTemplateFileData(templateName).GetChild("Entity");
|
||||
const CParamNode& templateRoot = m_TemplateLoader.GetTemplateFileData(templateName).GetOnlyChild();
|
||||
if (!templateRoot.IsOk())
|
||||
LOGERROR("Invalid template found for '%s'", templateName.c_str());
|
||||
|
||||
|
@ -415,7 +415,7 @@ bool CGUIManager::TemplateExists(const std::string& templateName) const
|
||||
|
||||
const CParamNode& CGUIManager::GetTemplate(const std::string& templateName)
|
||||
{
|
||||
const CParamNode& templateRoot = m_TemplateLoader.GetTemplateFileData(templateName).GetChild("Entity");
|
||||
const CParamNode& templateRoot = m_TemplateLoader.GetTemplateFileData(templateName).GetOnlyChild();
|
||||
if (!templateRoot.IsOk())
|
||||
LOGERROR("Invalid template found for '%s'", templateName.c_str());
|
||||
|
||||
|
@ -787,7 +787,7 @@ CParamNode GetTemplate(const std::string& templateName)
|
||||
// This is very cheap to create so let's just do it every time.
|
||||
CTemplateLoader templateLoader;
|
||||
|
||||
const CParamNode& templateRoot = templateLoader.GetTemplateFileData(templateName).GetChild("Entity");
|
||||
const CParamNode& templateRoot = templateLoader.GetTemplateFileData(templateName).GetOnlyChild();
|
||||
if (!templateRoot.IsOk())
|
||||
LOGERROR("Invalid template found for '%s'", templateName.c_str());
|
||||
|
||||
|
@ -354,7 +354,7 @@ public:
|
||||
{
|
||||
if (!m_TemplateLoader.TemplateExists(name))
|
||||
return CParamNode(false);
|
||||
return m_TemplateLoader.GetTemplateFileData(name).GetChild("Entity");
|
||||
return m_TemplateLoader.GetTemplateFileData(name).GetOnlyChild();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -170,7 +170,7 @@ const CParamNode* CCmpTemplateManager::GetTemplate(const std::string& templateNa
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const CParamNode& templateRoot = fileData.GetChild("Entity");
|
||||
const CParamNode& templateRoot = fileData.GetOnlyChild();
|
||||
if (!templateRoot.IsOk())
|
||||
{
|
||||
// The validator should never let this happen
|
||||
@ -183,7 +183,7 @@ const CParamNode* CCmpTemplateManager::GetTemplate(const std::string& templateNa
|
||||
|
||||
const CParamNode* CCmpTemplateManager::GetTemplateWithoutValidation(const std::string& templateName)
|
||||
{
|
||||
const CParamNode& templateRoot = m_templateLoader.GetTemplateFileData(templateName).GetChild("Entity");
|
||||
const CParamNode& templateRoot = m_templateLoader.GetTemplateFileData(templateName).GetOnlyChild();
|
||||
if (!templateRoot.IsOk())
|
||||
return NULL;
|
||||
|
||||
|
@ -1148,7 +1148,8 @@ std::string CComponentManager::GenerateSchema() const
|
||||
std::sort(componentTypes.begin(), componentTypes.end());
|
||||
schema +=
|
||||
"<start>"
|
||||
"<element name='Entity'>"
|
||||
"<element>"
|
||||
"<anyName/>"
|
||||
"<optional><attribute name='parent'/></optional>";
|
||||
for (std::vector<std::string>::const_iterator it = componentTypes.begin(); it != componentTypes.end(); ++it)
|
||||
schema += "<optional><ref name='component." + *it + "'/></optional>";
|
||||
|
@ -241,6 +241,15 @@ void CParamNode::ApplyLayer(const XMBData& xmb, const XMBElement& element, const
|
||||
}
|
||||
}
|
||||
|
||||
const CParamNode& CParamNode::GetOnlyChild() const
|
||||
{
|
||||
if (m_Childs.empty())
|
||||
return g_NullNode;
|
||||
|
||||
ENSURE(m_Childs.size() == 1);
|
||||
return m_Childs.begin()->second;
|
||||
}
|
||||
|
||||
const CParamNode& CParamNode::GetChild(const char* name) const
|
||||
{
|
||||
ChildrenMap::const_iterator it = m_Childs.find(name);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2021 Wildfire Games.
|
||||
/* Copyright (C) 2022 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -190,6 +190,12 @@ public:
|
||||
// (Children are returned as const in order to allow future optimisations, where we assume
|
||||
// a node is always modified explicitly and not indirectly via its children, e.g. to cache JS::Values)
|
||||
|
||||
/**
|
||||
* Returns the only child node, or a node with IsOk() == false if there is none.
|
||||
* This is mainly useful for the root node.
|
||||
*/
|
||||
const CParamNode& GetOnlyChild() const;
|
||||
|
||||
/**
|
||||
* Returns true if this is a valid CParamNode, false if it represents a non-existent node
|
||||
*/
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2021 Wildfire Games.
|
||||
/* Copyright (C) 2022 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -50,6 +50,7 @@ public:
|
||||
TS_ASSERT_EQUALS(node.GetChild("test").GetChild("Bar").GetChild("Baz").ToInt(), 3);
|
||||
TS_ASSERT(node.GetChild("test").GetChild("Qux").IsOk());
|
||||
TS_ASSERT(!node.GetChild("test").GetChild("Qux").GetChild("Baz").IsOk());
|
||||
TS_ASSERT_STR_EQUALS(node.GetChild("test").ToXMLString(), node.GetOnlyChild().ToXMLString());
|
||||
|
||||
CParamNode nullOne(false);
|
||||
CParamNode nullTwo = nullOne;
|
||||
|
Loading…
Reference in New Issue
Block a user