Files
itgmania212121/stepmania/src/Grade.cpp
T

92 lines
2.8 KiB
C++
Raw Normal View History

2003-02-16 04:01:45 +00:00
#include "global.h"
2002-01-16 10:01:32 +00:00
#include "Grade.h"
2004-01-20 03:32:48 +00:00
#include "RageUtil.h"
#include "ThemeManager.h"
2004-05-20 03:50:42 +00:00
#include "RageLog.h"
2005-03-31 02:06:24 +00:00
#include "EnumHelper.h"
#include "LuaManager.h"
#include "LuaFunctions.h"
2002-01-16 10:01:32 +00:00
2005-05-29 02:21:24 +00:00
LuaFunction( GradeToString, GradeToString((Grade)IArg(1)) )
2006-01-22 01:00:06 +00:00
RString GradeToLocalizedString( Grade g )
{
2006-01-22 01:00:06 +00:00
RString s = GradeToString(g);
2006-06-24 05:13:54 +00:00
if( !THEME->HasString("Grade",s) )
return "???";
2006-01-08 18:40:20 +00:00
return THEME->GetString( "Grade",s );
}
2006-01-22 01:00:06 +00:00
RString GradeToOldString( Grade g )
2004-01-20 07:09:44 +00:00
{
// string is meant to be human readable
switch( g )
{
case Grade_Tier01: return "AAAA";
case Grade_Tier02: return "AAA";
case Grade_Tier03: return "AA";
case Grade_Tier04: return "A";
case Grade_Tier05: return "B";
case Grade_Tier06: return "C";
case Grade_Tier07: return "D";
case Grade_Failed: return "E";
case Grade_NoData: return "N";
2006-09-15 04:40:27 +00:00
default: return "N";
2002-02-02 05:11:12 +00:00
}
};
2006-01-22 01:00:06 +00:00
Grade StringToGrade( const RString &sGrade )
2002-02-02 05:11:12 +00:00
{
2006-01-22 01:00:06 +00:00
RString s = sGrade;
2002-02-02 05:11:12 +00:00
s.MakeUpper();
2004-01-20 03:32:48 +00:00
// new style
int iTier;
2006-09-15 04:40:27 +00:00
if( sscanf(sGrade.c_str(),"TIER%02d",&iTier) == 1 && iTier >= 0 && iTier < NUM_Grade)
return (Grade)(iTier-1);
else if( s == "FAILED" )
return Grade_Failed;
else if( s == "NODATA" )
return Grade_NoData;
2004-05-20 03:50:42 +00:00
LOG->Warn( "Invalid grade: %s", sGrade.c_str() );
return Grade_NoData;
2002-02-02 05:11:12 +00:00
};
2006-09-15 04:40:27 +00:00
template<> void StringTo<Grade>( const RString& s, Grade &out ) { out = StringToGrade( s ); }
2004-01-20 03:32:48 +00:00
2005-03-31 02:06:24 +00:00
static void LuaGrade(lua_State* L)
{
FOREACH_Grade( g )
{
2006-01-22 01:00:06 +00:00
RString s = GradeToString(g);
LUA->SetGlobal( "Grade_"+s, g );
2005-03-31 02:06:24 +00:00
}
LUA->SetGlobal( "NUM_Grade", NUM_Grade );
2005-03-31 02:06:24 +00:00
}
REGISTER_WITH_LUA_FUNCTION( LuaGrade );
2004-05-31 22:42:12 +00:00
/*
* (c) 2001-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.
*/