2004-06-08 00:47:53 +00:00
|
|
|
#include "global.h"
|
2003-07-07 01:29:18 +00:00
|
|
|
#include "ActorUtil.h"
|
|
|
|
|
#include "Sprite.h"
|
|
|
|
|
#include "Model.h"
|
2003-10-31 00:50:06 +00:00
|
|
|
#include "BGAnimation.h"
|
2003-10-30 03:51:53 +00:00
|
|
|
#include "ThemeManager.h"
|
2005-08-26 19:05:10 +00:00
|
|
|
#include "RageFileManager.h"
|
2003-10-30 21:57:38 +00:00
|
|
|
#include "RageLog.h"
|
2005-10-07 01:45:20 +00:00
|
|
|
#include "RageUtil.h"
|
2005-09-03 05:52:00 +00:00
|
|
|
#include "EnumHelper.h"
|
2005-01-07 22:01:57 +00:00
|
|
|
#include "XmlFile.h"
|
2005-01-24 02:26:55 +00:00
|
|
|
#include "LuaManager.h"
|
2005-03-13 20:44:26 +00:00
|
|
|
#include "Foreach.h"
|
2003-07-07 01:29:18 +00:00
|
|
|
|
2004-08-07 21:32:43 +00:00
|
|
|
#include "arch/Dialog/Dialog.h"
|
|
|
|
|
|
2003-07-07 01:29:18 +00:00
|
|
|
|
2005-02-09 05:31:14 +00:00
|
|
|
// Actor registration
|
|
|
|
|
static map<CString,CreateActorFn> *g_pmapRegistrees = NULL;
|
|
|
|
|
|
2005-02-23 02:14:06 +00:00
|
|
|
static bool IsRegistered( const CString& sClassName )
|
|
|
|
|
{
|
|
|
|
|
return g_pmapRegistrees->find( sClassName ) != g_pmapRegistrees->end();
|
|
|
|
|
}
|
|
|
|
|
|
2005-02-09 05:31:14 +00:00
|
|
|
void ActorUtil::Register( const CString& sClassName, CreateActorFn pfn )
|
|
|
|
|
{
|
|
|
|
|
if( g_pmapRegistrees == NULL )
|
|
|
|
|
g_pmapRegistrees = new map<CString,CreateActorFn>;
|
|
|
|
|
|
|
|
|
|
map<CString,CreateActorFn>::iterator iter = g_pmapRegistrees->find( sClassName );
|
|
|
|
|
ASSERT_M( iter == g_pmapRegistrees->end(), ssprintf("Actor class '%s' already registered.", sClassName.c_str()) );
|
|
|
|
|
|
|
|
|
|
(*g_pmapRegistrees)[sClassName] = pfn;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Actor* ActorUtil::Create( const CString& sClassName, const CString& sDir, const XNode* pNode )
|
|
|
|
|
{
|
|
|
|
|
map<CString,CreateActorFn>::iterator iter = g_pmapRegistrees->find( sClassName );
|
|
|
|
|
ASSERT_M( iter != g_pmapRegistrees->end(), ssprintf("Actor '%s' is not registered.",sClassName.c_str()) )
|
|
|
|
|
|
|
|
|
|
CreateActorFn pfn = iter->second;
|
2005-05-30 21:09:48 +00:00
|
|
|
return (*pfn)( sDir, pNode );
|
2005-02-09 05:31:14 +00:00
|
|
|
}
|
|
|
|
|
|
2005-02-26 10:07:02 +00:00
|
|
|
/* Return false to retry. */
|
|
|
|
|
void ActorUtil::ResolvePath( CString &sPath, const CString &sName )
|
|
|
|
|
{
|
|
|
|
|
const CString sOriginalPath( sPath );
|
|
|
|
|
|
|
|
|
|
retry:
|
|
|
|
|
CollapsePath( sPath );
|
|
|
|
|
|
|
|
|
|
// If we know this is an exact match, don't bother with the GetDirListing,
|
|
|
|
|
// so "foo" doesn't partial match "foobar" if "foo" exists.
|
2005-08-26 19:05:10 +00:00
|
|
|
RageFileManager::FileType ft = FILEMAN->GetFileType( sPath );
|
|
|
|
|
if( ft != RageFileManager::TYPE_FILE && ft != RageFileManager::TYPE_DIR )
|
2005-02-26 10:07:02 +00:00
|
|
|
{
|
|
|
|
|
CStringArray asPaths;
|
|
|
|
|
GetDirListing( sPath + "*", asPaths, false, true ); // return path too
|
|
|
|
|
|
|
|
|
|
if( asPaths.empty() )
|
|
|
|
|
{
|
|
|
|
|
CString sError = ssprintf( "A file in '%s' references a file '%s' which doesn't exist.", sName.c_str(), sPath.c_str() );
|
|
|
|
|
switch( Dialog::AbortRetryIgnore( sError, "BROKEN_FILE_REFERENCE" ) )
|
|
|
|
|
{
|
|
|
|
|
case Dialog::abort:
|
|
|
|
|
RageException::Throw( sError );
|
|
|
|
|
break;
|
|
|
|
|
case Dialog::retry:
|
|
|
|
|
FlushDirCache();
|
|
|
|
|
goto retry;
|
|
|
|
|
case Dialog::ignore:
|
|
|
|
|
asPaths.push_back( sPath );
|
|
|
|
|
if( GetExtension(asPaths[0]) == "" )
|
|
|
|
|
asPaths[0] = SetExtension( asPaths[0], "png" );
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
ASSERT(0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if( asPaths.size() > 1 )
|
|
|
|
|
{
|
|
|
|
|
CString sError = ssprintf( "A file in '%s' references a file '%s' which has multiple matches.", sName.c_str(), sPath.c_str() );
|
|
|
|
|
switch( Dialog::AbortRetryIgnore( sError, "BROKEN_FILE_REFERENCE" ) )
|
|
|
|
|
{
|
|
|
|
|
case Dialog::abort:
|
|
|
|
|
RageException::Throw( sError );
|
|
|
|
|
break;
|
|
|
|
|
case Dialog::retry:
|
|
|
|
|
FlushDirCache();
|
|
|
|
|
goto retry;
|
|
|
|
|
case Dialog::ignore:
|
|
|
|
|
asPaths.erase( asPaths.begin()+1, asPaths.end() );
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
ASSERT(0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sPath = asPaths[0];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sPath = DerefRedir( sPath );
|
|
|
|
|
}
|
2005-02-09 05:31:14 +00:00
|
|
|
|
|
|
|
|
|
2005-07-22 19:57:42 +00:00
|
|
|
Actor* ActorUtil::LoadFromActorFile( const CString& sDir, const XNode* pNode )
|
2004-12-27 10:24:54 +00:00
|
|
|
{
|
2005-01-17 05:28:16 +00:00
|
|
|
ASSERT( pNode );
|
|
|
|
|
|
2005-01-17 04:08:08 +00:00
|
|
|
{
|
|
|
|
|
CString expr;
|
2005-01-17 05:28:16 +00:00
|
|
|
if( pNode->GetAttrValue("Condition",expr) )
|
2005-01-17 04:08:08 +00:00
|
|
|
{
|
2005-07-25 07:41:23 +00:00
|
|
|
LuaHelpers::RunAtExpressionS( expr );
|
2005-06-16 06:23:59 +00:00
|
|
|
if( !LuaHelpers::RunExpressionB(expr) )
|
2005-01-17 04:08:08 +00:00
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2005-07-22 19:57:42 +00:00
|
|
|
// Load Params
|
|
|
|
|
{
|
|
|
|
|
FOREACH_CONST_Child( pNode, pChild )
|
|
|
|
|
{
|
|
|
|
|
if( pChild->m_sName == "Param" )
|
|
|
|
|
{
|
|
|
|
|
CString sName;
|
|
|
|
|
if( !pChild->GetAttrValue( "Name", sName ) )
|
|
|
|
|
{
|
|
|
|
|
RageException::Throw( ssprintf("Param node in '%s' is missing the attribute 'Name'", sDir.c_str()) );
|
|
|
|
|
}
|
|
|
|
|
|
2005-09-06 04:39:36 +00:00
|
|
|
LuaHelpers::RunAtExpressionS( sName );
|
2005-08-14 23:02:22 +00:00
|
|
|
|
2005-07-22 19:57:42 +00:00
|
|
|
CString s;
|
2005-09-08 05:42:31 +00:00
|
|
|
if( pChild->GetAttrValue( "Value", s ) )
|
2005-07-22 19:57:42 +00:00
|
|
|
{
|
2005-08-14 23:02:22 +00:00
|
|
|
THEME->EvaluateString( s );
|
2005-07-22 19:57:42 +00:00
|
|
|
LUA->SetGlobalFromExpression( sName, s );
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
RageException::Throw( ssprintf("Param node in '%s' is missing the attribute 'Function' or 'Value'", sDir.c_str()) );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-01-08 02:05:31 +00:00
|
|
|
// Element name is the type in XML.
|
|
|
|
|
// Type= is the name in INI.
|
2005-04-11 15:39:44 +00:00
|
|
|
CString sClass = pNode->m_sName;
|
|
|
|
|
bool bHasClass = pNode->GetAttrValue( "Class", sClass );
|
|
|
|
|
if( !bHasClass )
|
|
|
|
|
bHasClass = pNode->GetAttrValue( "Type", sClass ); // for backward compatibility
|
2004-01-25 22:22:40 +00:00
|
|
|
|
2005-07-26 21:12:00 +00:00
|
|
|
// backward compat hack
|
|
|
|
|
if( !bHasClass )
|
|
|
|
|
{
|
|
|
|
|
CString sText;
|
|
|
|
|
if( pNode->GetAttrValue( "Text", sText ) )
|
|
|
|
|
sClass = "BitmapText";
|
|
|
|
|
}
|
2005-01-16 08:15:20 +00:00
|
|
|
|
2005-07-22 19:57:42 +00:00
|
|
|
Actor *pReturn = NULL;
|
2005-02-15 07:57:38 +00:00
|
|
|
|
2005-04-11 15:39:44 +00:00
|
|
|
if( IsRegistered(sClass) )
|
2005-01-17 04:08:08 +00:00
|
|
|
{
|
2005-07-22 19:57:42 +00:00
|
|
|
pReturn = ActorUtil::Create( sClass, sDir, pNode );
|
2005-01-16 08:15:20 +00:00
|
|
|
}
|
2005-04-11 15:39:44 +00:00
|
|
|
else // sClass is empty or garbage (e.g. "1" // 0==Sprite")
|
2005-01-16 08:15:20 +00:00
|
|
|
{
|
|
|
|
|
// automatically figure out the type
|
2005-09-01 06:12:15 +00:00
|
|
|
CString sFile;
|
|
|
|
|
pNode->GetAttrValue( "File", sFile );
|
|
|
|
|
|
|
|
|
|
LuaHelpers::RunAtExpressionS( sFile );
|
|
|
|
|
bool bIsAbsolutePath = sFile.Left(1) == "/";
|
|
|
|
|
FixSlashesInPlace( sFile );
|
|
|
|
|
|
2005-01-16 08:15:20 +00:00
|
|
|
/* Be careful: if sFile is "", and we don't check it, then we can end up recursively
|
2005-09-01 06:12:15 +00:00
|
|
|
* loading the layer we're in. */
|
2005-01-16 08:15:20 +00:00
|
|
|
if( sFile == "" )
|
2005-04-11 15:39:44 +00:00
|
|
|
{
|
2005-09-02 00:09:21 +00:00
|
|
|
CString sError = ssprintf( "An xml file in '%s' is missing the File attribute or has an invalid Class \"%s\"",
|
2005-07-22 19:57:42 +00:00
|
|
|
sDir.c_str(), sClass.c_str() );
|
2005-06-07 09:44:38 +00:00
|
|
|
Dialog::OK( sError );
|
2005-09-03 23:07:56 +00:00
|
|
|
pReturn = new Actor; // Return a dummy object so that we don't crash in AutoActor later.
|
2005-07-22 19:57:42 +00:00
|
|
|
goto all_done;
|
2005-04-11 15:39:44 +00:00
|
|
|
}
|
2004-03-26 08:08:02 +00:00
|
|
|
|
2005-07-22 19:57:42 +00:00
|
|
|
CString sNewPath = bIsAbsolutePath ? sFile : sDir+sFile;
|
|
|
|
|
|
|
|
|
|
ActorUtil::ResolvePath( sNewPath, sDir );
|
2005-01-16 08:15:20 +00:00
|
|
|
|
2005-07-22 19:57:42 +00:00
|
|
|
pReturn = ActorUtil::MakeActor( sNewPath );
|
|
|
|
|
if( pReturn == NULL )
|
|
|
|
|
goto all_done;
|
2005-10-10 08:23:00 +00:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Hack: take attributes from the file loading the new actor,
|
|
|
|
|
* and load them on top of the new file. This way, you can do
|
|
|
|
|
* eg:
|
|
|
|
|
*
|
|
|
|
|
* file1.xml: <Layer File="file2" OnCommand="x,10" />
|
|
|
|
|
* file2.xml: <Layer File="image" OffCommand="y,10" />
|
|
|
|
|
*
|
|
|
|
|
* Be sure to only run the low-level load, to pull in commands;
|
|
|
|
|
* don't reload the high-level actor, and don't rerun Init (which
|
|
|
|
|
* has already been run).
|
|
|
|
|
*/
|
|
|
|
|
pReturn->Actor::LoadFromNode( sDir, pNode );
|
2005-07-22 19:57:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
all_done:
|
2005-01-16 08:15:20 +00:00
|
|
|
|
2005-07-22 19:57:42 +00:00
|
|
|
// Unload Params
|
|
|
|
|
{
|
|
|
|
|
FOREACH_CONST_Child( pNode, pChild )
|
|
|
|
|
{
|
|
|
|
|
if( pChild->m_sName == "Param" )
|
|
|
|
|
{
|
|
|
|
|
CString sName;
|
|
|
|
|
if( !pChild->GetAttrValue( "Name", sName ) )
|
|
|
|
|
{
|
|
|
|
|
RageException::Throw( ssprintf("Param node in '%s' is missing the attribute 'Name'", sDir.c_str()) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LUA->UnsetGlobal( sName );
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-10-30 03:51:53 +00:00
|
|
|
}
|
2005-07-22 19:57:42 +00:00
|
|
|
|
|
|
|
|
return pReturn;
|
2003-10-30 03:51:53 +00:00
|
|
|
}
|
|
|
|
|
|
2005-10-10 20:55:47 +00:00
|
|
|
Actor* ActorUtil::MakeActor( const CString &sPath )
|
2003-10-30 03:51:53 +00:00
|
|
|
{
|
2005-10-10 20:55:47 +00:00
|
|
|
FileType ft = GetFileType( sPath );
|
2005-05-29 01:04:44 +00:00
|
|
|
switch( ft )
|
2003-10-30 03:51:53 +00:00
|
|
|
{
|
2005-05-29 01:04:44 +00:00
|
|
|
case FT_Directory:
|
|
|
|
|
{
|
2005-10-10 20:55:47 +00:00
|
|
|
CString sDir = sPath;
|
2005-05-29 01:04:44 +00:00
|
|
|
if( sDir.Right(1) != "/" )
|
|
|
|
|
sDir += '/';
|
2005-01-17 01:32:45 +00:00
|
|
|
|
2005-09-03 05:58:22 +00:00
|
|
|
CString sXml = sDir + "default.xml";
|
2005-10-11 00:48:27 +00:00
|
|
|
if( !DoesFileExist(sXml) )
|
2005-05-29 01:04:44 +00:00
|
|
|
{
|
|
|
|
|
BGAnimation *pBGA = new BGAnimation;
|
|
|
|
|
pBGA->LoadFromAniDir( sDir );
|
|
|
|
|
return pBGA;
|
|
|
|
|
}
|
2005-10-11 00:48:27 +00:00
|
|
|
|
|
|
|
|
XNode xml;
|
|
|
|
|
if( !xml.LoadFromFile(sXml) )
|
|
|
|
|
{
|
|
|
|
|
// XNode will warn about the error
|
|
|
|
|
return new Actor;
|
|
|
|
|
}
|
|
|
|
|
return LoadFromActorFile( sDir, &xml );
|
2005-05-29 01:04:44 +00:00
|
|
|
}
|
2005-10-11 00:47:15 +00:00
|
|
|
case FT_Xml:
|
|
|
|
|
{
|
|
|
|
|
XNode xml;
|
|
|
|
|
if( !xml.LoadFromFile(sPath) )
|
|
|
|
|
{
|
|
|
|
|
// XNode will warn about the error
|
|
|
|
|
return new Actor;
|
|
|
|
|
}
|
|
|
|
|
CString sDir = Dirname( sPath );
|
|
|
|
|
return LoadFromActorFile( sDir, &xml );
|
|
|
|
|
}
|
2005-05-29 01:04:44 +00:00
|
|
|
case FT_Bitmap:
|
|
|
|
|
case FT_Movie:
|
2005-01-17 01:32:45 +00:00
|
|
|
{
|
2005-05-29 01:04:44 +00:00
|
|
|
Sprite* pSprite = new Sprite;
|
2005-10-10 20:55:47 +00:00
|
|
|
pSprite->Load( sPath );
|
2005-05-29 01:04:44 +00:00
|
|
|
return pSprite;
|
2005-01-17 01:32:45 +00:00
|
|
|
}
|
2005-05-29 01:04:44 +00:00
|
|
|
case FT_Model:
|
2005-01-17 01:32:45 +00:00
|
|
|
{
|
2005-05-29 01:04:44 +00:00
|
|
|
Model* pModel = new Model;
|
2005-10-10 20:55:47 +00:00
|
|
|
pModel->Load( sPath );
|
2005-05-29 01:04:44 +00:00
|
|
|
return pModel;
|
2005-01-17 01:32:45 +00:00
|
|
|
}
|
2005-05-29 01:04:44 +00:00
|
|
|
default:
|
2004-11-26 17:28:47 +00:00
|
|
|
RageException::Throw("File \"%s\" has unknown type, \"%s\"",
|
2005-10-10 20:55:47 +00:00
|
|
|
sPath.c_str(), FileTypeToString(ft).c_str() );
|
2004-11-26 17:28:47 +00:00
|
|
|
}
|
2003-07-07 01:29:18 +00:00
|
|
|
}
|
|
|
|
|
|
2005-02-23 22:21:39 +00:00
|
|
|
void ActorUtil::SetXY( Actor& actor, const CString &sType )
|
2003-10-31 00:50:06 +00:00
|
|
|
{
|
2005-05-31 08:09:04 +00:00
|
|
|
ASSERT( !actor.GetName().empty() );
|
2005-08-25 23:03:30 +00:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Hack: We normally SET_XY in Init(), and run ON_COMMAND in BeginScreen. We
|
|
|
|
|
* want to load the actor's commands in Init(), since that takes long enough
|
|
|
|
|
* to skip. So, run LoadAllCommands here if it hasn't been run yet.
|
|
|
|
|
*/
|
|
|
|
|
if( !actor.HasCommand("On") ) // this actor hasn't loaded commands yet
|
|
|
|
|
LoadAllCommands( actor, sType );
|
|
|
|
|
|
2005-09-21 17:45:34 +00:00
|
|
|
/*
|
|
|
|
|
* Hack: This is run after InitCommand, and InitCommand might set X/Y. If
|
|
|
|
|
* these are both 0, leave the actor where it is. If InitCommand doesn't,
|
|
|
|
|
* then 0,0 is the default, anyway.
|
|
|
|
|
*/
|
|
|
|
|
float fX = THEME->GetMetricF(sType,actor.GetName()+"X");
|
|
|
|
|
float fY = THEME->GetMetricF(sType,actor.GetName()+"Y");
|
|
|
|
|
if( fX != 0 || fY != 0 )
|
|
|
|
|
actor.SetXY( fX, fY );
|
2003-10-31 00:50:06 +00:00
|
|
|
}
|
|
|
|
|
|
2005-03-13 20:44:26 +00:00
|
|
|
void ActorUtil::LoadCommand( Actor& actor, const CString &sType, const CString &sCommandName )
|
2003-10-31 00:50:06 +00:00
|
|
|
{
|
2005-09-08 03:38:08 +00:00
|
|
|
ActorUtil::LoadCommandFromName( actor, sType, sCommandName, actor.GetName() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ActorUtil::LoadCommandFromName( Actor& actor, const CString &sType, const CString &sCommandName, const CString &sName )
|
|
|
|
|
{
|
|
|
|
|
actor.AddCommand( sCommandName, THEME->GetMetricA(sType,sName+sCommandName+"Command") );
|
2005-03-13 20:44:26 +00:00
|
|
|
}
|
2003-10-31 00:50:06 +00:00
|
|
|
|
2005-06-12 00:35:08 +00:00
|
|
|
void ActorUtil::LoadAndPlayCommand( Actor& actor, const CString &sType, const CString &sCommandName, Actor* pParent )
|
2005-03-13 20:44:26 +00:00
|
|
|
{
|
2003-10-31 00:50:06 +00:00
|
|
|
// HACK: It's very often that we command things to TweenOffScreen
|
|
|
|
|
// that we aren't drawing. We know that an Actor is not being
|
2003-11-05 06:43:26 +00:00
|
|
|
// used if its name is blank. So, do nothing on Actors with a blank name.
|
2003-10-31 02:01:16 +00:00
|
|
|
// (Do "playcommand" anyway; BGAs often have no name.)
|
2005-05-31 08:09:04 +00:00
|
|
|
if( sCommandName=="Off" && actor.GetName().empty() )
|
2005-03-13 20:44:26 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
ASSERT_M(
|
2005-05-31 08:09:04 +00:00
|
|
|
!actor.GetName().empty(),
|
|
|
|
|
ssprintf("!actor.GetName().empty() ('%s', '%s')", sType.c_str(), sCommandName.c_str())
|
2005-03-13 20:44:26 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if( !actor.HasCommand(sCommandName ) ) // this actor hasn't loaded commands yet
|
|
|
|
|
LoadAllCommands( actor, sType );
|
|
|
|
|
|
|
|
|
|
// If we didn't load the command in LoadAllCommands, load the requested command
|
|
|
|
|
// explicitly. The metric is missing, and ThemeManager will prompt.
|
|
|
|
|
if( !actor.HasCommand(sCommandName) )
|
2004-11-06 03:09:29 +00:00
|
|
|
{
|
2005-03-13 20:44:26 +00:00
|
|
|
// If this metric exists and we didn't load it in LoadAllCommands, then
|
|
|
|
|
// LoadAllCommands has a bug.
|
2005-05-31 08:09:04 +00:00
|
|
|
DEBUG_ASSERT( !THEME->HasMetric(sType,actor.GetName()+sCommandName+"Command") );
|
2005-03-13 20:44:26 +00:00
|
|
|
|
|
|
|
|
LoadCommand( actor, sType, sCommandName );
|
2004-11-06 03:09:29 +00:00
|
|
|
}
|
2003-10-31 01:02:50 +00:00
|
|
|
|
2005-06-12 00:35:08 +00:00
|
|
|
actor.PlayCommand( sCommandName, pParent );
|
2003-10-31 00:50:06 +00:00
|
|
|
}
|
2004-01-10 20:34:18 +00:00
|
|
|
|
2005-03-13 20:44:26 +00:00
|
|
|
void ActorUtil::LoadAllCommands( Actor& actor, const CString &sType )
|
2005-09-07 20:41:50 +00:00
|
|
|
{
|
|
|
|
|
LoadAllCommandsFromName( actor, sType, actor.GetName() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ActorUtil::LoadAllCommandsFromName( Actor& actor, const CString &sType, const CString &sName )
|
2005-02-23 23:04:06 +00:00
|
|
|
{
|
2005-03-13 20:44:26 +00:00
|
|
|
set<CString> vsValueNames;
|
2005-09-07 20:41:50 +00:00
|
|
|
THEME->GetMetricsThatBeginWith( sType, sName, vsValueNames );
|
2005-03-13 20:44:26 +00:00
|
|
|
|
|
|
|
|
FOREACHS_CONST( CString, vsValueNames, v )
|
|
|
|
|
{
|
|
|
|
|
const CString &sv = *v;
|
|
|
|
|
if( sv.Right(7) == "Command" )
|
|
|
|
|
{
|
2005-09-07 20:41:50 +00:00
|
|
|
CString sCommandName( sv.begin()+sName.size(), sv.end()-7 );
|
2005-09-08 03:38:08 +00:00
|
|
|
LoadCommandFromName( actor, sType, sCommandName, sName );
|
2005-03-13 20:44:26 +00:00
|
|
|
}
|
|
|
|
|
}
|
2005-02-23 23:04:06 +00:00
|
|
|
}
|
|
|
|
|
|
2005-05-03 09:29:54 +00:00
|
|
|
static bool CompareActorsByZPosition(const Actor *p1, const Actor *p2)
|
|
|
|
|
{
|
|
|
|
|
return p1->GetZ() < p2->GetZ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ActorUtil::SortByZPosition( vector<Actor*> &vActors )
|
|
|
|
|
{
|
|
|
|
|
// Preserve ordering of Actors with equal Z positions.
|
|
|
|
|
stable_sort( vActors.begin(), vActors.end(), CompareActorsByZPosition );
|
|
|
|
|
}
|
|
|
|
|
|
2005-05-29 01:04:44 +00:00
|
|
|
static const CString FileTypeNames[] = {
|
|
|
|
|
"Bitmap",
|
|
|
|
|
"Movie",
|
|
|
|
|
"Directory",
|
|
|
|
|
"Xml",
|
|
|
|
|
"Model",
|
|
|
|
|
};
|
|
|
|
|
XToString( FileType, NUM_FileType );
|
|
|
|
|
|
|
|
|
|
FileType ActorUtil::GetFileType( const CString &sPath )
|
|
|
|
|
{
|
|
|
|
|
CString sExt = GetExtension( sPath );
|
|
|
|
|
sExt.MakeLower();
|
|
|
|
|
|
2005-09-02 00:09:21 +00:00
|
|
|
if( sExt=="xml" ) return FT_Xml;
|
2005-05-29 01:04:44 +00:00
|
|
|
else if(
|
|
|
|
|
sExt=="png" ||
|
|
|
|
|
sExt=="jpg" ||
|
|
|
|
|
sExt=="gif" ||
|
|
|
|
|
sExt=="bmp" ) return FT_Bitmap;
|
|
|
|
|
else if(
|
|
|
|
|
sExt=="avi" ||
|
|
|
|
|
sExt=="mpeg" ||
|
|
|
|
|
sExt=="mpg" ) return FT_Movie;
|
|
|
|
|
else if(
|
2005-07-05 23:46:08 +00:00
|
|
|
sExt=="txt" ) return FT_Model;
|
2005-08-26 19:41:19 +00:00
|
|
|
/* Do this last, to avoid the IsADirectory in most cases. */
|
|
|
|
|
else if( IsADirectory(sPath) ) return FT_Directory;
|
2005-05-29 01:04:44 +00:00
|
|
|
else return FT_Invalid;
|
|
|
|
|
}
|
2005-05-03 09:29:54 +00:00
|
|
|
|
2004-06-08 00:47:53 +00:00
|
|
|
/*
|
|
|
|
|
* (c) 2003-2004 Chris Danford
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
|
* copy of this software and associated documentation files (the
|
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
|
* distribute, and/or sell copies of the Software, and to permit persons to
|
|
|
|
|
* whom the Software is furnished to do so, provided that the above
|
|
|
|
|
* copyright notice(s) and this permission notice appear in all copies of
|
|
|
|
|
* the Software and that both the above copyright notice(s) and this
|
|
|
|
|
* permission notice appear in supporting documentation.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
|
|
|
|
|
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
|
|
|
|
|
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
|
|
|
|
|
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
|
|
|
|
|
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
|
|
|
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
|
|
|
* PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
|
*/
|