Esempio n. 1
0
XAttr *XNode::GetChildAttr( const char* name, const char* attrname )
{
	XNode *node = GetChild(name);
	return node ? node->GetAttr(attrname) : NULL;
}
Esempio n. 2
0
Actor *ActorUtil::LoadFromNode( const XNode* _pNode, Actor *pParentActor )
{
	ASSERT( _pNode != NULL );

	XNode node = *_pNode;

	// Remove this in favor of using conditionals in Lua. -Chris
	// There are a number of themes out there that depend on this (including
	// sm-ssc default). Probably for the best to leave this in. -aj
	{
		bool bCond;
		if( node.GetAttrValue("Condition", bCond) && !bCond )
			return NULL;
	}

	RString sClass;
	bool bHasClass = node.GetAttrValue( "Class", sClass );
	if( !bHasClass )
		bHasClass = node.GetAttrValue( "Type", sClass );

	bool bLegacy = (node.GetAttr( "_LegacyXml" ) != NULL);
	if( !bHasClass && bLegacy )
		sClass = GetLegacyActorClass( &node );

	map<RString,CreateActorFn>::iterator iter = g_pmapRegistrees->find( sClass );
	if( iter == g_pmapRegistrees->end() )
	{
		RString sFile;
		if (bLegacy && node.GetAttrValue("File", sFile) && sFile != "")
		{
			RString sPath;
			// Handle absolute paths correctly
			if (sFile.Left(1) == "/")
				sPath = sFile;
			else
				sPath = Dirname(GetSourcePath(&node)) + sFile;
			if (ResolvePath(sPath, GetWhere(&node)))
			{
				Actor *pNewActor = MakeActor(sPath, pParentActor);
				if (pNewActor == NULL)
					return NULL;
				if (pParentActor)
					pNewActor->SetParent(pParentActor);
				pNewActor->LoadFromNode(&node);
				return pNewActor;
			}
		}

		// sClass is invalid
		RString sError = ssprintf( "%s: invalid Class \"%s\"",
			ActorUtil::GetWhere(&node).c_str(), sClass.c_str() );
		LuaHelpers::ReportScriptError(sError);
		return new Actor;	// Return a dummy object so that we don't crash in AutoActor later.
	}

	const CreateActorFn &pfn = iter->second;
	Actor *pRet = pfn();

	if( pParentActor )
		pRet->SetParent( pParentActor );

	pRet->LoadFromNode( &node );
	return pRet;
}