From 124707961cf68fe947068bf533d039ffe4e427a9 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Thu, 30 Oct 2003 21:57:38 +0000 Subject: [PATCH] Move actor command parsing helpers into ActorUtil. --- stepmania/src/ActorUtil.cpp | 20 ++++++++++++++++++++ stepmania/src/ActorUtil.h | 16 ++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/stepmania/src/ActorUtil.cpp b/stepmania/src/ActorUtil.cpp index aec7216662..bbf0ecc4ac 100644 --- a/stepmania/src/ActorUtil.cpp +++ b/stepmania/src/ActorUtil.cpp @@ -18,6 +18,9 @@ #include "IniFile.h" #include "ThemeManager.h" #include "RageUtil_FileDB.h" +#include "RageDisplay.h" +#include "RageLog.h" +#include "arch/ArchHooks/ArchHooks.h" static Actor* LoadActor( CString sPath ) @@ -37,6 +40,15 @@ static Actor* LoadActor( CString sPath ) sNewPath = DerefRedir( sNewPath ); + /* XXX: How to handle translations? Maybe we should have one metrics section, + * "Text", eg: + * + * [Text] + * SoundVolume=Sound Volume + * TextItem=Hello + * + * and allow "$TextItem$" in .actors to reference that. + */ Actor* pActor = NULL; CString text; if( ini.GetValue ( "Actor", "Text", text ) ) @@ -107,3 +119,11 @@ Actor* MakeActor( CString sPath ) sPath.c_str(), sExt.c_str() ); } +void IncorrectActorParametersWarning( const CStringArray &asTokens, int iMaxIndexAccessed, int size ) +{ + const CString sError = ssprintf( "Actor::HandleCommand: Wrong number of parameters in command '%s'. Expected %d but there are %d.", + join(",",asTokens).c_str(), iMaxIndexAccessed+1, size ); + LOG->Warn( sError ); + if( DISPLAY->IsWindowed() ) + HOOKS->MessageBoxOK( sError ); +} diff --git a/stepmania/src/ActorUtil.h b/stepmania/src/ActorUtil.h index 6e9eac973d..475cd9d0f6 100644 --- a/stepmania/src/ActorUtil.h +++ b/stepmania/src/ActorUtil.h @@ -91,6 +91,22 @@ protected: }; +/* Actor command parsing helpers. */ +#define HandleParams int iMaxIndexAccessed = 0; +#define sParam(i) (GetParam(asTokens,i,iMaxIndexAccessed)) +#define fParam(i) ((float)atof(sParam(i))) +#define iParam(i) (atoi(sParam(i))) +#define bParam(i) (iParam(i)!=0) +#define CheckHandledParams if( iMaxIndexAccessed != (int)asTokens.size()-1 ) { IncorrectActorParametersWarning( asTokens, iMaxIndexAccessed, asTokens.size() ); } +void IncorrectActorParametersWarning( const CStringArray &asTokens, int iMaxIndexAccessed, int size ); +inline CString GetParam( const CStringArray& sParams, int iIndex, int& iMaxIndexAccessed ) +{ + iMaxIndexAccessed = max( iIndex, iMaxIndexAccessed ); + if( iIndex < int(sParams.size()) ) + return sParams[iIndex]; + else + return ""; +} #endif