2004-01-10 20:43:56 +00:00
|
|
|
#include "global.h" // testing updates
|
2004-12-03 05:19:46 +00:00
|
|
|
#include "Command.h"
|
2004-01-10 20:43:56 +00:00
|
|
|
#include "RageUtil.h"
|
|
|
|
|
#include "RageLog.h"
|
2004-06-10 22:47:51 +00:00
|
|
|
#include "arch/Dialog/Dialog.h"
|
2005-01-24 02:26:55 +00:00
|
|
|
#include "LuaManager.h"
|
2004-11-05 06:43:12 +00:00
|
|
|
|
2004-01-10 20:43:56 +00:00
|
|
|
|
2004-12-03 05:19:46 +00:00
|
|
|
void IncorrectNumberArgsWarning( const Command &command, int iMaxIndexAccessed )
|
2004-01-10 20:43:56 +00:00
|
|
|
{
|
2004-12-03 05:19:46 +00:00
|
|
|
const CString sError = ssprintf( "Actor::HandleCommand: Wrong number of arguments in command '%s'. Expected %d but there are %u.",
|
|
|
|
|
command.GetOriginalCommandString().c_str(), iMaxIndexAccessed+1, unsigned(command.m_vsArgs.size()) );
|
2004-01-10 20:43:56 +00:00
|
|
|
LOG->Warn( sError );
|
2004-06-10 22:47:51 +00:00
|
|
|
Dialog::OK( sError );
|
2004-01-10 20:43:56 +00:00
|
|
|
}
|
|
|
|
|
|
2004-12-03 05:19:46 +00:00
|
|
|
CString Command::GetName() const
|
2004-01-10 20:43:56 +00:00
|
|
|
{
|
2004-12-03 05:19:46 +00:00
|
|
|
if( m_vsArgs.empty() )
|
2005-09-04 16:55:21 +00:00
|
|
|
return CString();
|
2004-12-03 05:19:46 +00:00
|
|
|
CString s = m_vsArgs[0];
|
|
|
|
|
s.MakeLower();
|
|
|
|
|
return s;
|
2004-01-10 20:43:56 +00:00
|
|
|
}
|
|
|
|
|
|
2004-12-03 05:19:46 +00:00
|
|
|
Command::Arg Command::GetArg( unsigned index ) const
|
2004-01-10 20:43:56 +00:00
|
|
|
{
|
2004-12-03 05:19:46 +00:00
|
|
|
Arg a;
|
|
|
|
|
if( index < m_vsArgs.size() )
|
|
|
|
|
a.s = m_vsArgs[index];
|
|
|
|
|
return a;
|
|
|
|
|
}
|
2004-01-10 20:43:56 +00:00
|
|
|
|
2004-12-03 05:19:46 +00:00
|
|
|
Command::Arg::operator CString ()
|
|
|
|
|
{
|
2005-01-20 01:08:26 +00:00
|
|
|
CString sValue = s;
|
2005-06-16 22:17:45 +00:00
|
|
|
LuaHelpers::RunAtExpressionS( sValue );
|
2005-01-20 01:08:26 +00:00
|
|
|
return sValue;
|
2004-12-03 05:19:46 +00:00
|
|
|
}
|
2004-01-10 20:43:56 +00:00
|
|
|
|
2004-12-03 05:19:46 +00:00
|
|
|
Command::Arg::operator float ()
|
|
|
|
|
{
|
2005-06-16 22:22:37 +00:00
|
|
|
LuaHelpers::PrepareExpression( s ); // strip invalid chars
|
2005-06-16 06:30:33 +00:00
|
|
|
return LuaHelpers::RunExpressionF( s );
|
2004-12-03 05:19:46 +00:00
|
|
|
}
|
2004-11-06 03:51:06 +00:00
|
|
|
|
2004-12-03 05:19:46 +00:00
|
|
|
Command::Arg::operator int ()
|
|
|
|
|
{
|
2005-06-16 22:22:37 +00:00
|
|
|
LuaHelpers::PrepareExpression( s ); // strip invalid chars
|
2005-06-16 06:30:33 +00:00
|
|
|
return (int) LuaHelpers::RunExpressionF( s );
|
2004-12-03 05:19:46 +00:00
|
|
|
}
|
2004-11-06 03:51:06 +00:00
|
|
|
|
2004-12-03 05:19:46 +00:00
|
|
|
Command::Arg::operator bool ()
|
|
|
|
|
{
|
2005-06-16 22:22:37 +00:00
|
|
|
LuaHelpers::PrepareExpression( s ); // strip invalid chars
|
2005-06-16 06:30:33 +00:00
|
|
|
return LuaHelpers::RunExpressionF( s ) != 0.0f;
|
2004-01-10 20:43:56 +00:00
|
|
|
}
|
|
|
|
|
|
2004-12-03 05:19:46 +00:00
|
|
|
void Command::Load( const CString &sCommand )
|
2004-01-10 20:43:56 +00:00
|
|
|
{
|
2004-12-03 05:19:46 +00:00
|
|
|
m_vsArgs.clear();
|
|
|
|
|
split( sCommand, ",", m_vsArgs, false ); // don't ignore empty
|
2004-01-10 20:43:56 +00:00
|
|
|
}
|
|
|
|
|
|
2004-12-03 05:19:46 +00:00
|
|
|
CString Command::GetOriginalCommandString() const
|
|
|
|
|
{
|
|
|
|
|
return join( ",", m_vsArgs );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ParseCommands( const CString &sCommands, Commands &vCommandsOut )
|
2004-01-10 20:43:56 +00:00
|
|
|
{
|
|
|
|
|
CStringArray vsCommands;
|
|
|
|
|
split( sCommands, ";", vsCommands, true ); // do ignore empty
|
|
|
|
|
|
2004-12-02 05:56:38 +00:00
|
|
|
vCommandsOut.v.resize( vsCommands.size() );
|
2004-12-03 05:19:46 +00:00
|
|
|
|
2004-01-11 08:26:42 +00:00
|
|
|
for( unsigned i=0; i<vsCommands.size(); i++ )
|
2004-01-10 20:43:56 +00:00
|
|
|
{
|
2004-12-03 05:19:46 +00:00
|
|
|
Command &cmd = vCommandsOut.v[i];
|
|
|
|
|
cmd.Load( vsCommands[i] );
|
2004-01-10 20:43:56 +00:00
|
|
|
}
|
|
|
|
|
}
|
2004-06-08 00:47:53 +00:00
|
|
|
|
2004-12-03 05:19:46 +00:00
|
|
|
Commands ParseCommands( const CString &sCommands )
|
2004-11-06 23:13:47 +00:00
|
|
|
{
|
2004-12-03 05:19:46 +00:00
|
|
|
Commands vCommands;
|
|
|
|
|
ParseCommands( sCommands, vCommands );
|
2004-11-06 23:13:47 +00:00
|
|
|
return vCommands;
|
|
|
|
|
}
|
|
|
|
|
|
2004-06-08 00:47:53 +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.
|
|
|
|
|
*/
|