move validation into Preference
This commit is contained in:
@@ -49,17 +49,18 @@ template <class T, class BasicType=T>
|
|||||||
class Preference : public IPreference
|
class Preference : public IPreference
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Preference( const RString& sName, const T& defaultValue ):
|
Preference( const RString& sName, const T& defaultValue, void (pfnValidate)(T& val) = NULL ):
|
||||||
IPreference( sName ),
|
IPreference( sName ),
|
||||||
m_currentValue( defaultValue ),
|
m_currentValue( defaultValue ),
|
||||||
m_defaultValue( defaultValue )
|
m_defaultValue( defaultValue ),
|
||||||
|
m_pfnValidate( pfnValidate )
|
||||||
{
|
{
|
||||||
LoadDefault();
|
LoadDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
RString ToString() const { return PrefToString( (const BasicType &) m_currentValue ); }
|
RString ToString() const { return PrefToString( (const BasicType &) m_currentValue ); }
|
||||||
void FromString( const RString &s ) { PrefFromString( s, (BasicType &)m_currentValue ); }
|
void FromString( const RString &s ) { PrefFromString( s, (BasicType &)m_currentValue ); if(m_pfnValidate) m_pfnValidate(m_currentValue); }
|
||||||
void SetFromStack( lua_State *L ) { PrefSetFromStack( L, (BasicType &)m_currentValue ); }
|
void SetFromStack( lua_State *L ) { PrefSetFromStack( L, (BasicType &)m_currentValue ); if(m_pfnValidate) m_pfnValidate(m_currentValue); }
|
||||||
void PushValue( lua_State *L ) const { PrefPushValue( L, (BasicType &)m_currentValue ); }
|
void PushValue( lua_State *L ) const { PrefPushValue( L, (BasicType &)m_currentValue ); }
|
||||||
|
|
||||||
void LoadDefault()
|
void LoadDefault()
|
||||||
@@ -90,6 +91,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
T m_currentValue;
|
T m_currentValue;
|
||||||
T m_defaultValue;
|
T m_defaultValue;
|
||||||
|
void (*m_pfnValidate)(T& val);
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
|
|||||||
@@ -144,6 +144,23 @@ void TimeMeterSecondsChangeInit( size_t /*ScoreEvent*/ i, RString &sNameOut, flo
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ValidateDisplayAspectRatio( float &val )
|
||||||
|
{
|
||||||
|
if( val < 0 )
|
||||||
|
val = 4/3.f;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ValidateSongsPerPlay( int &val )
|
||||||
|
{
|
||||||
|
CLAMP(val,0,MAX_SONGS_PER_PLAY);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ValidateRandomBackgroundMode( PrefsManager::RandomBackgroundMode &val )
|
||||||
|
{
|
||||||
|
CLAMP((int&)val,0,PrefsManager::NUM_RandomBackgroundMode-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
PrefsManager::PrefsManager() :
|
PrefsManager::PrefsManager() :
|
||||||
m_sCurrentGame ( "CurrentGame", "" ),
|
m_sCurrentGame ( "CurrentGame", "" ),
|
||||||
|
|
||||||
@@ -154,7 +171,7 @@ PrefsManager::PrefsManager() :
|
|||||||
m_bWindowed ( "Windowed", TRUE_IF_DEBUG ),
|
m_bWindowed ( "Windowed", TRUE_IF_DEBUG ),
|
||||||
m_iDisplayWidth ( "DisplayWidth", 640 ),
|
m_iDisplayWidth ( "DisplayWidth", 640 ),
|
||||||
m_iDisplayHeight ( "DisplayHeight", 480 ),
|
m_iDisplayHeight ( "DisplayHeight", 480 ),
|
||||||
m_fDisplayAspectRatio ( "DisplayAspectRatio", 4/3.f ),
|
m_fDisplayAspectRatio ( "DisplayAspectRatio", 4/3.f, ValidateDisplayAspectRatio ),
|
||||||
m_iDisplayColorDepth ( "DisplayColorDepth", 16 ),
|
m_iDisplayColorDepth ( "DisplayColorDepth", 16 ),
|
||||||
m_iTextureColorDepth ( "TextureColorDepth", 16 ),
|
m_iTextureColorDepth ( "TextureColorDepth", 16 ),
|
||||||
m_iMovieColorDepth ( "MovieColorDepth", 16 ),
|
m_iMovieColorDepth ( "MovieColorDepth", 16 ),
|
||||||
@@ -165,7 +182,7 @@ PrefsManager::PrefsManager() :
|
|||||||
m_bShowBanners ( "ShowBanners", true ),
|
m_bShowBanners ( "ShowBanners", true ),
|
||||||
|
|
||||||
m_bSongBackgrounds ( "SongBackgrounds", true ),
|
m_bSongBackgrounds ( "SongBackgrounds", true ),
|
||||||
m_RandomBackgroundMode ( "RandomBackgroundMode", BGMODE_ANIMATIONS ),
|
m_RandomBackgroundMode ( "RandomBackgroundMode", BGMODE_ANIMATIONS, ValidateRandomBackgroundMode ),
|
||||||
m_iNumBackgrounds ( "NumBackgrounds", 8 ),
|
m_iNumBackgrounds ( "NumBackgrounds", 8 ),
|
||||||
m_fBGBrightness ( "BGBrightness", 0.8f ),
|
m_fBGBrightness ( "BGBrightness", 0.8f ),
|
||||||
m_bHiddenSongs ( "HiddenSongs", false ),
|
m_bHiddenSongs ( "HiddenSongs", false ),
|
||||||
@@ -222,7 +239,7 @@ PrefsManager::PrefsManager() :
|
|||||||
m_AllowW1 ( "AllowW1", ALLOW_W1_EVERYWHERE ),
|
m_AllowW1 ( "AllowW1", ALLOW_W1_EVERYWHERE ),
|
||||||
m_bEventMode ( "EventMode", false ),
|
m_bEventMode ( "EventMode", false ),
|
||||||
m_iCoinsPerCredit ( "CoinsPerCredit", 1 ),
|
m_iCoinsPerCredit ( "CoinsPerCredit", 1 ),
|
||||||
m_iSongsPerPlay ( "SongsPerPlay", 3 ),
|
m_iSongsPerPlay ( "SongsPerPlay", 3, ValidateSongsPerPlay ),
|
||||||
|
|
||||||
m_CoinMode ( "CoinMode", COIN_MODE_HOME ),
|
m_CoinMode ( "CoinMode", COIN_MODE_HOME ),
|
||||||
m_Premium ( "Premium", PREMIUM_NONE ),
|
m_Premium ( "Premium", PREMIUM_NONE ),
|
||||||
@@ -429,12 +446,6 @@ void PrefsManager::ReadPrefsFromIni( const IniFile &ini, const RString &sSection
|
|||||||
// pPref->FromString( sVal );
|
// pPref->FromString( sVal );
|
||||||
|
|
||||||
IPreference::ReadAllPrefsFromNode( ini.GetChild(sSection) );
|
IPreference::ReadAllPrefsFromNode( ini.GetChild(sSection) );
|
||||||
|
|
||||||
// validate
|
|
||||||
if( m_fDisplayAspectRatio < 0 )
|
|
||||||
m_fDisplayAspectRatio.Set( 4/3.f );
|
|
||||||
m_iSongsPerPlay.Set( clamp(m_iSongsPerPlay.Get(),0,MAX_SONGS_PER_PLAY) );
|
|
||||||
m_RandomBackgroundMode.Set( (RandomBackgroundMode)clamp((int)m_RandomBackgroundMode.Get(),0,(int)NUM_RandomBackgroundMode-1) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrefsManager::ReadGamePrefsFromIni( const RString &sIni )
|
void PrefsManager::ReadGamePrefsFromIni( const RString &sIni )
|
||||||
|
|||||||
Reference in New Issue
Block a user