2003-02-16 04:01:45 +00:00
|
|
|
#include "global.h"
|
2002-08-01 13:42:56 +00:00
|
|
|
#include "SongOptions.h"
|
|
|
|
|
#include "RageUtil.h"
|
2004-07-31 23:58:53 +00:00
|
|
|
#include "PrefsManager.h"
|
2002-08-01 13:42:56 +00:00
|
|
|
|
2003-08-13 18:30:46 +00:00
|
|
|
void SongOptions::Init()
|
|
|
|
|
{
|
|
|
|
|
m_LifeType = LIFE_BAR;
|
|
|
|
|
m_DrainType = DRAIN_NORMAL;
|
|
|
|
|
m_iBatteryLives = 4;
|
2004-06-08 07:16:28 +00:00
|
|
|
m_FailType = FAIL_IMMEDIATE;
|
2003-08-13 18:30:46 +00:00
|
|
|
m_bAssistTick = false;
|
|
|
|
|
m_fMusicRate = 1.0f;
|
|
|
|
|
m_bAutoSync = false;
|
2003-09-04 21:24:50 +00:00
|
|
|
m_bSaveScore = true;
|
2003-08-13 18:30:46 +00:00
|
|
|
}
|
2002-08-01 13:42:56 +00:00
|
|
|
|
2003-09-29 05:01:41 +00:00
|
|
|
CString SongOptions::GetString() const
|
2002-08-01 13:42:56 +00:00
|
|
|
{
|
|
|
|
|
CString sReturn;
|
|
|
|
|
|
|
|
|
|
switch( m_LifeType )
|
|
|
|
|
{
|
|
|
|
|
case LIFE_BAR:
|
|
|
|
|
switch( m_DrainType )
|
|
|
|
|
{
|
|
|
|
|
case DRAIN_NORMAL: break;
|
|
|
|
|
case DRAIN_NO_RECOVER: sReturn += "NoRecover, "; break;
|
|
|
|
|
case DRAIN_SUDDEN_DEATH: sReturn += "SuddenDeath, "; break;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case LIFE_BATTERY:
|
|
|
|
|
sReturn += ssprintf( "%dLives, ", m_iBatteryLives );
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2003-02-12 23:11:37 +00:00
|
|
|
|
|
|
|
|
switch( m_FailType )
|
|
|
|
|
{
|
2004-07-31 19:14:53 +00:00
|
|
|
case FAIL_IMMEDIATE: break;
|
|
|
|
|
case FAIL_COMBO_OF_30_MISSES: sReturn += "Fail30Misses, "; break;
|
|
|
|
|
case FAIL_END_OF_SONG: sReturn += "FailEndOfSong, "; break;
|
|
|
|
|
case FAIL_OFF: sReturn += "FailOff, "; break;
|
2003-02-12 23:11:37 +00:00
|
|
|
}
|
|
|
|
|
|
2002-08-01 13:42:56 +00:00
|
|
|
if( m_fMusicRate != 1 )
|
|
|
|
|
{
|
2002-08-03 18:40:09 +00:00
|
|
|
CString s = ssprintf( "%2.2f", m_fMusicRate );
|
2002-08-01 13:42:56 +00:00
|
|
|
if( s[s.GetLength()-1] == '0' )
|
2003-01-03 05:29:45 +00:00
|
|
|
s.erase(s.GetLength()-1);
|
2002-08-03 18:40:09 +00:00
|
|
|
sReturn += s + "xMusic, ";
|
2002-08-01 13:42:56 +00:00
|
|
|
}
|
|
|
|
|
|
2003-01-11 08:55:21 +00:00
|
|
|
if( m_bAutoSync )
|
|
|
|
|
sReturn += "AutoSync, ";
|
2002-10-01 01:55:07 +00:00
|
|
|
|
2002-08-01 13:42:56 +00:00
|
|
|
if( sReturn.GetLength() > 2 )
|
2003-01-03 05:29:45 +00:00
|
|
|
sReturn.erase( sReturn.GetLength()-2 ); // delete the trailing ", "
|
2002-08-01 13:42:56 +00:00
|
|
|
return sReturn;
|
|
|
|
|
}
|
|
|
|
|
|
2003-02-22 21:56:59 +00:00
|
|
|
/* Options are added to the current settings; call Init() beforehand if
|
|
|
|
|
* you don't want this. */
|
2002-08-01 13:42:56 +00:00
|
|
|
void SongOptions::FromString( CString sOptions )
|
|
|
|
|
{
|
2003-02-22 21:56:59 +00:00
|
|
|
// Init();
|
2002-08-01 13:42:56 +00:00
|
|
|
sOptions.MakeLower();
|
|
|
|
|
CStringArray asBits;
|
|
|
|
|
split( sOptions, ",", asBits, true );
|
|
|
|
|
|
2002-10-31 03:16:02 +00:00
|
|
|
for( unsigned i=0; i<asBits.size(); i++ )
|
2002-08-01 13:42:56 +00:00
|
|
|
{
|
|
|
|
|
CString& sBit = asBits[i];
|
2002-10-31 08:05:13 +00:00
|
|
|
TrimLeft(sBit);
|
|
|
|
|
TrimRight(sBit);
|
2002-08-01 13:42:56 +00:00
|
|
|
|
2003-08-11 06:09:57 +00:00
|
|
|
Regex mult("^([0-9]+(\\.[0-9]+)?)xmusic$");
|
|
|
|
|
vector<CString> matches;
|
|
|
|
|
if( mult.Compare(sBit, matches) )
|
|
|
|
|
{
|
2004-08-10 22:19:06 +00:00
|
|
|
char *p = NULL;
|
|
|
|
|
m_fMusicRate = strtof( matches[0], &p );
|
|
|
|
|
ASSERT( p != matches[0] );
|
2003-08-11 06:09:57 +00:00
|
|
|
}
|
|
|
|
|
|
2003-09-29 06:22:13 +00:00
|
|
|
matches.clear();
|
|
|
|
|
Regex lives("^([0-9]+) ?(lives|life)$");
|
|
|
|
|
if( lives.Compare(sBit, matches) )
|
|
|
|
|
{
|
|
|
|
|
int ret = sscanf( matches[0], "%i", &m_iBatteryLives );
|
|
|
|
|
ASSERT( ret == 1 );
|
|
|
|
|
}
|
|
|
|
|
|
2003-09-27 07:30:54 +00:00
|
|
|
CStringArray asParts;
|
|
|
|
|
split( sBit, " ", asParts, true );
|
|
|
|
|
bool on = true;
|
|
|
|
|
if( asParts.size() > 1 )
|
|
|
|
|
{
|
|
|
|
|
sBit = asParts[1];
|
|
|
|
|
|
|
|
|
|
if( asParts[0] == "no" )
|
|
|
|
|
on = false;
|
|
|
|
|
}
|
|
|
|
|
|
2002-08-01 13:42:56 +00:00
|
|
|
if( sBit == "norecover" ) m_DrainType = DRAIN_NO_RECOVER;
|
|
|
|
|
else if( sBit == "suddendeath" ) m_DrainType = DRAIN_SUDDEN_DEATH;
|
|
|
|
|
else if( sBit == "power-drop" ) m_DrainType = DRAIN_NO_RECOVER;
|
|
|
|
|
else if( sBit == "death" ) m_DrainType = DRAIN_SUDDEN_DEATH;
|
2003-09-29 06:22:13 +00:00
|
|
|
else if( sBit == "normal-drain" ) m_DrainType = DRAIN_NORMAL;
|
2004-06-11 06:05:35 +00:00
|
|
|
else if( sBit == "failarcade" ||
|
|
|
|
|
sBit == "failimmediate" ) m_FailType = FAIL_IMMEDIATE;
|
2004-07-31 19:14:53 +00:00
|
|
|
else if( sBit == "fail30misses" ) m_FailType = FAIL_COMBO_OF_30_MISSES;
|
2003-04-01 19:31:27 +00:00
|
|
|
else if( sBit == "failendofsong" ) m_FailType = FAIL_END_OF_SONG;
|
|
|
|
|
else if( sBit == "failoff" ) m_FailType = FAIL_OFF;
|
2004-07-31 23:58:53 +00:00
|
|
|
|
|
|
|
|
else if( sBit == "faildefault" )
|
|
|
|
|
{
|
|
|
|
|
SongOptions so;
|
|
|
|
|
// TODO: Fix this so that SongOptions don't depend on PrefsManager
|
|
|
|
|
so.FromString( PREFSMAN->m_sDefaultModifiers );
|
|
|
|
|
m_FailType = so.m_FailType;
|
|
|
|
|
}
|
|
|
|
|
|
2003-09-27 07:30:54 +00:00
|
|
|
else if( sBit == "assisttick" ) m_bAssistTick = on;
|
|
|
|
|
else if( sBit == "autosync" ) m_bAutoSync = on;
|
|
|
|
|
else if( sBit == "savescore" ) m_bSaveScore = on;
|
2003-09-29 06:22:13 +00:00
|
|
|
else if( sBit == "bar" ) m_LifeType = LIFE_BAR;
|
|
|
|
|
else if( sBit == "battery" ) m_LifeType = LIFE_BATTERY;
|
2002-08-01 13:42:56 +00:00
|
|
|
}
|
|
|
|
|
}
|
2003-09-27 19:23:15 +00:00
|
|
|
|
2004-01-18 07:44:39 +00:00
|
|
|
bool SongOptions::operator==( const SongOptions &other ) const
|
2003-09-27 19:23:15 +00:00
|
|
|
{
|
2004-01-11 04:33:21 +00:00
|
|
|
#define COMPARE(x) { if( x != other.x ) return false; }
|
2003-09-27 19:23:15 +00:00
|
|
|
COMPARE( m_LifeType );
|
|
|
|
|
COMPARE( m_DrainType );
|
|
|
|
|
COMPARE( m_iBatteryLives );
|
|
|
|
|
COMPARE( m_FailType );
|
|
|
|
|
COMPARE( m_fMusicRate );
|
|
|
|
|
COMPARE( m_bAssistTick );
|
|
|
|
|
COMPARE( m_bAutoSync );
|
|
|
|
|
COMPARE( m_bSaveScore );
|
|
|
|
|
#undef COMPARE
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2004-05-31 21:35:31 +00:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* (c) 2001-2004 Chris Danford, Glenn Maynard
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|