Mark the directory of actor definition XNodes in the nodes themselves.
Use ActorUtil::GetAttrPath to look up a path, with automatic handling of relative paths. This way, we don't need to do it in every place we look up paths. (For Lua nodes, this will be set by Lua.)
This commit is contained in:
@@ -316,6 +316,24 @@ static void MergeActorXML( XNode *pChild, const XNode *pParent )
|
||||
|
||||
namespace
|
||||
{
|
||||
void AnnotateXMLTree( XNode *pNode, const RString &sFile )
|
||||
{
|
||||
RString sDir = Dirname( sFile );
|
||||
|
||||
vector<XNode *> queue;
|
||||
queue.push_back( pNode );
|
||||
while( !queue.empty() )
|
||||
{
|
||||
pNode = queue.back();
|
||||
queue.pop_back();
|
||||
FOREACH_Child( pNode, pChild )
|
||||
queue.push_back( pChild );
|
||||
|
||||
pNode->AppendAttr( "_Dir", sDir );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
XNode *LoadXNodeFromLuaShowErrors( const RString &sFile )
|
||||
{
|
||||
RString sScript;
|
||||
@@ -401,6 +419,7 @@ Actor* ActorUtil::MakeActor( const RString &sPath_, const XNode *pParent, Actor
|
||||
}
|
||||
|
||||
XmlFileUtil::CompileXNodeTree( &xml, sPath );
|
||||
AnnotateXMLTree( &xml, sPath );
|
||||
MergeActorXML( &xml, pParent );
|
||||
return ActorUtil::LoadFromNode( sDir, &xml );
|
||||
}
|
||||
@@ -440,6 +459,26 @@ Actor* ActorUtil::MakeActor( const RString &sPath_, const XNode *pParent, Actor
|
||||
}
|
||||
}
|
||||
|
||||
bool ActorUtil::GetAttrPath( const XNode *pNode, const RString &sName, RString &sOut )
|
||||
{
|
||||
if( !pNode->GetAttrValue(sName, sOut) )
|
||||
return false;
|
||||
|
||||
bool bIsRelativePath = sOut.Left(1) != "/";
|
||||
if( bIsRelativePath )
|
||||
{
|
||||
RString sDir;
|
||||
if( !pNode->GetAttrValue("_Dir", sDir) )
|
||||
{
|
||||
LOG->Warn( "Relative path \"%s\", but path is unknown", sOut.c_str() );
|
||||
return false;
|
||||
}
|
||||
sOut = sDir+sOut;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
apActorCommands ActorUtil::ParseActorCommands( const RString &sCommands, const RString &sName )
|
||||
{
|
||||
Lua *L = LUA->Get();
|
||||
|
||||
@@ -71,6 +71,7 @@ namespace ActorUtil
|
||||
// Return a Sprite, BitmapText, or Model depending on the file type
|
||||
Actor* LoadFromNode( const RString& sAniDir, const XNode* pNode, Actor *pParentActor = NULL );
|
||||
Actor* MakeActor( const RString &sPath, const XNode *pParent = NULL, Actor *pParentActor = NULL );
|
||||
bool GetAttrPath( const XNode *pNode, const RString &sName, RString &sOut );
|
||||
|
||||
void ResolvePath( RString &sPath, const RString &sName );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user