Files
itgmania212121/stepmania/src/BGAnimation.cpp
T

192 lines
5.3 KiB
C++
Raw Normal View History

2003-02-16 04:01:45 +00:00
#include "global.h"
2002-09-29 05:06:18 +00:00
#include "BGAnimation.h"
#include "IniFile.h"
#include "BGAnimationLayer.h"
2003-03-05 02:52:40 +00:00
#include "RageUtil.h"
2003-10-31 01:55:17 +00:00
#include "ActorUtil.h"
#include "Foreach.h"
2005-01-26 11:21:43 +00:00
#include "Command.h"
#include "LuaManager.h"
2002-09-29 05:06:18 +00:00
2005-01-16 19:19:24 +00:00
BGAnimation::BGAnimation()
2002-09-29 05:06:18 +00:00
{
}
BGAnimation::~BGAnimation()
{
2004-02-01 03:14:37 +00:00
DeleteAllChildren();
2002-09-29 05:06:18 +00:00
}
static bool CompareLayerNames( const CString& s1, const CString& s2 )
{
int i1, i2;
int ret;
ret = sscanf( s1, "Layer%d", &i1 );
ASSERT( ret == 1 );
ret = sscanf( s2, "Layer%d", &i2 );
ASSERT( ret == 1 );
return i1 < i2;
}
2005-09-01 06:23:59 +00:00
void BGAnimation::AddLayersFromAniDir( const CString &_sAniDir, const XNode *pNode )
2002-09-29 05:06:18 +00:00
{
2005-01-17 00:58:07 +00:00
const CString& sAniDir = _sAniDir;
2003-10-14 17:05:10 +00:00
2002-09-29 05:06:18 +00:00
{
vector<CString> vsLayerNames;
2005-09-01 06:23:59 +00:00
FOREACH_CONST_Child( pNode, pLayer )
{
2005-01-07 14:28:00 +00:00
if( strncmp(pLayer->m_sName, "Layer", 5) == 0 )
vsLayerNames.push_back( pLayer->m_sName );
}
sort( vsLayerNames.begin(), vsLayerNames.end(), CompareLayerNames );
2003-03-05 02:52:40 +00:00
FOREACH_CONST( CString, vsLayerNames, s )
2003-03-05 02:52:40 +00:00
{
2005-01-07 14:28:00 +00:00
const CString &sLayer = *s;
2005-09-01 06:23:59 +00:00
const XNode* pKey = pNode->GetChild( sLayer );
ASSERT( pKey );
CString sImportDir;
2005-01-07 14:28:00 +00:00
if( pKey->GetAttrValue("Import", sImportDir) )
2004-05-03 03:58:41 +00:00
{
CString expr;
2005-01-07 14:28:00 +00:00
if( pKey->GetAttrValue("Condition",expr) )
{
2005-06-16 06:23:59 +00:00
if( !LuaHelpers::RunExpressionB( expr ) )
continue;
}
// import a whole BGAnimation
sImportDir = sAniDir + sImportDir;
CollapsePath( sImportDir );
2005-01-17 00:58:07 +00:00
if( sImportDir.Right(1) != "/" )
sImportDir += "/";
ASSERT_M( IsADirectory(sImportDir), sImportDir + " isn't a directory" );
CString sPathToIni = sImportDir + "BGAnimation.ini";
IniFile ini2;
ini2.ReadFile( sPathToIni );
2005-09-01 06:23:59 +00:00
AddLayersFromAniDir( sImportDir, &ini2 );
}
else
{
// import as a single layer
BGAnimationLayer* pLayer = new BGAnimationLayer;
pLayer->LoadFromNode( sAniDir, pKey );
2005-01-17 00:58:07 +00:00
this->AddChild( pLayer );
2004-05-03 03:58:41 +00:00
}
2003-03-05 02:52:40 +00:00
}
2003-10-14 17:05:10 +00:00
}
}
void BGAnimation::LoadFromAniDir( const CString &_sAniDir )
2003-10-14 17:05:10 +00:00
{
2005-08-31 22:03:40 +00:00
DeleteAllChildren();
2005-01-07 22:01:57 +00:00
if( _sAniDir.empty() )
2003-10-14 17:05:10 +00:00
return;
2005-01-07 22:01:57 +00:00
CString sAniDir = _sAniDir;
2003-12-10 09:44:16 +00:00
if( sAniDir.Right(1) != "/" )
sAniDir += "/";
2003-10-14 17:05:10 +00:00
2004-06-16 00:38:31 +00:00
ASSERT_M( IsADirectory(sAniDir), sAniDir + " isn't a directory" );
2003-10-14 17:05:10 +00:00
CString sPathToIni = sAniDir + "BGAnimation.ini";
2003-10-14 17:05:10 +00:00
if( DoesFileExist(sPathToIni) )
{
// This is a new style BGAnimation (using .ini)
2004-05-23 02:27:51 +00:00
IniFile ini;
ini.ReadFile( sPathToIni );
2005-01-07 22:01:57 +00:00
2005-09-01 06:23:59 +00:00
AddLayersFromAniDir( sAniDir, &ini ); // TODO: Check for circular load
XNode* pBGAnimation = ini.GetChild( "BGAnimation" );
2005-01-07 22:01:57 +00:00
XNode dummy;
dummy.m_sName = "BGAnimation";
if( pBGAnimation == NULL )
pBGAnimation = &dummy;
LoadFromNode( sAniDir, pBGAnimation );
2003-03-05 02:52:40 +00:00
}
else
{
// This is an old style BGAnimation (not using .ini)
// loading a directory of layers
CStringArray asImagePaths;
ASSERT( sAniDir != "" );
GetDirListing( sAniDir+"*.png", asImagePaths, false, true );
GetDirListing( sAniDir+"*.jpg", asImagePaths, false, true );
GetDirListing( sAniDir+"*.gif", asImagePaths, false, true );
GetDirListing( sAniDir+"*.avi", asImagePaths, false, true );
GetDirListing( sAniDir+"*.mpg", asImagePaths, false, true );
GetDirListing( sAniDir+"*.mpeg", asImagePaths, false, true );
SortCStringArray( asImagePaths );
for( unsigned i=0; i<asImagePaths.size(); i++ )
{
const CString sPath = asImagePaths[i];
2003-10-29 20:32:29 +00:00
if( Basename(sPath).Left(1) == "_" )
2003-03-05 02:52:40 +00:00
continue; // don't directly load files starting with an underscore
BGAnimationLayer* pLayer = new BGAnimationLayer;
pLayer->LoadFromAniLayerFile( asImagePaths[i] );
2004-02-01 03:14:37 +00:00
AddChild( pLayer );
2003-03-05 02:52:40 +00:00
}
2002-09-29 05:06:18 +00:00
}
}
void BGAnimation::LoadFromNode( const CString& sDir, const XNode* pNode )
2005-01-07 22:01:57 +00:00
{
ActorFrame::LoadFromNode( sDir, pNode );
2005-01-17 00:58:07 +00:00
/* Backwards-compatibility: if a "LengthSeconds" value is present, create a dummy
* actor that sleeps for the given length of time. This will extend GetTweenTimeLeft. */
float fLengthSeconds = 0;
if( pNode->GetAttrValue( "LengthSeconds", fLengthSeconds ) )
2005-01-07 23:56:18 +00:00
{
Actor *pActor = new Actor;
2005-06-11 10:25:46 +00:00
pActor->SetName( "BGAnimation dummy" );
pActor->SetHidden( true );
apActorCommands ap( new ActorCommands(ssprintf("sleep,%f",fLengthSeconds)) );
pActor->AddCommand( "On", ap );
AddChild( pActor );
2005-01-07 23:56:18 +00:00
}
2005-01-07 22:01:57 +00:00
}
2004-06-01 00:53:06 +00:00
/*
* (c) 2001-2004 Ben Nordstrom, 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.
*/