2011-03-17 01:47:30 -04:00
|
|
|
#include "global.h"
|
|
|
|
|
#include "SongOptions.h"
|
|
|
|
|
#include "RageUtil.h"
|
|
|
|
|
#include "GameState.h"
|
|
|
|
|
#include "CommonMetrics.h"
|
|
|
|
|
|
2023-04-19 14:22:59 +02:00
|
|
|
#include <cmath>
|
|
|
|
|
|
2014-05-03 19:27:32 -06:00
|
|
|
static const char *AutosyncTypeNames[] = {
|
|
|
|
|
"Off",
|
|
|
|
|
"Song",
|
|
|
|
|
"Machine",
|
|
|
|
|
"Tempo",
|
|
|
|
|
};
|
|
|
|
|
XToString( AutosyncType );
|
|
|
|
|
XToLocalizedString( AutosyncType );
|
|
|
|
|
LuaXType( AutosyncType );
|
|
|
|
|
|
|
|
|
|
static const char *SoundEffectTypeNames[] = {
|
|
|
|
|
"Off",
|
|
|
|
|
"Speed",
|
|
|
|
|
"Pitch",
|
|
|
|
|
};
|
|
|
|
|
XToString( SoundEffectType );
|
|
|
|
|
XToLocalizedString( SoundEffectType );
|
|
|
|
|
LuaXType( SoundEffectType );
|
|
|
|
|
|
2011-03-17 01:47:30 -04:00
|
|
|
void SongOptions::Approach( const SongOptions& other, float fDeltaSeconds )
|
|
|
|
|
{
|
|
|
|
|
#define APPROACH( opt ) \
|
|
|
|
|
fapproach( m_ ## opt, other.m_ ## opt, fDeltaSeconds * other.m_Speed ## opt );
|
|
|
|
|
#define DO_COPY( x ) \
|
|
|
|
|
x = other.x;
|
|
|
|
|
|
|
|
|
|
APPROACH( fMusicRate );
|
|
|
|
|
APPROACH( fHaste );
|
|
|
|
|
DO_COPY( m_bAssistClap );
|
|
|
|
|
DO_COPY( m_bAssistMetronome );
|
|
|
|
|
DO_COPY( m_AutosyncType );
|
|
|
|
|
DO_COPY( m_SoundEffectType );
|
|
|
|
|
DO_COPY( m_bStaticBackground );
|
|
|
|
|
DO_COPY( m_bRandomBGOnly );
|
|
|
|
|
DO_COPY( m_bSaveScore );
|
|
|
|
|
DO_COPY( m_bSaveReplay );
|
|
|
|
|
#undef APPROACH
|
|
|
|
|
#undef DO_COPY
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-10 18:28:56 +03:00
|
|
|
static void AddPart( std::vector<RString> &AddTo, float level, RString name )
|
2011-03-17 01:47:30 -04:00
|
|
|
{
|
|
|
|
|
if( level == 0 )
|
|
|
|
|
return;
|
|
|
|
|
|
2023-04-19 14:22:59 +02:00
|
|
|
const RString LevelStr = (level == 1)? RString(""): ssprintf( "%ld%% ", std::lrint(level*100) );
|
2011-03-17 01:47:30 -04:00
|
|
|
|
|
|
|
|
AddTo.push_back( LevelStr + name );
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-10 18:28:56 +03:00
|
|
|
void SongOptions::GetMods( std::vector<RString> &AddTo ) const
|
2011-03-17 01:47:30 -04:00
|
|
|
{
|
|
|
|
|
if( m_fMusicRate != 1 )
|
|
|
|
|
{
|
|
|
|
|
RString s = ssprintf( "%2.2f", m_fMusicRate );
|
|
|
|
|
if( s[s.size()-1] == '0' )
|
|
|
|
|
s.erase( s.size()-1 );
|
|
|
|
|
AddTo.push_back( s + "xMusic" );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AddPart( AddTo, m_fHaste, "Haste" );
|
|
|
|
|
|
|
|
|
|
switch( m_AutosyncType )
|
|
|
|
|
{
|
2014-05-03 19:27:32 -06:00
|
|
|
case AutosyncType_Off: break;
|
|
|
|
|
case AutosyncType_Song: AddTo.push_back("AutosyncSong"); break;
|
|
|
|
|
case AutosyncType_Machine: AddTo.push_back("AutosyncMachine"); break;
|
|
|
|
|
case AutosyncType_Tempo: AddTo.push_back("AutosyncTempo"); break;
|
2012-12-27 16:59:35 -05:00
|
|
|
default:
|
|
|
|
|
FAIL_M(ssprintf("Invalid autosync type: %i", m_AutosyncType));
|
2011-03-17 01:47:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch( m_SoundEffectType )
|
|
|
|
|
{
|
2014-05-03 19:27:32 -06:00
|
|
|
case SoundEffectType_Off: break;
|
|
|
|
|
case SoundEffectType_Speed: AddTo.push_back("EffectSpeed"); break;
|
|
|
|
|
case SoundEffectType_Pitch: AddTo.push_back("EffectPitch"); break;
|
2012-12-27 16:59:35 -05:00
|
|
|
default:
|
|
|
|
|
FAIL_M(ssprintf("Invalid sound effect type: %i", m_SoundEffectType));
|
2011-03-17 01:47:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( m_bAssistClap )
|
|
|
|
|
AddTo.push_back( "Clap" );
|
|
|
|
|
if( m_bAssistMetronome )
|
|
|
|
|
AddTo.push_back( "Metronome" );
|
|
|
|
|
|
|
|
|
|
if( m_bStaticBackground )
|
|
|
|
|
AddTo.push_back( "StaticBG" );
|
|
|
|
|
if( m_bRandomBGOnly )
|
|
|
|
|
AddTo.push_back( "RandomBG" );
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-10 18:28:56 +03:00
|
|
|
void SongOptions::GetLocalizedMods( std::vector<RString> &v ) const
|
2011-03-17 01:47:30 -04:00
|
|
|
{
|
|
|
|
|
GetMods( v );
|
2019-06-22 12:35:38 -07:00
|
|
|
for (RString &s : v)
|
2011-03-17 01:47:30 -04:00
|
|
|
{
|
2019-06-22 12:35:38 -07:00
|
|
|
s = CommonMetrics::LocalizeOptionItem( s, true );
|
2011-03-17 01:47:30 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RString SongOptions::GetString() const
|
|
|
|
|
{
|
2022-07-10 18:28:56 +03:00
|
|
|
std::vector<RString> v;
|
2011-03-17 01:47:30 -04:00
|
|
|
GetMods( v );
|
|
|
|
|
return join( ", ", v );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RString SongOptions::GetLocalizedString() const
|
|
|
|
|
{
|
2022-07-10 18:28:56 +03:00
|
|
|
std::vector<RString> v;
|
2011-03-17 01:47:30 -04:00
|
|
|
GetLocalizedMods( v );
|
|
|
|
|
return join( ", ", v );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Options are added to the current settings; call Init() beforehand if
|
|
|
|
|
* you don't want this. */
|
|
|
|
|
void SongOptions::FromString( const RString &sMultipleMods )
|
|
|
|
|
{
|
|
|
|
|
RString sTemp = sMultipleMods;
|
2022-07-10 18:28:56 +03:00
|
|
|
std::vector<RString> vs;
|
2011-03-17 01:47:30 -04:00
|
|
|
split( sTemp, ",", vs, true );
|
|
|
|
|
RString sThrowAway;
|
2019-06-22 12:35:38 -07:00
|
|
|
for (RString &s : vs)
|
2011-03-17 01:47:30 -04:00
|
|
|
{
|
2019-06-22 12:35:38 -07:00
|
|
|
FromOneModString( s, sThrowAway );
|
2011-03-17 01:47:30 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool SongOptions::FromOneModString( const RString &sOneMod, RString &sErrorOut )
|
|
|
|
|
{
|
|
|
|
|
RString sBit = sOneMod;
|
|
|
|
|
sBit.MakeLower();
|
|
|
|
|
Trim( sBit );
|
|
|
|
|
|
|
|
|
|
Regex mult("^([0-9]+(\\.[0-9]+)?)xmusic$");
|
2022-07-10 18:28:56 +03:00
|
|
|
std::vector<RString> matches;
|
2011-03-17 01:47:30 -04:00
|
|
|
if( mult.Compare(sBit, matches) )
|
|
|
|
|
{
|
|
|
|
|
m_fMusicRate = StringToFloat( matches[0] );
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
matches.clear();
|
|
|
|
|
|
2022-07-10 18:28:56 +03:00
|
|
|
std::vector<RString> asParts;
|
2011-03-17 01:47:30 -04:00
|
|
|
split( sBit, " ", asParts, true );
|
|
|
|
|
bool on = true;
|
|
|
|
|
if( asParts.size() > 1 )
|
|
|
|
|
{
|
|
|
|
|
sBit = asParts[1];
|
|
|
|
|
if( asParts[0] == "no" )
|
|
|
|
|
on = false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-06 23:26:05 -06:00
|
|
|
if( sBit == "clap" ) m_bAssistClap = on;
|
2011-03-17 01:47:30 -04:00
|
|
|
else if( sBit == "metronome" ) m_bAssistMetronome = on;
|
2014-05-03 19:27:32 -06:00
|
|
|
else if( sBit == "autosync" || sBit == "autosyncsong" ) m_AutosyncType = on ? AutosyncType_Song : AutosyncType_Off;
|
2023-04-19 14:22:59 +02:00
|
|
|
else if( sBit == "autosyncmachine" ) m_AutosyncType = on ? AutosyncType_Machine : AutosyncType_Off;
|
2014-05-03 19:27:32 -06:00
|
|
|
else if( sBit == "autosynctempo" ) m_AutosyncType = on ? AutosyncType_Tempo : AutosyncType_Off;
|
|
|
|
|
else if( sBit == "effect" && !on ) m_SoundEffectType = SoundEffectType_Off;
|
|
|
|
|
else if( sBit == "effectspeed" ) m_SoundEffectType = on ? SoundEffectType_Speed : SoundEffectType_Off;
|
|
|
|
|
else if( sBit == "effectpitch" ) m_SoundEffectType = on ? SoundEffectType_Pitch : SoundEffectType_Off;
|
2011-03-17 01:47:30 -04:00
|
|
|
else if( sBit == "staticbg" ) m_bStaticBackground = on;
|
|
|
|
|
else if( sBit == "randombg" ) m_bRandomBGOnly = on;
|
|
|
|
|
else if( sBit == "savescore" ) m_bSaveScore = on;
|
|
|
|
|
else if( sBit == "savereplay" ) m_bSaveReplay = on;
|
|
|
|
|
else if( sBit == "haste" ) m_fHaste = on? 1.0f:0.0f;
|
|
|
|
|
else
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool SongOptions::operator==( const SongOptions &other ) const
|
|
|
|
|
{
|
|
|
|
|
#define COMPARE(x) { if( x != other.x ) return false; }
|
|
|
|
|
COMPARE( m_fMusicRate );
|
|
|
|
|
COMPARE( m_fHaste );
|
|
|
|
|
COMPARE( m_bAssistClap );
|
|
|
|
|
COMPARE( m_bAssistMetronome );
|
|
|
|
|
COMPARE( m_AutosyncType );
|
|
|
|
|
COMPARE( m_SoundEffectType );
|
|
|
|
|
COMPARE( m_bStaticBackground );
|
|
|
|
|
COMPARE( m_bRandomBGOnly );
|
|
|
|
|
COMPARE( m_bSaveScore );
|
|
|
|
|
COMPARE( m_bSaveReplay );
|
|
|
|
|
#undef COMPARE
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-03 19:27:32 -06:00
|
|
|
// lua start
|
|
|
|
|
#include "LuaBinding.h"
|
|
|
|
|
#include "OptionsBinding.h"
|
|
|
|
|
|
|
|
|
|
/** @brief Allow Lua to have access to SongOptions. */
|
|
|
|
|
class LunaSongOptions: public Luna<SongOptions>
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
ENUM_INTERFACE(AutosyncSetting, AutosyncType, AutosyncType);
|
|
|
|
|
//ENUM_INTERFACE(SoundEffectSetting, SoundEffectType, SoundEffectType);
|
|
|
|
|
// Broken, SoundEffectType_Speed disables rate mod, other settings have no effect. -Kyz
|
|
|
|
|
BOOL_INTERFACE(AssistClap, AssistClap);
|
|
|
|
|
BOOL_INTERFACE(AssistMetronome, AssistMetronome);
|
|
|
|
|
BOOL_INTERFACE(StaticBackground, StaticBackground);
|
|
|
|
|
BOOL_INTERFACE(RandomBGOnly, RandomBGOnly);
|
|
|
|
|
BOOL_INTERFACE(SaveScore, SaveScore);
|
|
|
|
|
BOOL_INTERFACE(SaveReplay, SaveReplay);
|
|
|
|
|
FLOAT_INTERFACE(MusicRate, MusicRate, (v > 0.0f && v <= 3.0f)); // Greater than 3 seems to crash frequently, haven't investigated why. -Kyz
|
2014-05-05 14:16:08 -06:00
|
|
|
FLOAT_INTERFACE(Haste, Haste, (v >= -1.0f && v <= 1.0f));
|
2014-05-03 19:27:32 -06:00
|
|
|
|
|
|
|
|
LunaSongOptions()
|
|
|
|
|
{
|
|
|
|
|
ADD_METHOD(AutosyncSetting);
|
|
|
|
|
//ADD_METHOD(SoundEffectSetting);
|
|
|
|
|
ADD_METHOD(AssistClap);
|
|
|
|
|
ADD_METHOD(AssistMetronome);
|
|
|
|
|
ADD_METHOD(StaticBackground);
|
|
|
|
|
ADD_METHOD(RandomBGOnly);
|
|
|
|
|
ADD_METHOD(SaveScore);
|
|
|
|
|
ADD_METHOD(SaveReplay);
|
|
|
|
|
ADD_METHOD(MusicRate);
|
|
|
|
|
ADD_METHOD(Haste);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
LUA_REGISTER_CLASS( SongOptions )
|
|
|
|
|
// lua end
|
|
|
|
|
|
2011-03-17 01:47:30 -04:00
|
|
|
/*
|
|
|
|
|
* (c) 2001-2004 Chris Danford, Glenn Maynard
|
|
|
|
|
* All rights reserved.
|
2023-04-19 14:22:59 +02:00
|
|
|
*
|
2011-03-17 01:47:30 -04:00
|
|
|
* 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.
|
2023-04-19 14:22:59 +02:00
|
|
|
*
|
2011-03-17 01:47:30 -04:00
|
|
|
* 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.
|
|
|
|
|
*/
|