fix legacy songs not showing background at end, but still allow new

songs to not have it
This commit is contained in:
Glenn Maynard
2004-09-13 08:00:34 +00:00
parent 70ed8fdfdc
commit 66b17e5ef2
5 changed files with 59 additions and 4 deletions
+1
View File
@@ -18,6 +18,7 @@ public:
const set<istring> &GetBlacklistedImages() const { return BlacklistedImages; }
static void GetMainAndSubTitlesFromFullTitle( const CString sFullTitle, CString &sMainTitleOut, CString &sSubTitleOut );
virtual bool LoadFromDir( CString sPath, Song &out ) = 0;
virtual void TidyUpData( Song &song, bool cache ) { }
bool Loadable( CString sPath );
};
+43
View File
@@ -470,6 +470,49 @@ bool SMLoader::LoadEdit( CString sEditFilePath, ProfileSlot slot )
}
void SMLoader::TidyUpData( Song &song, bool cache )
{
/*
* Hack: if the song has any changes at all (so it won't use a random BGA)
* and doesn't end with "-nosongbg-", add a song background BGC. Remove
* "-nosongbg-" if it exists.
*
* This way, songs that were created earlier, when we added the song BG
* at the end by default, will still behave as expected; all new songs will
* have to add an explicit song BG tag if they want it. This is really a
* formatting hack only; nothing outside of SMLoader ever sees "-nosongbg-".
*/
vector<BackgroundChange> &bg = song.m_BackgroundChanges;
if( !bg.empty() )
{
/* BGChanges have been sorted. On the odd chance that a BGChange exists
* with a very high beat, search the whole list. */
bool bHasNoSongBgTag = false;
for( unsigned i = 0; !bHasNoSongBgTag && i < bg.size(); ++i )
{
if( !bg[i].m_sBGName.CompareNoCase("-nosongbg-") )
{
bg.erase( bg.begin()+i );
bHasNoSongBgTag = true;
}
}
/*
* If we're loading cache, -nosongbg- should always be in there. We must
* not call IsAFile(song.GetBackgroundPath()) when loading cache.
*
* If BGChanges already exist after the last beat, don't add the background
* in the middle.
*/
if( !cache &&
bg.back().m_fStartBeat-0.0001f < song.m_fLastBeat &&
!bHasNoSongBgTag &&
IsAFile( song.GetBackgroundPath() ) )
bg.push_back( BackgroundChange(song.m_fLastBeat,song.m_sBackgroundFile) );
}
}
/*
* (c) 2001-2004 Chris Danford, Glenn Maynard
* All rights reserved.
+1
View File
@@ -34,6 +34,7 @@ public:
void GetApplicableFiles( CString sPath, CStringArray &out );
bool LoadFromDir( CString sPath, Song &out );
void TidyUpData( Song &song, bool cache );
static bool LoadTimingFromFile( const CString &fn, TimingData &out );
static void LoadTimingFromSMFile( const MsdFile &msd, TimingData &out );
static bool LoadEdit( CString sEditFilePath, ProfileSlot slot );
+7 -3
View File
@@ -85,10 +85,14 @@ void NotesWriterSM::WriteGlobalTags( RageFile &f, const Song &out )
{
const BackgroundChange &seg = out.m_BackgroundChanges[i];
f.PutLine( ssprintf( "%.3f=%s=%.3f=%d=%d=%d", seg.m_fStartBeat, seg.m_sBGName.c_str(), seg.m_fRate, seg.m_bFadeLast, seg.m_bRewindMovie, seg.m_bLoop ) );
if( i != out.m_BackgroundChanges.size()-1 )
f.Write( "," );
f.PutLine( ssprintf( "%.3f=%s=%.3f=%d=%d=%d,", seg.m_fStartBeat, seg.m_sBGName.c_str(), seg.m_fRate, seg.m_bFadeLast, seg.m_bRewindMovie, seg.m_bLoop ) );
}
/* If there's an animation plan at all, add a dummy "-nosongbg-" tag to indicate that
* this file doesn't want a song BG entry added at the end. See SMLoader::TidyUpData.
* This tag will be removed on load. Add it at a very high beat, so it won't cause
* problems if loaded in older versions. */
if( !out.m_BackgroundChanges.empty() )
f.PutLine( "99999=-nosongbg-=1.000=0=0=0 // don't automatically add -songbackground-" );
f.PutLine( ";" );
if( out.m_ForegroundChanges.size() )
+7 -1
View File
@@ -229,6 +229,7 @@ bool Song::LoadFromSongDir( CString sDir )
// LOG->Trace( "Loading '%s' from cache file '%s'.", m_sSongDir.c_str(), GetCacheFilePath().c_str() );
SMLoader ld;
ld.LoadFromSMFile( GetCacheFilePath(), *this, true );
ld.TidyUpData( *this, true );
}
else
{
@@ -246,12 +247,17 @@ bool Song::LoadFromSongDir( CString sDir )
bool success = ld->LoadFromDir( sDir, *this );
BlacklistedImages = ld->GetBlacklistedImages();
delete ld;
if(!success)
{
delete ld;
return false;
}
TidyUpData();
ld->TidyUpData( *this, false );
delete ld;
// save a cache file so we don't have to parse it all over again next time
SaveToCacheFile();