3 #include "ThemeMetric.h"
4 #include "GameManager.h"
7 #include "LuaFunctions.h"
8 #define LuaXToString(X) \
9 LuaFunction( X##ToString, X##ToString( (X) IArg(1) ) );
11 #define LuaStringToX(X) \
12 LuaFunction( StringTo##X, (X) StringTo##X( SArg(1) ) );
14 const CString RANKING_TO_FILL_IN_MARKER
[NUM_PLAYERS
] = {"#P1#","#P2#"};
16 static const CString RadarCategoryNames
[] = {
29 XToString( RadarCategory
, NUM_RADAR_CATEGORIES
);
30 XToThemedString( RadarCategory
, NUM_RADAR_CATEGORIES
);
32 static void LuaRadarCategory(lua_State
* L
)
34 FOREACH_RadarCategory( rc
)
36 CString s
= RadarCategoryNames
[rc
];
38 LUA
->SetGlobal( "RADAR_CATEGORY_"+s
, rc
);
41 REGISTER_WITH_LUA_FUNCTION( LuaRadarCategory
);
43 static void LuaStepsType(lua_State
* L
)
45 FOREACH_StepsType( st
)
47 CString s
= GAMEMAN
->StepsTypeToString( st
);
50 LUA
->SetGlobal( "STEPS_TYPE_"+s
, st
);
53 REGISTER_WITH_LUA_FUNCTION( LuaStepsType
);
56 static const CString PlayModeNames
[] = {
64 XToString( PlayMode
, NUM_PLAY_MODES
);
65 XToThemedString( PlayMode
, NUM_PLAY_MODES
);
66 StringToX( PlayMode
);
67 LuaXToString( PlayMode
);
68 static void LuaPlayMode(lua_State
* L
)
70 FOREACH_PlayMode( pm
)
72 CString s
= PlayModeNames
[pm
];
74 LUA
->SetGlobal( "PLAY_MODE_"+s
, pm
);
76 LUA
->SetGlobal( "NUM_PLAY_MODES", NUM_PLAY_MODES
);
78 REGISTER_WITH_LUA_FUNCTION( LuaPlayMode
);
81 RankingCategory
AverageMeterToRankingCategory( int iAverageMeter
)
83 if( iAverageMeter
<= 3 ) return RANKING_A
;
84 else if( iAverageMeter
<= 6 ) return RANKING_B
;
85 else if( iAverageMeter
<= 9 ) return RANKING_C
;
86 else return RANKING_D
;
90 static const CString RankingCategoryNames
[] = {
96 XToString( RankingCategory
, NUM_RANKING_CATEGORIES
);
97 StringToX( RankingCategory
);
100 static const CString PlayerControllerNames
[] = {
105 XToString( PlayerController
, NUM_PLAYER_CONTROLLERS
);
108 static const CString CoinModeNames
[] = {
113 XToString( CoinMode
, NUM_COIN_MODES
);
114 static void LuaCoinMode(lua_State
* L
)
116 FOREACH_CoinMode( i
)
118 CString s
= CoinModeNames
[i
];
120 LUA
->SetGlobal( "COIN_MODE_"+s
, i
);
123 REGISTER_WITH_LUA_FUNCTION( LuaCoinMode
);
126 static const CString PremiumNames
[] = {
131 XToString( Premium
, NUM_PREMIUMS
);
132 static void LuaPremium(lua_State
* L
)
136 CString s
= PremiumNames
[i
];
138 LUA
->SetGlobal( "PREMIUM_"+s
, i
);
141 REGISTER_WITH_LUA_FUNCTION( LuaPremium
);
144 static const CString SortOrderNames
[] = {
166 XToString( SortOrder
, NUM_SORT_ORDERS
);
167 StringToX( SortOrder
);
169 static void LuaSortOrder(lua_State
* L
)
171 FOREACH_SortOrder( so
)
173 CString s
= SortOrderToString( so
);
175 // [uppercase] -> _[uppercase]
176 for( unsigned i
=0; i
<s
.size(); i
++ )
180 s
.insert( s
.begin()+i
, '_' );
186 LUA
->SetGlobal( "SORT"+s
, so
);
189 REGISTER_WITH_LUA_FUNCTION( LuaSortOrder
);
192 static const CString TapNoteScoreNames
[] = {
203 XToString( TapNoteScore
, NUM_TAP_NOTE_SCORES
);
204 StringToX( TapNoteScore
);
205 XToThemedString( TapNoteScore
, NUM_TAP_NOTE_SCORES
);
206 static void LuaTapNoteScores( lua_State
* L
)
208 FOREACH_TapNoteScore( i
)
210 CString s
= TapNoteScoreNames
[i
];
212 LUA
->SetGlobal( "TNS_"+s
, i
);
215 REGISTER_WITH_LUA_FUNCTION( LuaTapNoteScores
);
218 static const CString HoldNoteScoreNames
[] = {
223 XToString( HoldNoteScore
, NUM_HOLD_NOTE_SCORES
);
224 StringToX( HoldNoteScore
);
225 XToThemedString( HoldNoteScore
, NUM_HOLD_NOTE_SCORES
);
226 static void LuaHoldNoteScores( lua_State
* L
)
228 FOREACH_HoldNoteScore( i
)
230 CString s
= HoldNoteScoreNames
[i
];
232 LUA
->SetGlobal( "HNS_"+s
, i
);
235 REGISTER_WITH_LUA_FUNCTION( LuaHoldNoteScores
);
238 static const CString MemoryCardStateNames
[] = {
246 XToString( MemoryCardState
, NUM_MEMORY_CARD_STATES
);
249 static const CString PerDifficultyAwardNames
[] = {
254 "SingleDigitPerfects",
256 "FullComboMarvelouses",
261 XToString( PerDifficultyAward
, NUM_PER_DIFFICULTY_AWARDS
);
262 XToThemedString( PerDifficultyAward
, NUM_PER_DIFFICULTY_AWARDS
);
263 StringToX( PerDifficultyAward
);
266 // Numbers are intentially not at the front of these strings so that the
267 // strings can be used as XML entity names.
268 // Numbers are intentially not at the back so that "1000" and "10000" don't
269 // conflict when searching for theme elements.
270 static const CString PeakComboAwardNames
[] = {
282 XToString( PeakComboAward
, NUM_PEAK_COMBO_AWARDS
);
283 XToThemedString( PeakComboAward
, NUM_PEAK_COMBO_AWARDS
);
284 StringToX( PeakComboAward
);
287 LuaXToString( Difficulty
);
288 LuaStringToX( Difficulty
);
291 void DisplayBpms
::Add( float f
)
293 vfBpms
.push_back( f
);
296 float DisplayBpms
::GetMin() const
298 float fMin
= FLT_MAX
;
299 FOREACH_CONST( float, vfBpms
, f
)
302 fMin
= min( fMin
, *f
);
304 if( fMin
== FLT_MAX
)
310 float DisplayBpms
::GetMax() const
313 FOREACH_CONST( float, vfBpms
, f
)
316 fMax
= max( fMax
, *f
);
321 bool DisplayBpms
::BpmIsConstant() const
323 return fabsf( GetMin() - GetMax() ) < 0.001f
;
326 bool DisplayBpms
::IsSecret() const
328 FOREACH_CONST( float, vfBpms
, f
)
336 static const CString StyleTypeNames
[] = {
338 "TwoPlayersTwoSides",
341 XToString( StyleType
, NUM_STYLE_TYPES
);
342 StringToX( StyleType
);
345 static const CString MenuDirNames
[] = {
352 XToString( MenuDir
, NUM_MENU_DIRS
);
355 static const CString GoalTypeNames
[] = {
360 XToString( GoalType
, NUM_GOAL_TYPES
);
361 StringToX( GoalType
);
362 static void LuaGoalType(lua_State
* L
)
364 FOREACH_GoalType( gt
)
366 CString s
= GoalTypeNames
[gt
];
368 LUA
->SetGlobal( "GOAL_"+s
, gt
);
371 REGISTER_WITH_LUA_FUNCTION( LuaGoalType
);
374 static const CString StageNames
[] = {
390 XToString( Stage
, NUM_STAGES
);
393 * (c) 2001-2004 Chris Danford
394 * All rights reserved.
396 * Permission is hereby granted, free of charge, to any person obtaining a
397 * copy of this software and associated documentation files (the
398 * "Software"), to deal in the Software without restriction, including
399 * without limitation the rights to use, copy, modify, merge, publish,
400 * distribute, and/or sell copies of the Software, and to permit persons to
401 * whom the Software is furnished to do so, provided that the above
402 * copyright notice(s) and this permission notice appear in all copies of
403 * the Software and that both the above copyright notice(s) and this
404 * permission notice appear in supporting documentation.
406 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
407 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
408 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
409 * THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
410 * INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
411 * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
412 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
413 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
414 * PERFORMANCE OF THIS SOFTWARE.