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.
|
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
|
2015/10/29
|
||||||
----------
|
----------
|
||||||
* [Language] French translation updated. [Arvaneth]
|
* [Language] French translation updated. [Arvaneth]
|
||||||
|
|||||||
@@ -379,7 +379,7 @@ void ScreenSelectMusic::CheckBackgroundRequests( bool bForce )
|
|||||||
g_bSampleMusicWaiting = false;
|
g_bSampleMusicWaiting = false;
|
||||||
|
|
||||||
GameSoundManager::PlayMusicParams PlayParams;
|
GameSoundManager::PlayMusicParams PlayParams;
|
||||||
PlayParams.sFile = m_sSampleMusicToPlay;
|
PlayParams.sFile = HandleLuaMusicFile(m_sSampleMusicToPlay);
|
||||||
PlayParams.pTiming = m_pSampleMusicTimingData;
|
PlayParams.pTiming = m_pSampleMusicTimingData;
|
||||||
PlayParams.bForceLoop = SAMPLE_MUSIC_LOOPS;
|
PlayParams.bForceLoop = SAMPLE_MUSIC_LOOPS;
|
||||||
PlayParams.fStartSecond = m_fSampleStartSeconds;
|
PlayParams.fStartSecond = m_fSampleStartSeconds;
|
||||||
@@ -1859,6 +1859,11 @@ void ScreenSelectMusic::AfterMusicChange()
|
|||||||
case SampleMusicPreviewMode_LastSong: // fall through
|
case SampleMusicPreviewMode_LastSong: // fall through
|
||||||
// play the sample music
|
// play the sample music
|
||||||
m_sSampleMusicToPlay = pSong->GetPreviewMusicPath();
|
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_pSampleMusicTimingData = &pSong->m_SongTiming;
|
||||||
m_fSampleStartSeconds = pSong->GetPreviewStartSeconds();
|
m_fSampleStartSeconds = pSong->GetPreviewStartSeconds();
|
||||||
m_fSampleLengthSeconds = pSong->m_fMusicSampleLengthSeconds;
|
m_fSampleLengthSeconds = pSong->m_fMusicSampleLengthSeconds;
|
||||||
|
|||||||
@@ -178,6 +178,56 @@ void ScreenWithMenuElements::SetHelpText( RString s )
|
|||||||
this->HandleMessage( msg );
|
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()
|
void ScreenWithMenuElements::StartPlayingMusic()
|
||||||
{
|
{
|
||||||
/* Some screens should leave the music alone (eg. ScreenPlayerOptions music
|
/* Some screens should leave the music alone (eg. ScreenPlayerOptions music
|
||||||
@@ -185,67 +235,15 @@ void ScreenWithMenuElements::StartPlayingMusic()
|
|||||||
if( PLAY_MUSIC )
|
if( PLAY_MUSIC )
|
||||||
{
|
{
|
||||||
GameSoundManager::PlayMusicParams pmp;
|
GameSoundManager::PlayMusicParams pmp;
|
||||||
FileType ft = ActorUtil::GetFileType( m_sPathToMusic );
|
pmp.sFile= HandleLuaMusicFile(m_sPathToMusic);
|
||||||
/* If m_sPathToMusic points to a Lua file, parse it and make sure it
|
if(!pmp.sFile.empty())
|
||||||
* 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 )
|
|
||||||
{
|
{
|
||||||
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;
|
pmp.bAlignBeat = MUSIC_ALIGN_BEAT;
|
||||||
|
if(DELAY_MUSIC_SECONDS > 0.0f)
|
||||||
if( DELAY_MUSIC_SECONDS > 0.0f )
|
{
|
||||||
pmp.fStartSecond = -DELAY_MUSIC_SECONDS;
|
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.
|
bool m_bShouldAllowLateJoin; // So that it can be exposed to Lua.
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
RString HandleLuaMusicFile(RString const& path);
|
||||||
virtual void StartPlayingMusic();
|
virtual void StartPlayingMusic();
|
||||||
void SetHelpText( RString s );
|
void SetHelpText( RString s );
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user