|
@@ -247,6 +247,34 @@ SimObject* TamlXmlReader::parseElement( TiXmlElement* pXmlElement )
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
+void TamlXmlReader::parseAttributes( TiXmlElement* pXmlElement, SimObject* pSimObject )
|
|
|
+{
|
|
|
+ // Debug Profiling.
|
|
|
+ PROFILE_SCOPE(TamlXmlReader_ParseAttributes);
|
|
|
+
|
|
|
+ // Sanity!
|
|
|
+ AssertFatal( pSimObject != NULL, "Taml: Cannot parse attributes on a NULL object." );
|
|
|
+
|
|
|
+ // Iterate attributes.
|
|
|
+ for ( TiXmlAttribute* pAttribute = pXmlElement->FirstAttribute(); pAttribute; pAttribute = pAttribute->Next() )
|
|
|
+ {
|
|
|
+ // Insert attribute name.
|
|
|
+ StringTableEntry attributeName = StringTable->insert( pAttribute->Name() );
|
|
|
+
|
|
|
+ // Ignore if this is a Taml attribute.
|
|
|
+ if ( attributeName == mTamlRefId ||
|
|
|
+ attributeName == mTamlRefToId ||
|
|
|
+ attributeName == mTamlObjectName ||
|
|
|
+ attributeName == mTamlRefField )
|
|
|
+ continue;
|
|
|
+
|
|
|
+ // We can assume this is a field for now.
|
|
|
+ pSimObject->setPrefixedDataField( attributeName, NULL, pAttribute->Value() );
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+//-----------------------------------------------------------------------------
|
|
|
+
|
|
|
void TamlXmlReader::parseCustomElement( TiXmlElement* pXmlElement, TamlCustomNodes& customNodes )
|
|
|
{
|
|
|
// Debug Profiling.
|
|
@@ -258,91 +286,77 @@ void TamlXmlReader::parseCustomElement( TiXmlElement* pXmlElement, TamlCustomNod
|
|
|
// Sanity!
|
|
|
AssertFatal( pPeriod != NULL, "Parsing extended element but no period character found." );
|
|
|
|
|
|
- // Fetch any property alias.
|
|
|
- TiXmlNode* pPropertyAliasXmlNode = pXmlElement->FirstChild();
|
|
|
+ // Fetch any custom XML node.
|
|
|
+ TiXmlNode* pCustomXmlNode = pXmlElement->FirstChild();
|
|
|
+
|
|
|
+ // Finish is no XML node exists.
|
|
|
+ if ( pCustomXmlNode == NULL )
|
|
|
+ return;
|
|
|
|
|
|
- // Do we have any property alias?
|
|
|
- if ( pPropertyAliasXmlNode != NULL )
|
|
|
+ // Yes, so add custom node.
|
|
|
+ TamlCustomNode* pCustomNode = customNodes.addNode( pPeriod+1 );
|
|
|
+
|
|
|
+ do
|
|
|
{
|
|
|
- // Yes, so add custom property.
|
|
|
- TamlCustomProperty* pCustomProperty = customProperties.addProperty( pPeriod+1 );
|
|
|
+ // Fetch element.
|
|
|
+ TiXmlElement* pCustomXmlElement = dynamic_cast<TiXmlElement*>( pCustomXmlNode );
|
|
|
|
|
|
- do
|
|
|
- {
|
|
|
- // Fetch element.
|
|
|
- TiXmlElement* pPropertyAliasXmlElement = dynamic_cast<TiXmlElement*>( pPropertyAliasXmlNode );
|
|
|
+ // Move to next sibling.
|
|
|
+ pCustomXmlNode = pCustomXmlNode->NextSibling();
|
|
|
|
|
|
- // Move to next sibling.
|
|
|
- pPropertyAliasXmlNode = pPropertyAliasXmlNode->NextSibling();
|
|
|
+ // Skip if this is not an element.
|
|
|
+ if ( pCustomXmlElement == NULL )
|
|
|
+ continue;
|
|
|
|
|
|
- // Skip if this is not an element?
|
|
|
- if ( pPropertyAliasXmlElement == NULL )
|
|
|
- continue;
|
|
|
+ // Parse custom node.
|
|
|
+ parseCustomNode( pCustomXmlElement, pCustomNode );
|
|
|
|
|
|
- // Add property alias.
|
|
|
- TamlPropertyAlias* pPropertyAlias = pCustomProperty->addAlias( pPropertyAliasXmlElement->Value() );
|
|
|
+ }
|
|
|
+ while ( pCustomXmlNode != NULL );
|
|
|
+}
|
|
|
|
|
|
- // Iterate property field attributes.
|
|
|
- for ( TiXmlAttribute* pAttribute = pPropertyAliasXmlElement->FirstAttribute(); pAttribute; pAttribute = pAttribute->Next() )
|
|
|
- {
|
|
|
- // Insert attribute name.
|
|
|
- StringTableEntry attributeName = StringTable->insert( pAttribute->Name() );
|
|
|
+//-----------------------------------------------------------------------------
|
|
|
|
|
|
- // Add property field.
|
|
|
- pPropertyAlias->addField( attributeName, pAttribute->Value() );
|
|
|
- }
|
|
|
+void TamlXmlReader::parseCustomNode( TiXmlElement* pXmlElement, TamlCustomNode* pCustomNode )
|
|
|
+{
|
|
|
+ // Is the node a proxy object?
|
|
|
+ if ( getTamlRefId( pXmlElement ) != 0 || getTamlRefToId( pXmlElement ) != 0 )
|
|
|
+ {
|
|
|
+ // Yes, so parse proxy object.
|
|
|
+ SimObject* pProxyObject = parseElement( pXmlElement );
|
|
|
|
|
|
- // Fetch any children.
|
|
|
- TiXmlNode* pChildXmlNode = pPropertyAliasXmlElement->FirstChild();
|
|
|
+ // Add child node.
|
|
|
+ pCustomNode->addNode( pProxyObject );
|
|
|
|
|
|
- // Do we have any element children?
|
|
|
- if ( pChildXmlNode != NULL )
|
|
|
- {
|
|
|
- do
|
|
|
- {
|
|
|
- // Fetch element.
|
|
|
- TiXmlElement* pChildXmlElement = dynamic_cast<TiXmlElement*>( pChildXmlNode );
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- // Move to next sibling.
|
|
|
- pChildXmlNode = pChildXmlNode->NextSibling();
|
|
|
+ // Add child node.
|
|
|
+ TamlCustomNode* pChildNode = pCustomNode->addNode( pXmlElement->Value() );
|
|
|
|
|
|
- // Skip if this is not an element?
|
|
|
- if ( pChildXmlElement == NULL )
|
|
|
- continue;
|
|
|
+ // Fetch any children.
|
|
|
+ TiXmlNode* pChildXmlNode = pXmlElement->FirstChild();
|
|
|
|
|
|
- // Fetch the reference field.
|
|
|
- const char* pRefField = getTamlRefField( pChildXmlElement );
|
|
|
+ // Do we have any element children?
|
|
|
+ if ( pChildXmlNode != NULL )
|
|
|
+ {
|
|
|
+ do
|
|
|
+ {
|
|
|
+ // Yes, so fetch child element.
|
|
|
+ TiXmlElement* pChildXmlElement = dynamic_cast<TiXmlElement*>( pChildXmlNode );
|
|
|
|
|
|
- // Was a reference field found?
|
|
|
- if ( pRefField == NULL )
|
|
|
- {
|
|
|
- // No, so warn.
|
|
|
- Con::warnf( "Taml: Encountered a child element in a custom element but it did not have a field reference using '%s'.", mTamlRefField );
|
|
|
- continue;
|
|
|
- }
|
|
|
+ // Move to next sibling.
|
|
|
+ pChildXmlNode = pChildXmlNode->NextSibling();
|
|
|
|
|
|
- // Parse the child element.
|
|
|
- SimObject* pFieldObject = parseElement( pChildXmlElement );
|
|
|
+ // Skip if this is not an element.
|
|
|
+ if ( pChildXmlElement == NULL )
|
|
|
+ continue;
|
|
|
|
|
|
- // Add property field.
|
|
|
- pPropertyAlias->addField( pRefField, pFieldObject );
|
|
|
- }
|
|
|
- while( pChildXmlNode != NULL );
|
|
|
- }
|
|
|
+ // Parse custom node.
|
|
|
+ parseCustomNode( pChildXmlElement, pChildNode );
|
|
|
}
|
|
|
- while ( pPropertyAliasXmlNode != NULL );
|
|
|
+ while( pChildXmlNode != NULL );
|
|
|
}
|
|
|
-}
|
|
|
-
|
|
|
-//-----------------------------------------------------------------------------
|
|
|
-
|
|
|
-void TamlXmlReader::parseAttributes( TiXmlElement* pXmlElement, SimObject* pSimObject )
|
|
|
-{
|
|
|
- // Debug Profiling.
|
|
|
- PROFILE_SCOPE(TamlXmlReader_ParseAttributes);
|
|
|
-
|
|
|
- // Sanity!
|
|
|
- AssertFatal( pSimObject != NULL, "Taml: Cannot parse attributes on a NULL object." );
|
|
|
|
|
|
// Iterate attributes.
|
|
|
for ( TiXmlAttribute* pAttribute = pXmlElement->FirstAttribute(); pAttribute; pAttribute = pAttribute->Next() )
|
|
@@ -350,15 +364,12 @@ void TamlXmlReader::parseAttributes( TiXmlElement* pXmlElement, SimObject* pSimO
|
|
|
// Insert attribute name.
|
|
|
StringTableEntry attributeName = StringTable->insert( pAttribute->Name() );
|
|
|
|
|
|
- // Ignore if this is a Taml attribute.
|
|
|
- if ( attributeName == mTamlRefId ||
|
|
|
- attributeName == mTamlRefToId ||
|
|
|
- attributeName == mTamlObjectName ||
|
|
|
- attributeName == mTamlRefField )
|
|
|
- continue;
|
|
|
+ // Skip if a Taml reference attribute.
|
|
|
+ if ( attributeName == mTamlRefId || attributeName == mTamlRefToId )
|
|
|
+ continue;
|
|
|
|
|
|
- // We can assume this is a field for now.
|
|
|
- pSimObject->setPrefixedDataField( attributeName, NULL, pAttribute->Value() );
|
|
|
+ // Add node field.
|
|
|
+ pChildNode->addField( attributeName, pAttribute->Value() );
|
|
|
}
|
|
|
}
|
|
|
|