Let ActorCommand do the parsing for ModeChoice

This commit is contained in:
Chris Danford
2004-12-02 05:56:38 +00:00
parent 061fbb276a
commit e1da21f61c
13 changed files with 54 additions and 41 deletions
+1 -1
View File
@@ -619,7 +619,7 @@ void Actor::AddRotationR( float rot )
void Actor::Command( const ActorCommands &vCommands ) void Actor::Command( const ActorCommands &vCommands )
{ {
FOREACH_CONST( ActorCommand, vCommands, c ) FOREACH_CONST( ActorCommand, vCommands.v, c )
this->HandleCommand( *c ); this->HandleCommand( *c );
} }
+3 -3
View File
@@ -54,16 +54,16 @@ CString ActorCommand::GetOriginalCommandString() const
void ParseActorCommands( const CString &sCommands, ActorCommands &vCommandsOut ) void ParseActorCommands( const CString &sCommands, ActorCommands &vCommandsOut )
{ {
vCommandsOut.clear(); vCommandsOut.v.clear();
CStringArray vsCommands; CStringArray vsCommands;
split( sCommands, ";", vsCommands, true ); // do ignore empty split( sCommands, ";", vsCommands, true ); // do ignore empty
vCommandsOut.resize( vsCommands.size() ); vCommandsOut.v.resize( vsCommands.size() );
for( unsigned i=0; i<vsCommands.size(); i++ ) for( unsigned i=0; i<vsCommands.size(); i++ )
{ {
const CString &sCommand = vsCommands[i]; const CString &sCommand = vsCommands[i];
ActorCommand &pc = vCommandsOut[i]; ActorCommand &pc = vCommandsOut.v[i];
pc.Set( sCommand ); pc.Set( sCommand );
} }
} }
+4 -1
View File
@@ -32,7 +32,10 @@ struct ActorCommand
CString GetOriginalCommandString() const; // for when reporting an error in number of params CString GetOriginalCommandString() const; // for when reporting an error in number of params
}; };
typedef vector<ActorCommand> ActorCommands; struct ActorCommands
{
vector<ActorCommand> v;
};
// Take a command list string and return pointers to each of the tokens in the // Take a command list string and return pointers to each of the tokens in the
// string. sCommand list is a list of commands separated by ';'. // string. sCommand list is a list of commands separated by ';'.
+1 -1
View File
@@ -86,7 +86,7 @@ void GameState::ApplyCmdline()
for( int i = 0; GetCommandlineArgument( "mode", &sMode, i ); ++i ) for( int i = 0; GetCommandlineArgument( "mode", &sMode, i ); ++i )
{ {
ModeChoice m; ModeChoice m;
m.Load( 0, sMode ); m.Load( 0, ParseActorCommands(sMode) );
CString why; CString why;
if( !m.IsPlayable(&why) ) if( !m.IsPlayable(&why) )
RageException::Throw( "Can't apply mode \"%s\": %s", sMode.c_str(), why.c_str() ); RageException::Throw( "Can't apply mode \"%s\": %s", sMode.c_str(), why.c_str() );
+2 -2
View File
@@ -201,7 +201,7 @@ bool RunExpression( const CString &str )
{ {
CString err; CString err;
Lua::PopStack( L, err ); Lua::PopStack( L, err );
CString sError = ssprintf( "Runtime error running \"%s\": %s", str.c_str(), err.c_str() ); CString sError = ssprintf( "Lua runtime error parsing \"%s\": %s", str.c_str(), err.c_str() );
Dialog::OK( sError, "LUA_ERROR" ); Dialog::OK( sError, "LUA_ERROR" );
return false; return false;
} }
@@ -216,7 +216,7 @@ bool RunExpression( const CString &str )
{ {
CString err; CString err;
Lua::PopStack( L, err ); Lua::PopStack( L, err );
CString sError = ssprintf( "Runtime error running \"%s\": %s", str.c_str(), err.c_str() ); CString sError = ssprintf( "Lua runtime error evaluating \"%s\": %s", str.c_str(), err.c_str() );
Dialog::OK( sError, "LUA_ERROR" ); Dialog::OK( sError, "LUA_ERROR" );
return false; return false;
} }
+17 -14
View File
@@ -16,6 +16,7 @@
#include "song.h" #include "song.h"
#include "Game.h" #include "Game.h"
#include "Style.h" #include "Style.h"
#include "Foreach.h"
void ModeChoice::Init() void ModeChoice::Init()
{ {
@@ -96,7 +97,7 @@ bool ModeChoice::DescribesCurrentMode( PlayerNumber pn ) const
return true; return true;
} }
void ModeChoice::Load( int iIndex, CString sChoice ) void ModeChoice::Load( int iIndex, const ActorCommands& acs )
{ {
m_iIndex = iIndex; m_iIndex = iIndex;
@@ -104,21 +105,22 @@ void ModeChoice::Load( int iIndex, CString sChoice )
CString sSteps; CString sSteps;
CStringArray asCommands; FOREACH_CONST( ActorCommand, acs.v, command )
split( sChoice, ";", asCommands );
for( unsigned i=0; i<asCommands.size(); i++ )
{ {
CString sCommand = asCommands[i]; if( command->vTokens.empty() )
continue;
CStringArray asBits; const CString &sName = command->vTokens[0]; // name is already made lowercase by ActorCommand
split( sCommand, ",", asBits );
CString sName = asBits[0]; CString sValue;
asBits.erase(asBits.begin(), asBits.begin()+1); for( vector<ActorCommandToken>::const_iterator iter = command->vTokens.begin()+1;
CString sValue = join( ",", asBits ); iter != command->vTokens.end();
iter++ )
sName.MakeLower(); {
// sValue.MakeLower(); sValue += *iter;
if( iter != command->vTokens.end()-1 )
sValue += ",";
}
if( sName == "game" ) if( sName == "game" )
{ {
@@ -207,7 +209,8 @@ void ModeChoice::Load( int iIndex, CString sChoice )
else if( sName == "setenv" ) else if( sName == "setenv" )
{ {
m_SetEnv[ asBits[0] ] = sValue; if( command->vTokens.size() == 3 )
m_SetEnv[ command->vTokens[1] ] = command->vTokens[2];
} }
else if( sName == "songgroup" ) else if( sName == "songgroup" )
+2 -1
View File
@@ -14,13 +14,14 @@ class Trail;
class Character; class Character;
class Style; class Style;
class Game; class Game;
struct ActorCommands;
struct ModeChoice // used in SelectMode struct ModeChoice // used in SelectMode
{ {
ModeChoice() { Init(); } ModeChoice() { Init(); }
void Init(); void Init();
void Load( int iIndex, CString str ); void Load( int iIndex, const ActorCommands& acs );
void ApplyToAllPlayers() const; void ApplyToAllPlayers() const;
void Apply( PlayerNumber pn ) const; void Apply( PlayerNumber pn ) const;
bool DescribesCurrentMode( PlayerNumber pn ) const; bool DescribesCurrentMode( PlayerNumber pn ) const;
+1 -1
View File
@@ -437,7 +437,7 @@ void MusicWheel::BuildWheelItemDatas( vector<WheelItemData> &arrayWheelItemDatas
WheelItemData wid( TYPE_SORT, NULL, "", NULL, SORT_MENU_COLOR, so ); WheelItemData wid( TYPE_SORT, NULL, "", NULL, SORT_MENU_COLOR, so );
wid.m_sLabel = Names[i]; wid.m_sLabel = Names[i];
wid.m_Action.Load( i, Actions[i] ); wid.m_Action.Load( i, ParseActorCommands(Actions[i]) );
switch( so ) switch( so )
{ {
+1 -1
View File
@@ -44,7 +44,7 @@ void ScreenBranch::HandleScreenMessage( const ScreenMessage SM )
LOG->Trace( "Branching to '%s'", sNextScreen.c_str() ); LOG->Trace( "Branching to '%s'", sNextScreen.c_str() );
ModeChoice mc; ModeChoice mc;
mc.Load( 0, sNextScreen ); mc.Load( 0, ParseActorCommands(sNextScreen) );
if( mc.m_sScreen == "" ) if( mc.m_sScreen == "" )
RageException::Throw("Metric %s::%s must set \"screen\"", RageException::Throw("Metric %s::%s must set \"screen\"",
m_sName.c_str(), ("NextScreen"+m_sChoice).c_str() ); m_sName.c_str(), ("NextScreen"+m_sChoice).c_str() );
+5 -5
View File
@@ -58,7 +58,7 @@ void ScreenOptionsMaster::SetList( OptionRowData &row, OptionRowHandler &hand, C
return; return;
} }
hand.Default.Load( -1, ENTRY_DEFAULT(ListName) ); hand.Default.Load( -1, ParseActorCommands(ENTRY_DEFAULT(ListName)) );
/* Parse the basic configuration metric. */ /* Parse the basic configuration metric. */
CStringArray asParts; CStringArray asParts;
@@ -79,7 +79,7 @@ void ScreenOptionsMaster::SetList( OptionRowData &row, OptionRowHandler &hand, C
for( int col = 0; col < NumCols; ++col ) for( int col = 0; col < NumCols; ++col )
{ {
ModeChoice mc; ModeChoice mc;
mc.Load( 0, ENTRY_MODE(ListName, col) ); mc.Load( 0, ParseActorCommands(ENTRY_MODE(ListName, col)) );
if( mc.m_sName == "" ) if( mc.m_sName == "" )
RageException::Throw( "List \"%s\", col %i has no name", ListName.c_str(), col ); RageException::Throw( "List \"%s\", col %i has no name", ListName.c_str(), col );
@@ -250,13 +250,13 @@ ScreenOptionsMaster::ScreenOptionsMaster( CString sClassName ):
ActorCommands vCommands; ActorCommands vCommands;
ParseActorCommands( sRowCommands, vCommands ); ParseActorCommands( sRowCommands, vCommands );
if( vCommands.size() < 1 ) if( vCommands.v.size() < 1 )
RageException::Throw( "Parse error in %s::Line%i", m_sName.c_str(), i+1 ); RageException::Throw( "Parse error in %s::Line%i", m_sName.c_str(), i+1 );
OptionRowHandler hand; OptionRowHandler hand;
for( unsigned part = 0; part < vCommands.size(); ++part) for( unsigned part = 0; part < vCommands.v.size(); ++part)
{ {
ActorCommand& command = vCommands[part]; ActorCommand& command = vCommands.v[part];
BeginHandleParams; BeginHandleParams;
+2 -2
View File
@@ -51,7 +51,7 @@ ScreenSelect::ScreenSelect( CString sClassName ) : ScreenWithMenuElements(sClass
ModeChoice mc; ModeChoice mc;
mc.m_sName = sChoiceName; mc.m_sName = sChoiceName;
mc.Load( c, sChoice ); mc.Load( c, ParseActorCommands(sChoice) );
m_aModeChoices.push_back( mc ); m_aModeChoices.push_back( mc );
CString sBGAnimationDir = THEME->GetPath(BGAnimations, m_sName, mc.m_sName, true); // true="optional" CString sBGAnimationDir = THEME->GetPath(BGAnimations, m_sName, mc.m_sName, true); // true="optional"
@@ -74,7 +74,7 @@ ScreenSelect::ScreenSelect( CString sClassName ) : ScreenWithMenuElements(sClass
m_aCodes.push_back( code ); m_aCodes.push_back( code );
m_aCodeActions.push_back( CODE_ACTION(c) ); m_aCodeActions.push_back( CODE_ACTION(c) );
ModeChoice mc; ModeChoice mc;
mc.Load( c, CODE_ACTION(c) ); mc.Load( c, ParseActorCommands(CODE_ACTION(c)) );
m_aCodeChoices.push_back( mc ); m_aCodeChoices.push_back( mc );
} }
+5
View File
@@ -765,6 +765,11 @@ void ThemeManager::GetModifierNames( set<CString>& AddTo )
} }
} }
void ThemeManager::GetMetric( const CString &sClassName, const CString &sValueName, ActorCommands &valueOut )
{
valueOut = GetMetricA( sClassName, sValueName );
}
/* /*
* (c) 2001-2004 Chris Danford * (c) 2001-2004 Chris Danford
* All rights reserved. * All rights reserved.
+9 -8
View File
@@ -5,12 +5,12 @@
#include "RageTypes.h" #include "RageTypes.h"
#include "RageTimer.h" #include "RageTimer.h"
#include "ActorCommands.h"
#include <set> #include <set>
#include <deque> #include <deque>
class IThemeMetric; class IThemeMetric;
class IniFile; class IniFile;
struct ActorCommands;
enum ElementCategory { BGAnimations, Fonts, Graphics, Numbers, Sounds, Other, NUM_ELEMENT_CATEGORIES }; enum ElementCategory { BGAnimations, Fonts, Graphics, Numbers, Sounds, Other, NUM_ELEMENT_CATEGORIES };
@@ -51,7 +51,7 @@ public:
CString GetPathToS( const CString &sFileName, bool bOptional=false ); CString GetPathToS( const CString &sFileName, bool bOptional=false );
CString GetPathToO( const CString &sFileName, bool bOptional=false ); CString GetPathToO( const CString &sFileName, bool bOptional=false );
// TODO: Make these return values const refs.
bool HasMetric( const CString &sClassName, const CString &sValueName ); bool HasMetric( const CString &sClassName, const CString &sValueName );
CString GetMetricRaw( const CString &sClassName, const CString &sValueName ); CString GetMetricRaw( const CString &sClassName, const CString &sValueName );
CString GetMetric( const CString &sClassName, const CString &sValueName ); CString GetMetric( const CString &sClassName, const CString &sValueName );
@@ -60,12 +60,13 @@ public:
bool GetMetricB( const CString &sClassName, const CString &sValueName ); bool GetMetricB( const CString &sClassName, const CString &sValueName );
RageColor GetMetricC( const CString &sClassName, const CString &sValueName ); RageColor GetMetricC( const CString &sClassName, const CString &sValueName );
ActorCommands GetMetricA( const CString &sClassName, const CString &sValueName ); ActorCommands GetMetricA( const CString &sClassName, const CString &sValueName );
void GetMetric( const CString &sClassName, const CString &sValueName, CString &valueOut ) { valueOut = GetMetric( sClassName, sValueName ); }
void GetMetric( const CString &sClassName, const CString &sValueName, int &valueOut ) { valueOut = GetMetricI( sClassName, sValueName ); } void GetMetric( const CString &sClassName, const CString &sValueName, CString &valueOut ) { valueOut = GetMetric( sClassName, sValueName ); }
void GetMetric( const CString &sClassName, const CString &sValueName, float &valueOut ) { valueOut = GetMetricF( sClassName, sValueName ); } void GetMetric( const CString &sClassName, const CString &sValueName, int &valueOut ) { valueOut = GetMetricI( sClassName, sValueName ); }
void GetMetric( const CString &sClassName, const CString &sValueName, bool &valueOut ) { valueOut = GetMetricB( sClassName, sValueName ); } void GetMetric( const CString &sClassName, const CString &sValueName, float &valueOut ) { valueOut = GetMetricF( sClassName, sValueName ); }
void GetMetric( const CString &sClassName, const CString &sValueName, RageColor &valueOut ) { valueOut = GetMetricC( sClassName, sValueName ); } void GetMetric( const CString &sClassName, const CString &sValueName, bool &valueOut ) { valueOut = GetMetricB( sClassName, sValueName ); }
void GetMetric( const CString &sClassName, const CString &sValueName, ActorCommands &valueOut ){ valueOut = GetMetricA( sClassName, sValueName ); } void GetMetric( const CString &sClassName, const CString &sValueName, RageColor &valueOut ) { valueOut = GetMetricC( sClassName, sValueName ); }
void GetMetric( const CString &sClassName, const CString &sValueName, ActorCommands &valueOut );
// //
// For self-registering metrics // For self-registering metrics