Files
itgmania212121/stepmania/src/TrailUtil.cpp
T

158 lines
3.9 KiB
C++
Raw Normal View History

2004-05-23 09:17:10 +00:00
#include "global.h"
#include "TrailUtil.h"
#include "Trail.h"
#include "Course.h"
#include "XmlFile.h"
#include "GameManager.h"
2009-03-22 08:42:27 +00:00
#include "Song.h"
2004-05-23 09:17:10 +00:00
2009-03-22 08:42:27 +00:00
int TrailUtil::GetNumSongs( const Trail *pTrail )
{
return pTrail->m_vEntries.size();
}
float TrailUtil::GetTotalSeconds( const Trail *pTrail )
{
float fSecs = 0;
FOREACH_CONST( TrailEntry, pTrail->m_vEntries, e )
fSecs += e->pSong->m_fMusicLengthSeconds;
return fSecs;
}
///////////////////////////////////////////////////////////////////////
2004-05-23 09:17:10 +00:00
void TrailID::FromTrail( const Trail *p )
{
if( p == NULL )
{
2006-09-26 20:28:46 +00:00
st = StepsType_Invalid;
cd = Difficulty_Invalid;
2004-05-23 09:17:10 +00:00
}
else
{
st = p->m_StepsType;
cd = p->m_CourseDifficulty;
}
m_Cache.Unset();
2004-05-23 09:17:10 +00:00
}
Trail *TrailID::ToTrail( const Course *p, bool bAllowNull ) const
{
2004-05-24 06:07:59 +00:00
ASSERT( p );
Trail *pRet = NULL;
if( !m_Cache.Get(&pRet) )
{
if( st != StepsType_Invalid && cd != Difficulty_Invalid )
pRet = p->GetTrail( st, cd );
m_Cache.Set( pRet );
}
2007-08-12 22:23:17 +00:00
if( !bAllowNull && pRet == NULL )
2005-05-23 00:38:09 +00:00
RageException::Throw( "%i, %i, \"%s\"", st, cd, p->GetDisplayFullTitle().c_str() );
2004-06-03 20:46:54 +00:00
2007-08-12 22:23:17 +00:00
return pRet;
2004-05-23 09:17:10 +00:00
}
XNode* TrailID::CreateNode() const
{
2006-10-01 14:53:03 +00:00
XNode* pNode = new XNode( "Trail" );
2004-05-23 09:17:10 +00:00
pNode->AppendAttr( "StepsType", GameManager::GetStepsTypeInfo(st).szName );
2006-10-07 22:49:04 +00:00
pNode->AppendAttr( "CourseDifficulty", DifficultyToString(cd) );
2004-05-23 09:17:10 +00:00
return pNode;
}
void TrailID::LoadFromNode( const XNode* pNode )
{
2006-10-02 06:26:25 +00:00
ASSERT( pNode->GetName() == "Trail" );
2004-05-23 09:17:10 +00:00
2006-01-22 01:00:06 +00:00
RString sTemp;
2004-05-23 09:17:10 +00:00
2007-06-01 04:50:36 +00:00
pNode->GetAttrValue( "StepsType", sTemp );
2004-07-12 02:19:24 +00:00
st = GameManager::StringToStepsType( sTemp );
2004-05-23 09:17:10 +00:00
2007-06-01 04:50:36 +00:00
pNode->GetAttrValue( "CourseDifficulty", sTemp );
cd = StringToDifficulty( sTemp );
m_Cache.Unset();
2004-05-23 09:17:10 +00:00
}
2006-01-22 01:00:06 +00:00
RString TrailID::ToString() const
2004-05-23 09:17:10 +00:00
{
RString s = GameManager::GetStepsTypeInfo(st).szName;
2007-06-01 04:50:36 +00:00
s += " " + DifficultyToString( cd );
2004-05-23 09:17:10 +00:00
return s;
}
bool TrailID::IsValid() const
{
return st != StepsType_Invalid && cd != Difficulty_Invalid;
2004-05-23 09:17:10 +00:00
}
bool TrailID::operator<( const TrailID &rhs ) const
{
#define COMP(a) if(a<rhs.a) return true; if(a>rhs.a) return false;
COMP(st);
COMP(cd);
#undef COMP
return false;
}
2004-05-31 21:35:31 +00:00
2009-03-22 08:42:27 +00:00
// lua start
#include "LuaBinding.h"
namespace
{
int GetNumSongs( lua_State *L )
{
Trail *pTrail = Luna<Trail>::check( L, 1, true );
int iNum = TrailUtil::GetNumSongs( pTrail );
LuaHelpers::Push( L, iNum );
return 1;
}
int GetTotalSeconds( lua_State *L )
{
Trail *pTrail = Luna<Trail>::check( L, 1, true );
float fSecs = TrailUtil::GetTotalSeconds( pTrail );
LuaHelpers::Push( L, fSecs );
return 1;
}
const luaL_Reg TrailUtilTable[] =
{
LIST_METHOD( GetNumSongs ),
LIST_METHOD( GetTotalSeconds ),
{ NULL, NULL }
};
}
LUA_REGISTER_NAMESPACE( TrailUtil )
2004-05-31 21:35:31 +00:00
/*
* (c) 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.
*/