Moved lua music logic to a separate function so that ScreenSelectMusic can use lua for the various kinds of sample music.
This commit is contained in:
@@ -4,6 +4,15 @@ The StepMania 5 Changelog covers all post-sm-ssc changes. For a list of changes
|
||||
from StepMania 4 alpha 5 to sm-ssc v1.2.5, see Changelog_sm-ssc.txt.
|
||||
________________________________________________________________________________
|
||||
|
||||
2015/11/08
|
||||
----------
|
||||
* [ScreenSelectMusic] Using lua music files for the section music and similar
|
||||
things works now. [kyzentun]
|
||||
|
||||
================================================================================
|
||||
StepMania 5.0.10 | 20151031
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
2015/10/29
|
||||
----------
|
||||
* [Language] French translation updated. [Arvaneth]
|
||||
|
||||
@@ -379,7 +379,7 @@ void ScreenSelectMusic::CheckBackgroundRequests( bool bForce )
|
||||
g_bSampleMusicWaiting = false;
|
||||
|
||||
GameSoundManager::PlayMusicParams PlayParams;
|
||||
PlayParams.sFile = m_sSampleMusicToPlay;
|
||||
PlayParams.sFile = HandleLuaMusicFile(m_sSampleMusicToPlay);
|
||||
PlayParams.pTiming = m_pSampleMusicTimingData;
|
||||
PlayParams.bForceLoop = SAMPLE_MUSIC_LOOPS;
|
||||
PlayParams.fStartSecond = m_fSampleStartSeconds;
|
||||
@@ -1859,6 +1859,11 @@ void ScreenSelectMusic::AfterMusicChange()
|
||||
case SampleMusicPreviewMode_LastSong: // fall through
|
||||
// play the sample music
|
||||
m_sSampleMusicToPlay = pSong->GetPreviewMusicPath();
|
||||
if(ActorUtil::GetFileType(m_sSampleMusicToPlay) != FT_Sound)
|
||||
{
|
||||
LuaHelpers::ReportScriptErrorFmt("Music file %s for song is not a sound file, ignoring.", m_sSampleMusicToPlay.c_str());
|
||||
m_sSampleMusicToPlay= "";
|
||||
}
|
||||
m_pSampleMusicTimingData = &pSong->m_SongTiming;
|
||||
m_fSampleStartSeconds = pSong->GetPreviewStartSeconds();
|
||||
m_fSampleLengthSeconds = pSong->m_fMusicSampleLengthSeconds;
|
||||
|
||||
@@ -178,74 +178,72 @@ void ScreenWithMenuElements::SetHelpText( RString s )
|
||||
this->HandleMessage( msg );
|
||||
}
|
||||
|
||||
RString ScreenWithMenuElements::HandleLuaMusicFile(RString const& path)
|
||||
{
|
||||
FileType ft= ActorUtil::GetFileType(path);
|
||||
RString ret= path;
|
||||
if(ft == FT_Lua)
|
||||
{
|
||||
RString script;
|
||||
RString error= "Lua runtime error: ";
|
||||
if(GetFileContents(path, script))
|
||||
{
|
||||
Lua* L= LUA->Get();
|
||||
if(!LuaHelpers::RunScript(L, script, "@"+path, error, 0, 1, true))
|
||||
{
|
||||
ret= "";
|
||||
}
|
||||
else
|
||||
{
|
||||
// there are two possible ways to load a music file via Lua.
|
||||
// 1) return the path to the sound
|
||||
// (themer has to use THEME:GetPathS())
|
||||
RString music_path_from_lua;
|
||||
LuaHelpers::Pop(L, music_path_from_lua);
|
||||
if(!music_path_from_lua.empty())
|
||||
{
|
||||
ret= music_path_from_lua;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 2) perhaps it's a table with some params? unsure if I want to support
|
||||
// this just yet. -aj
|
||||
LOG->Trace("Lua music script did not return a path to a sound.");
|
||||
ret= "";
|
||||
}
|
||||
}
|
||||
LUA->Release(L);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG->Trace("run script failed hardcore, lol");
|
||||
ret= "";
|
||||
}
|
||||
}
|
||||
else if(ft != FT_Sound)
|
||||
{
|
||||
LuaHelpers::ReportScriptErrorFmt("Music file %s is not a sound file.", path.c_str());
|
||||
ret= "";
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void ScreenWithMenuElements::StartPlayingMusic()
|
||||
{
|
||||
/* Some screens should leave the music alone (eg. ScreenPlayerOptions music
|
||||
/* Some screens should leave the music alone (eg. ScreenPlayerOptions music
|
||||
* sample left over from ScreenSelectMusic). */
|
||||
if( PLAY_MUSIC )
|
||||
{
|
||||
GameSoundManager::PlayMusicParams pmp;
|
||||
FileType ft = ActorUtil::GetFileType( m_sPathToMusic );
|
||||
/* If m_sPathToMusic points to a Lua file, parse it and make sure it
|
||||
* returns a string pointing to a sound. Otherwise, if it points to
|
||||
* a normal music file, use the normal playback code. -aj
|
||||
* TODO: Make Lua music files accept playback params.
|
||||
*/
|
||||
if( ft == FT_Lua )
|
||||
pmp.sFile= HandleLuaMusicFile(m_sPathToMusic);
|
||||
if(!pmp.sFile.empty())
|
||||
{
|
||||
RString Script;
|
||||
RString Error= "Lua runtime error: ";
|
||||
if( GetFileContents(m_sPathToMusic, Script) )
|
||||
{
|
||||
Lua *L = LUA->Get();
|
||||
|
||||
if( !LuaHelpers::RunScript(L, Script, "@"+m_sPathToMusic, Error, 0, 1, true) )
|
||||
{
|
||||
LUA->Release( L );
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
// there are two possible ways to load a music file via Lua.
|
||||
// 1) return the path to the sound
|
||||
// (themer has to use THEME:GetPathS())
|
||||
RString sMusicPathFromLua;
|
||||
LuaHelpers::Pop(L, sMusicPathFromLua);
|
||||
|
||||
if( !sMusicPathFromLua.empty() )
|
||||
{
|
||||
pmp.sFile = sMusicPathFromLua;
|
||||
pmp.bAlignBeat = MUSIC_ALIGN_BEAT;
|
||||
|
||||
// TODO: load other params into pmp here -aj
|
||||
if( DELAY_MUSIC_SECONDS > 0.0f )
|
||||
pmp.fStartSecond = -DELAY_MUSIC_SECONDS;
|
||||
|
||||
SOUND->PlayMusic( pmp );
|
||||
}
|
||||
else
|
||||
{
|
||||
// 2) perhaps it's a table with some params? unsure if I want to support
|
||||
// this just yet. -aj
|
||||
LOG->Trace("Lua music script did not return a path to a sound.");
|
||||
}
|
||||
LUA->Release( L );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG->Trace("run script failed hardcore, lol");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
pmp.sFile = m_sPathToMusic;
|
||||
pmp.bAlignBeat = MUSIC_ALIGN_BEAT;
|
||||
|
||||
if( DELAY_MUSIC_SECONDS > 0.0f )
|
||||
if(DELAY_MUSIC_SECONDS > 0.0f)
|
||||
{
|
||||
pmp.fStartSecond = -DELAY_MUSIC_SECONDS;
|
||||
|
||||
SOUND->PlayMusic( pmp );
|
||||
}
|
||||
SOUND->PlayMusic(pmp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ public:
|
||||
bool m_bShouldAllowLateJoin; // So that it can be exposed to Lua.
|
||||
|
||||
protected:
|
||||
RString HandleLuaMusicFile(RString const& path);
|
||||
virtual void StartPlayingMusic();
|
||||
void SetHelpText( RString s );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user