Files
itgmania212121/src/NotesLoaderSSC.cpp
T

1189 lines
35 KiB
C++
Raw Normal View History

2011-02-10 23:35:34 -05:00
#include "global.h"
#include "NotesLoaderSSC.h"
#include "BackgroundUtil.h"
#include "GameManager.h"
#include "MsdFile.h" // No JSON here.
#include "NoteTypes.h"
2011-02-11 12:28:23 -05:00
#include "NotesLoaderSM.h" // For loading SM style edits.
2011-02-10 23:35:34 -05:00
#include "RageFileManager.h"
#include "RageLog.h"
#include "RageUtil.h"
#include "Song.h"
#include "SongManager.h"
#include "Steps.h"
#include "PrefsManager.h"
2011-02-12 13:57:06 -05:00
/**
* @brief A custom .edit file can only be so big before we have to reject it.
*/
2011-02-10 23:35:34 -05:00
const int MAX_EDIT_STEPS_SIZE_BYTES = 60*1024; // 60 KB
2011-02-12 13:57:06 -05:00
/**
* @brief Attempt to load any background changes in use by this song.
*
* This code is right now copied from NotesLoaderSM. There may be a time
* when we add to this code, or perhaps just refactor it properly.
* @param change a reference to the background change.
* @param sBGChangeExpression a reference to the list of changes to be made.
* @return its success or failure.
*/
2011-02-10 23:35:34 -05:00
bool LoadFromBGSSCChangesString( BackgroundChange &change, const RString &sBGChangeExpression )
{
vector<RString> aBGChangeValues;
split( sBGChangeExpression, "=", aBGChangeValues, false );
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
aBGChangeValues.resize( min((int)aBGChangeValues.size(),11) );
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
switch( aBGChangeValues.size() )
{
case 11:
change.m_def.m_sColor2 = aBGChangeValues[10];
change.m_def.m_sColor2.Replace( '^', ',' );
change.m_def.m_sColor2 = RageColor::NormalizeColorString( change.m_def.m_sColor2 );
// fall through
case 10:
change.m_def.m_sColor1 = aBGChangeValues[9];
change.m_def.m_sColor1.Replace( '^', ',' );
change.m_def.m_sColor1 = RageColor::NormalizeColorString( change.m_def.m_sColor1 );
// fall through
case 9:
change.m_sTransition = aBGChangeValues[8];
// fall through
case 8:
change.m_def.m_sFile2 = aBGChangeValues[7];
// fall through
case 7:
change.m_def.m_sEffect = aBGChangeValues[6];
// fall through
case 6:
// param 7 overrides this.
// Backward compatibility:
if( change.m_def.m_sEffect.empty() )
{
bool bLoop = atoi( aBGChangeValues[5] ) != 0;
if( !bLoop )
change.m_def.m_sEffect = SBE_StretchNoLoop;
}
// fall through
case 5:
// param 7 overrides this.
// Backward compatibility:
if( change.m_def.m_sEffect.empty() )
{
bool bRewindMovie = atoi( aBGChangeValues[4] ) != 0;
if( bRewindMovie )
change.m_def.m_sEffect = SBE_StretchRewind;
}
// fall through
case 4:
// param 9 overrides this.
// Backward compatibility:
if( change.m_sTransition.empty() )
change.m_sTransition = (atoi( aBGChangeValues[3] ) != 0) ? "CrossFade" : "";
// fall through
case 3:
change.m_fRate = StringToFloat( aBGChangeValues[2] );
// fall through
case 2:
change.m_def.m_sFile1 = aBGChangeValues[1];
// fall through
case 1:
change.m_fStartBeat = StringToFloat( aBGChangeValues[0] );
// fall through
}
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
return aBGChangeValues.size() >= 2;
}
bool SSCLoader::LoadFromDir( const RString &sPath, Song &out )
{
vector<RString> aFileNames;
GetApplicableFiles( sPath, aFileNames );
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
if( aFileNames.size() > 1 )
{
LOG->UserLog( "Song", sPath, "has more than one SSC file. Only one SSC file is allowed per song." );
return false;
}
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
ASSERT( aFileNames.size() == 1 ); // Ensure one was found entirely.
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
return LoadFromSSCFile( sPath + aFileNames[0], out );
}
bool SSCLoader::LoadFromSSCFile( const RString &sPath, Song &out, bool bFromCache )
{
LOG->Trace( "Song::LoadFromSSCFile(%s)", sPath.c_str() );
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
MsdFile msd;
if( !msd.ReadFile( sPath, true ) )
{
LOG->UserLog( "Song file", sPath, "couldn't be opened: %s", msd.GetError().c_str() );
return false;
}
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
out.m_Timing.m_sFile = sPath; // songs still have their fallback timing.
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
int state = GETTING_SONG_INFO;
const unsigned values = msd.GetNumValues();
Steps* pNewNotes;
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
for( unsigned i = 0; i < values; i++ )
{
const MsdFile::value_t &sParams = msd.GetValue(i);
RString sValueName = sParams[0];
sValueName.MakeUpper();
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
switch (state)
{
case GETTING_SONG_INFO:
{
2011-02-13 11:06:34 -06:00
if( sValueName=="VERSION" )
{
out.m_fVersion = StringToFloat( sParams[1] );
}
else if( sValueName=="TITLE" )
2011-02-10 23:35:34 -05:00
{
out.m_sMainTitle = sParams[1];
}
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
else if( sValueName=="SUBTITLE" )
{
out.m_sSubTitle = sParams[1];
}
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
else if( sValueName=="ARTIST" )
{
out.m_sArtist = sParams[1];
}
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
else if( sValueName=="TITLETRANSLIT" )
{
out.m_sMainTitleTranslit = sParams[1];
}
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
else if( sValueName=="SUBTITLETRANSLIT" )
{
out.m_sSubTitleTranslit = sParams[1];
}
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
else if( sValueName=="ARTISTTRANSLIT" )
{
out.m_sArtistTranslit = sParams[1];
}
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
else if( sValueName=="GENRE" )
{
out.m_sGenre = sParams[1];
}
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
else if( sValueName=="CREDIT" )
{
out.m_sCredit = sParams[1];
}
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
else if( sValueName=="BANNER" )
{
out.m_sBannerFile = sParams[1];
}
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
else if( sValueName=="BACKGROUND" )
{
out.m_sBackgroundFile = sParams[1];
}
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
else if( sValueName=="LYRICSPATH" )
{
out.m_sLyricsFile = sParams[1];
}
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
else if( sValueName=="CDTITLE" )
{
out.m_sCDTitleFile = sParams[1];
}
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
else if( sValueName=="MUSIC" )
{
out.m_sMusicFile = sParams[1];
}
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
else if( sValueName=="INSTRUMENTTRACK" )
{
vector<RString> vs1;
split( sParams[1], ",", vs1 );
FOREACH_CONST( RString, vs1, s )
{
vector<RString> vs2;
split( *s, "=", vs2 );
if( vs2.size() >= 2 )
{
InstrumentTrack it = StringToInstrumentTrack( vs2[0] );
if( it != InstrumentTrack_Invalid )
out.m_sInstrumentTrackFile[it] = vs2[1];
}
}
}
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
else if( sValueName=="MUSICLENGTH" )
{
if( !bFromCache )
continue;
out.m_fMusicLengthSeconds = StringToFloat( sParams[1] );
}
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
else if( sValueName=="LASTBEATHINT" )
{
out.m_fSpecifiedLastBeat = StringToFloat( sParams[1] );
}
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
else if( sValueName=="MUSICBYTES" )
{
2011-02-13 11:06:34 -06:00
; // ignore
2011-02-10 23:35:34 -05:00
}
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
else if( sValueName=="SAMPLESTART" )
{
out.m_fMusicSampleStartSeconds = HHMMSSToSeconds( sParams[1] );
}
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
else if( sValueName=="SAMPLELENGTH" )
{
out.m_fMusicSampleLengthSeconds = HHMMSSToSeconds( sParams[1] );
}
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
else if( sValueName=="DISPLAYBPM" )
{
// #DISPLAYBPM:[xxx][xxx:xxx]|[*];
if( sParams[1] == "*" )
out.m_DisplayBPMType = Song::DISPLAY_RANDOM;
else
{
out.m_DisplayBPMType = Song::DISPLAY_SPECIFIED;
out.m_fSpecifiedBPMMin = StringToFloat( sParams[1] );
if( sParams[2].empty() )
out.m_fSpecifiedBPMMax = out.m_fSpecifiedBPMMin;
else
out.m_fSpecifiedBPMMax = StringToFloat( sParams[2] );
}
}
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
else if( sValueName=="SELECTABLE" )
{
if(!stricmp(sParams[1],"YES"))
out.m_SelectionDisplay = out.SHOW_ALWAYS;
else if(!stricmp(sParams[1],"NO"))
out.m_SelectionDisplay = out.SHOW_NEVER;
// ROULETTE from 3.9 is no longer in use.
else if(!stricmp(sParams[1],"ROULETTE"))
out.m_SelectionDisplay = out.SHOW_ALWAYS;
/* The following two cases are just fixes to make sure simfiles that
* used 3.9+ features are not excluded here */
else if(!stricmp(sParams[1],"ES") || !stricmp(sParams[1],"OMES"))
out.m_SelectionDisplay = out.SHOW_ALWAYS;
else if( atoi(sParams[1]) > 0 )
out.m_SelectionDisplay = out.SHOW_ALWAYS;
else
LOG->UserLog( "Song file", sPath, "has an unknown #SELECTABLE value, \"%s\"; ignored.", sParams[1].c_str() );
}
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
else if( sValueName.Left(strlen("BGCHANGES"))=="BGCHANGES" || sValueName=="ANIMATIONS" )
{
BackgroundLayer iLayer = BACKGROUND_LAYER_1;
if( sscanf(sValueName, "BGCHANGES%d", &*ConvertValue<int>(&iLayer)) == 1 )
enum_add(iLayer, -1); // #BGCHANGES2 = BACKGROUND_LAYER_2
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
bool bValid = iLayer>=0 && iLayer<NUM_BackgroundLayer;
if( !bValid )
{
LOG->UserLog( "Song file", sPath, "has a #BGCHANGES tag \"%s\" that is out of range.", sValueName.c_str() );
}
else
{
vector<RString> aBGChangeExpressions;
split( sParams[1], ",", aBGChangeExpressions );
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
for( unsigned b=0; b<aBGChangeExpressions.size(); b++ )
{
BackgroundChange change;
if( LoadFromBGSSCChangesString( change, aBGChangeExpressions[b] ) )
out.AddBackgroundChange( iLayer, change );
}
}
}
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
else if( sValueName=="FGCHANGES" )
{
vector<RString> aFGChangeExpressions;
split( sParams[1], ",", aFGChangeExpressions );
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
for( unsigned b=0; b<aFGChangeExpressions.size(); b++ )
{
BackgroundChange change;
if( LoadFromBGSSCChangesString( change, aFGChangeExpressions[b] ) )
out.AddForegroundChange( change );
}
}
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
else if( sValueName=="KEYSOUNDS" )
{
split( sParams[1], ",", out.m_vsKeysoundFile );
}
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
// Attacks loaded from file
else if( sValueName=="ATTACKS" )
{
// Build the RString vector here so we can write it to file again later
for( unsigned s=1; s < sParams.params.size(); ++s )
out.m_sAttackString.push_back( sParams[s] );
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
Attack attack;
float end = -9999;
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
for( unsigned j=1; j < sParams.params.size(); ++j )
{
vector<RString> sBits;
split( sParams[j], "=", sBits, false );
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
// Need an identifer and a value for this to work
if( sBits.size() < 2 )
continue;
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
TrimLeft( sBits[0] );
TrimRight( sBits[0] );
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
if( !sBits[0].CompareNoCase("TIME") )
attack.fStartSecond = strtof( sBits[1], NULL );
else if( !sBits[0].CompareNoCase("LEN") )
attack.fSecsRemaining = strtof( sBits[1], NULL );
else if( !sBits[0].CompareNoCase("END") )
end = strtof( sBits[1], NULL );
else if( !sBits[0].CompareNoCase("MODS") )
{
attack.sModifiers = sBits[1];
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
if( end != -9999 )
{
attack.fSecsRemaining = end - attack.fStartSecond;
end = -9999;
}
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
if( attack.fSecsRemaining < 0.0f )
attack.fSecsRemaining = 0.0f;
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
out.m_Attacks.push_back( attack );
}
}
}
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
else if( sValueName=="OFFSET" )
{
out.m_Timing.m_fBeat0OffsetInSeconds = StringToFloat( sParams[1] );
}
2011-02-13 11:06:34 -06:00
/* Below are the song based timings that should only be used
* if the steps do not have their own timing. */
2011-02-10 23:35:34 -05:00
else if( sValueName=="STOPS" )
{
vector<RString> arrayFreezeExpressions;
split( sParams[1], ",", arrayFreezeExpressions );
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
for( unsigned f=0; f<arrayFreezeExpressions.size(); f++ )
{
vector<RString> arrayFreezeValues;
split( arrayFreezeExpressions[f], "=", arrayFreezeValues );
if( arrayFreezeValues.size() != 2 )
{
// XXX: Hard to tell which file caused this.
LOG->UserLog( "Song file", "(UNKNOWN)", "has an invalid #%s value \"%s\" (must have exactly one '='), ignored.",
2011-02-13 11:06:34 -06:00
sValueName.c_str(), arrayFreezeExpressions[f].c_str() );
2011-02-10 23:35:34 -05:00
continue;
}
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
const float fFreezeBeat = StringToFloat( arrayFreezeValues[0] );
const float fFreezeSeconds = StringToFloat( arrayFreezeValues[1] );
StopSegment new_seg( BeatToNoteRow(fFreezeBeat), fFreezeSeconds );
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
if(fFreezeSeconds > 0.0f)
{
// LOG->Trace( "Adding a freeze segment: beat: %f, seconds = %f", new_seg.m_fStartBeat, new_seg.m_fStopSeconds );
out.m_Timing.AddStopSegment( new_seg );
}
else
{
// negative stops (hi JS!) -aj
if( PREFSMAN->m_bQuirksMode )
{
// LOG->Trace( "Adding a negative freeze segment: beat: %f, seconds = %f", new_seg.m_fStartBeat, new_seg.m_fStopSeconds );
out.m_Timing.AddStopSegment( new_seg );
}
else
LOG->UserLog( "Song file", "(UNKNOWN)", "has an invalid stop at beat %f, length %f.", fFreezeBeat, fFreezeSeconds );
}
}
}
else if( sValueName=="DELAYS" )
{
vector<RString> arrayDelayExpressions;
split( sParams[1], ",", arrayDelayExpressions );
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
for( unsigned f=0; f<arrayDelayExpressions.size(); f++ )
{
vector<RString> arrayDelayValues;
split( arrayDelayExpressions[f], "=", arrayDelayValues );
if( arrayDelayValues.size() != 2 )
{
// XXX: Hard to tell which file caused this.
LOG->UserLog( "Song file", "(UNKNOWN)", "has an invalid #%s value \"%s\" (must have exactly one '='), ignored.",
2011-02-13 11:06:34 -06:00
sValueName.c_str(), arrayDelayExpressions[f].c_str() );
2011-02-10 23:35:34 -05:00
continue;
}
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
const float fFreezeBeat = StringToFloat( arrayDelayValues[0] );
const float fFreezeSeconds = StringToFloat( arrayDelayValues[1] );
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
StopSegment new_seg( BeatToNoteRow(fFreezeBeat), fFreezeSeconds, true );
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
// LOG->Trace( "Adding a delay segment: beat: %f, seconds = %f", new_seg.m_fStartBeat, new_seg.m_fStopSeconds );
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
if(fFreezeSeconds > 0.0f)
out.m_Timing.AddStopSegment( new_seg );
else
LOG->UserLog( "Song file", "(UNKNOWN)", "has an invalid delay at beat %f, length %f.", fFreezeBeat, fFreezeSeconds );
}
}
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
else if( sValueName=="BPMS" )
{
vector<RString> arrayBPMChangeExpressions;
split( sParams[1], ",", arrayBPMChangeExpressions );
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
for( unsigned b=0; b<arrayBPMChangeExpressions.size(); b++ )
{
vector<RString> arrayBPMChangeValues;
split( arrayBPMChangeExpressions[b], "=", arrayBPMChangeValues );
// XXX: Hard to tell which file caused this.
if( arrayBPMChangeValues.size() != 2 )
{
LOG->UserLog( "Song file", "(UNKNOWN)", "has an invalid #%s value \"%s\" (must have exactly one '='), ignored.",
2011-02-13 11:06:34 -06:00
sValueName.c_str(), arrayBPMChangeExpressions[b].c_str() );
2011-02-10 23:35:34 -05:00
continue;
}
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
const float fBeat = StringToFloat( arrayBPMChangeValues[0] );
const float fNewBPM = StringToFloat( arrayBPMChangeValues[1] );
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
if(fNewBPM > 0.0f)
out.m_Timing.AddBPMSegment( BPMSegment(BeatToNoteRow(fBeat), fNewBPM) );
else
{
out.m_Timing.m_bHasNegativeBpms = true;
// only add Negative BPMs in quirks mode -aj
if( PREFSMAN->m_bQuirksMode )
out.m_Timing.AddBPMSegment( BPMSegment(BeatToNoteRow(fBeat), fNewBPM) );
else
LOG->UserLog( "Song file", "(UNKNOWN)", "has an invalid BPM change at beat %f, BPM %f.", fBeat, fNewBPM );
}
}
}
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
else if( sValueName=="TIMESIGNATURES" )
{
vector<RString> vs1;
split( sParams[1], ",", vs1 );
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
FOREACH_CONST( RString, vs1, s1 )
{
vector<RString> vs2;
split( *s1, "=", vs2 );
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
if( vs2.size() < 3 )
{
LOG->UserLog( "Song file", "(UNKNOWN)", "has an invalid time signature change with %i values.", (int)vs2.size() );
continue;
}
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
const float fBeat = StringToFloat( vs2[0] );
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
TimeSignatureSegment seg;
seg.m_iStartRow = BeatToNoteRow(fBeat);
seg.m_iNumerator = atoi( vs2[1] );
seg.m_iDenominator = atoi( vs2[2] );
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
if( fBeat < 0 )
{
LOG->UserLog( "Song file", "(UNKNOWN)", "has an invalid time signature change with beat %f.", fBeat );
continue;
}
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
if( seg.m_iNumerator < 1 )
{
LOG->UserLog( "Song file", "(UNKNOWN)", "has an invalid time signature change with beat %f, iNumerator %i.", fBeat, seg.m_iNumerator );
continue;
}
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
if( seg.m_iDenominator < 1 )
{
LOG->UserLog( "Song file", "(UNKNOWN)", "has an invalid time signature change with beat %f, iDenominator %i.", fBeat, seg.m_iDenominator );
continue;
}
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
out.m_Timing.AddTimeSignatureSegment( seg );
}
}
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
else if( sValueName=="TICKCOUNTS" )
{
vector<RString> arrayTickcountExpressions;
split( sParams[1], ",", arrayTickcountExpressions );
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
for( unsigned f=0; f<arrayTickcountExpressions.size(); f++ )
{
vector<RString> arrayTickcountValues;
split( arrayTickcountExpressions[f], "=", arrayTickcountValues );
if( arrayTickcountValues.size() != 2 )
{
// XXX: Hard to tell which file caused this.
LOG->UserLog( "Song file", "(UNKNOWN)", "has an invalid #%s value \"%s\" (must have exactly one '='), ignored.",
2011-02-13 11:06:34 -06:00
sValueName.c_str(), arrayTickcountExpressions[f].c_str() );
2011-02-10 23:35:34 -05:00
continue;
}
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
const float fTickcountBeat = StringToFloat( arrayTickcountValues[0] );
const int iTicks = atoi( arrayTickcountValues[1] );
TickcountSegment new_seg( BeatToNoteRow(fTickcountBeat), iTicks );
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
if(iTicks >= 1 && iTicks <= ROWS_PER_BEAT ) // Constants
{
// LOG->Trace( "Adding a tickcount segment: beat: %f, ticks = %d", fTickcountBeat, iTicks );
out.m_Timing.AddTickcountSegment( new_seg );
}
else
{
LOG->UserLog( "Song file", "(UNKNOWN)", "has an invalid tickcount at beat %f, ticks %d.", fTickcountBeat, iTicks );
}
}
}
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
else if( sValueName=="COMBOS" )
{/*
vector<RString> arrayComboExpressions;
split( sParams[1], ",", arrayComboExpressions );
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
for( unsigned f=0; f<arrayComboExpressions.size(); f++ )
{
vector<RString> arrayComboValues;
split( arrayComboExpressions[f], "=", arrayComboValues );
if( arrayComboValues.size() != 2 )
{
LOG->UserLog( "Song file", "(UNKNOWN)", "has an invalid #%s value \"%s\" (must have exactly one '='), ignored.",
2011-02-13 11:06:34 -06:00
sValueName.c_str(), arrayComboExpressions[f].c_str() );
2011-02-10 23:35:34 -05:00
continue;
}
const float fComboBeat = StringToFloat( arrayComboValues[0] );
const int iCombos = atoi( arrayComboValues[1] );
ComboSegment new_seg( BeatToNoteRow( fComboBeat ), iCombos );
out.m_Timing.AddComboSegment( new_seg );
}
*/
}
2011-02-13 11:06:34 -06:00
/* The following are cache tags. Never fill their values
* directly: only from the cached version. */
2011-02-10 23:35:34 -05:00
else if( sValueName=="FIRSTBEAT" )
{
if( bFromCache )
out.m_fFirstBeat = StringToFloat( sParams[1] );
}
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
else if( sValueName=="LASTBEAT" )
{
if( bFromCache )
out.m_fLastBeat = StringToFloat( sParams[1] );
}
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
else if( sValueName=="SONGFILENAME" )
{
if( bFromCache )
out.m_sSongFileName = sParams[1];
}
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
else if( sValueName=="HASMUSIC" )
{
if( bFromCache )
out.m_bHasMusic = atoi( sParams[1] ) != 0;
}
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
else if( sValueName=="HASBANNER" )
{
if( bFromCache )
out.m_bHasBanner = atoi( sParams[1] ) != 0;
}
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
// This tag will get us to the next section.
else if( sValueName=="NOTEDATA" )
{
state = GETTING_STEP_INFO;
pNewNotes = new Steps;
}
break;
}
case GETTING_STEP_INFO:
{
if( sValueName=="STEPSTYPE" )
{
pNewNotes->m_StepsType = GAMEMAN->StringToStepsType( sParams[1] );
}
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
else if( sValueName=="DESCRIPTION" )
{
pNewNotes->SetDescription( sParams[1] );
}
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
else if( sValueName=="DIFFICULTY" )
{
pNewNotes->SetDifficulty( DwiCompatibleStringToDifficulty( sParams[1] ) );
}
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
else if( sValueName=="METER" )
{
pNewNotes->SetMeter( atoi( sParams[1] ) );
}
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
else if( sValueName=="RADARVALUES" )
{
vector<RString> saValues;
split( sParams[1], ",", saValues, true );
if( saValues.size() == NUM_RadarCategory * NUM_PLAYERS )
{
RadarValues v[NUM_PLAYERS];
FOREACH_PlayerNumber( pn )
FOREACH_ENUM( RadarCategory, rc )
v[pn][rc] = StringToFloat( saValues[pn*NUM_RadarCategory + rc] );
pNewNotes->SetCachedRadarValues( v );
}
}
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
else if( sValueName=="CREDIT" )
{
2011-02-11 01:17:24 -05:00
pNewNotes->SetCredit( sParams[1] );
2011-02-10 23:35:34 -05:00
}
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
else if( sValueName=="NOTES" )
{
state = GETTING_SONG_INFO;
//pNewNotes->m_Timing = out.m_Timing;
pNewNotes->SetSMNoteData( sParams[1] );
pNewNotes->TidyUpData();
out.AddSteps( pNewNotes );
}
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
else if( sValueName=="BPMS" )
{
/*
state = GETTING_STEP_TIMING_INFO;
vector<RString> arrayBPMChangeExpressions;
split( sParams[1], ",", arrayBPMChangeExpressions );
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
for( unsigned b=0; b<arrayBPMChangeExpressions.size(); b++ )
{
vector<RString> arrayBPMChangeValues;
split( arrayBPMChangeExpressions[b], "=", arrayBPMChangeValues );
// XXX: Hard to tell which file caused this.
if( arrayBPMChangeValues.size() != 2 )
{
LOG->UserLog( "Song file", "(UNKNOWN)", "has an invalid #%s value \"%s\" (must have exactly one '='), ignored.",
2011-02-13 11:06:34 -06:00
sValueName.c_str(), arrayBPMChangeExpressions[b].c_str() );
2011-02-10 23:35:34 -05:00
continue;
}
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
const float fBeat = StringToFloat( arrayBPMChangeValues[0] );
const float fNewBPM = StringToFloat( arrayBPMChangeValues[1] );
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
if(fNewBPM > 0.0f)
pNewNotes->m_Timing.AddBPMSegment( BPMSegment(BeatToNoteRow(fBeat), fNewBPM) );
else
{
pNewNotes->m_Timing.m_bHasNegativeBpms = true;
// only add Negative BPMs in quirks mode -aj
if( PREFSMAN->m_bQuirksMode )
pNewNotes->m_Timing.AddBPMSegment( BPMSegment(BeatToNoteRow(fBeat), fNewBPM) );
else
LOG->UserLog( "Song file", "(UNKNOWN)", "has an invalid BPM change at beat %f, BPM %f.", fBeat, fNewBPM );
}
}
*/
}
break;
}
case GETTING_STEP_TIMING_INFO:
{
if( sValueName=="STOPS" )
{
/*
vector<RString> arrayFreezeExpressions;
split( sParams[1], ",", arrayFreezeExpressions );
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
for( unsigned f=0; f<arrayFreezeExpressions.size(); f++ )
{
vector<RString> arrayFreezeValues;
split( arrayFreezeExpressions[f], "=", arrayFreezeValues );
if( arrayFreezeValues.size() != 2 )
{
// XXX: Hard to tell which file caused this.
LOG->UserLog( "Song file", "(UNKNOWN)", "has an invalid #%s value \"%s\" (must have exactly one '='), ignored.",
2011-02-13 11:06:34 -06:00
sValueName.c_str(), arrayFreezeExpressions[f].c_str() );
2011-02-10 23:35:34 -05:00
continue;
}
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
const float fFreezeBeat = StringToFloat( arrayFreezeValues[0] );
const float fFreezeSeconds = StringToFloat( arrayFreezeValues[1] );
StopSegment new_seg( BeatToNoteRow(fFreezeBeat), fFreezeSeconds );
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
if(fFreezeSeconds > 0.0f)
{
// LOG->Trace( "Adding a freeze segment: beat: %f, seconds = %f", new_seg.m_fStartBeat, new_seg.m_fStopSeconds );
pNewNotes->m_Timing.AddStopSegment( new_seg );
}
else
{
// negative stops (hi JS!) -aj
if( PREFSMAN->m_bQuirksMode )
{
// LOG->Trace( "Adding a negative freeze segment: beat: %f, seconds = %f", new_seg.m_fStartBeat, new_seg.m_fStopSeconds );
pNewNotes->m_Timing.AddStopSegment( new_seg );
}
else
LOG->UserLog( "Song file", "(UNKNOWN)", "has an invalid stop at beat %f, length %f.", fFreezeBeat, fFreezeSeconds );
}
}
*/
}
else if( sValueName=="DELAYS" )
{
/*
vector<RString> arrayDelayExpressions;
split( sParams[1], ",", arrayDelayExpressions );
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
for( unsigned f=0; f<arrayDelayExpressions.size(); f++ )
{
vector<RString> arrayDelayValues;
split( arrayDelayExpressions[f], "=", arrayDelayValues );
if( arrayDelayValues.size() != 2 )
{
// XXX: Hard to tell which file caused this.
LOG->UserLog( "Song file", "(UNKNOWN)", "has an invalid #%s value \"%s\" (must have exactly one '='), ignored.",
2011-02-13 11:06:34 -06:00
sValueName.c_str(), arrayDelayExpressions[f].c_str() );
2011-02-10 23:35:34 -05:00
continue;
}
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
const float fFreezeBeat = StringToFloat( arrayDelayValues[0] );
const float fFreezeSeconds = StringToFloat( arrayDelayValues[1] );
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
StopSegment new_seg( BeatToNoteRow(fFreezeBeat), fFreezeSeconds, true );
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
// LOG->Trace( "Adding a delay segment: beat: %f, seconds = %f", new_seg.m_fStartBeat, new_seg.m_fStopSeconds );
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
if(fFreezeSeconds > 0.0f)
pNewNotes->m_Timing.AddStopSegment( new_seg );
else
LOG->UserLog( "Song file", "(UNKNOWN)", "has an invalid delay at beat %f, length %f.", fFreezeBeat, fFreezeSeconds );
}
*/
}
else if( sValueName=="TIMESIGNATURES" )
{
/*
vector<RString> vs1;
split( sParams[1], ",", vs1 );
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
FOREACH_CONST( RString, vs1, s1 )
{
vector<RString> vs2;
split( *s1, "=", vs2 );
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
if( vs2.size() < 3 )
{
LOG->UserLog( "Song file", "(UNKNOWN)", "has an invalid time signature change with %i values.", (int)vs2.size() );
continue;
}
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
const float fBeat = StringToFloat( vs2[0] );
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
TimeSignatureSegment seg;
seg.m_iStartRow = BeatToNoteRow(fBeat);
seg.m_iNumerator = atoi( vs2[1] );
seg.m_iDenominator = atoi( vs2[2] );
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
if( fBeat < 0 )
{
LOG->UserLog( "Song file", "(UNKNOWN)", "has an invalid time signature change with beat %f.", fBeat );
continue;
}
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
if( seg.m_iNumerator < 1 )
{
LOG->UserLog( "Song file", "(UNKNOWN)", "has an invalid time signature change with beat %f, iNumerator %i.", fBeat, seg.m_iNumerator );
continue;
}
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
if( seg.m_iDenominator < 1 )
{
LOG->UserLog( "Song file", "(UNKNOWN)", "has an invalid time signature change with beat %f, iDenominator %i.", fBeat, seg.m_iDenominator );
continue;
}
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
pNewNotes->m_Timing.AddTimeSignatureSegment( seg );
}
*/
}
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
else if( sValueName=="TICKCOUNTS" )
{
/*
vector<RString> arrayTickcountExpressions;
split( sParams[1], ",", arrayTickcountExpressions );
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
for( unsigned f=0; f<arrayTickcountExpressions.size(); f++ )
{
vector<RString> arrayTickcountValues;
split( arrayTickcountExpressions[f], "=", arrayTickcountValues );
if( arrayTickcountValues.size() != 2 )
{
// XXX: Hard to tell which file caused this.
LOG->UserLog( "Song file", "(UNKNOWN)", "has an invalid #%s value \"%s\" (must have exactly one '='), ignored.",
2011-02-13 11:06:34 -06:00
sValueName.c_str(), arrayTickcountExpressions[f].c_str() );
2011-02-10 23:35:34 -05:00
continue;
}
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
const float fTickcountBeat = StringToFloat( arrayTickcountValues[0] );
const int iTicks = atoi( arrayTickcountValues[1] );
TickcountSegment new_seg( BeatToNoteRow(fTickcountBeat), iTicks );
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
if(iTicks >= 1 && iTicks <= ROWS_PER_BEAT ) // Constants
{
// LOG->Trace( "Adding a tickcount segment: beat: %f, ticks = %d", fTickcountBeat, iTicks );
pNewNotes->m_Timing.AddTickcountSegment( new_seg );
}
else
{
LOG->UserLog( "Song file", "(UNKNOWN)", "has an invalid tickcount at beat %f, ticks %d.", fTickcountBeat, iTicks );
}
}
*/
}
else if( sValueName=="COMBOS" )
{
/*
vector<RString> arrayComboExpressions;
split( sParams[1], ",", arrayComboExpressions );
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
for( unsigned f=0; f<arrayComboExpressions.size(); f++ )
{
vector<RString> arrayComboValues;
split( arrayComboExpressions[f], "=", arrayComboValues );
if( arrayComboValues.size() != 2 )
{
LOG->UserLog( "Song file", "(UNKNOWN)", "has an invalid #%s value \"%s\" (must have exactly one '='), ignored.",
2011-02-13 11:06:34 -06:00
sValueName.c_str(), arrayComboExpressions[f].c_str() );
2011-02-10 23:35:34 -05:00
continue;
}
const float fComboBeat = StringToFloat( arrayComboValues[0] );
const int iCombos = atoi( arrayComboValues[1] );
ComboSegment new_seg( BeatToNoteRow( fComboBeat ), iCombos );
pNewNotes->m_Timing.AddComboSegment( new_seg );
}
*/
}
else if( sValueName=="OFFSET" )
{/*
pNewNotes->m_Timing.m_fBeat0OffsetInSeconds = StringToFloat( sParams[1] );
*/
}
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
else if( sValueName=="NOTES" )
{
state = GETTING_SONG_INFO;
// pNewNotes->m_Timing.m_fBeat0OffsetInSeconds = out.m_Timing.m_fBeat0OffsetInSeconds;
pNewNotes->SetSMNoteData( sParams[1] );
pNewNotes->TidyUpData();
out.AddSteps( pNewNotes );
}
break;
}
}
}
return true;
}
void SSCLoader::GetApplicableFiles( const RString &sPath, vector<RString> &out )
{
GetDirListing( sPath + RString("*.ssc"), out );
}
bool SSCLoader::LoadEditFromFile( RString sEditFilePath, ProfileSlot slot, bool bAddStepsToSong )
{
LOG->Trace( "SSCLoader::LoadEditFromFile(%s)", sEditFilePath.c_str() );
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
int iBytes = FILEMAN->GetFileSizeInBytes( sEditFilePath );
if( iBytes > MAX_EDIT_STEPS_SIZE_BYTES )
{
LOG->UserLog( "Edit file", sEditFilePath, "is unreasonably large. It won't be loaded." );
return false;
}
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
MsdFile msd;
if( !msd.ReadFile( sEditFilePath, true ) ) // unescape
{
LOG->UserLog( "Edit file", sEditFilePath, "couldn't be opened: %s", msd.GetError().c_str() );
return false;
}
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
return LoadEditFromMsd( msd, sEditFilePath, slot, bAddStepsToSong );
}
bool SSCLoader::LoadEditFromMsd( const MsdFile &msd, const RString &sEditFilePath, ProfileSlot slot, bool bAddStepsToSong )
{
Song* pSong = NULL;
2011-02-11 11:39:19 -05:00
Steps* pNewNotes;
bool bSSCFormat = false;
2011-02-10 23:35:34 -05:00
for( unsigned i=0; i<msd.GetNumValues(); i++ )
{
int iNumParams = msd.GetNumParams(i);
const MsdFile::value_t &sParams = msd.GetValue(i);
RString sValueName = sParams[0];
sValueName.MakeUpper();
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
// handle the data
if( sValueName=="SONG" )
{
if( pSong )
{
LOG->UserLog( "Edit file", sEditFilePath, "has more than one #SONG tag." );
return false;
}
RString sSongFullTitle = sParams[1];
sSongFullTitle.Replace( '\\', '/' );
pSong = SONGMAN->FindSong( sSongFullTitle );
if( pSong == NULL )
{
LOG->UserLog( "Edit file", sEditFilePath, "requires a song \"%s\" that isn't present.", sSongFullTitle.c_str() );
return false;
}
if( pSong->GetNumStepsLoadedFromProfile(slot) >= MAX_EDITS_PER_SONG_PER_PROFILE )
{
LOG->UserLog( "Song file", sSongFullTitle, "already has the maximum number of edits allowed for ProfileSlotP%d.", slot+1 );
return false;
}
}
2011-02-11 11:39:19 -05:00
else if( sValueName=="NOTEDATA" )
{
pNewNotes = new Steps;
bSSCFormat = true;
}
if( sValueName=="STEPSTYPE" )
{
pNewNotes->m_StepsType = GAMEMAN->StringToStepsType( sParams[1] );
bSSCFormat = true;
}
2011-02-13 11:06:34 -06:00
2011-02-11 11:39:19 -05:00
else if( sValueName=="DESCRIPTION" )
{
pNewNotes->SetDescription( sParams[1] );
bSSCFormat = true;
}
2011-02-13 11:06:34 -06:00
2011-02-11 11:39:19 -05:00
else if( sValueName=="DIFFICULTY" )
{
pNewNotes->SetDifficulty( DwiCompatibleStringToDifficulty( sParams[1] ) );
bSSCFormat = true;
}
2011-02-13 11:06:34 -06:00
2011-02-11 11:39:19 -05:00
else if( sValueName=="METER" )
{
pNewNotes->SetMeter( atoi( sParams[1] ) );
bSSCFormat = true;
}
2011-02-13 11:06:34 -06:00
2011-02-11 11:39:19 -05:00
else if( sValueName=="RADARVALUES" )
{
vector<RString> saValues;
split( sParams[1], ",", saValues, true );
if( saValues.size() == NUM_RadarCategory * NUM_PLAYERS )
{
RadarValues v[NUM_PLAYERS];
FOREACH_PlayerNumber( pn )
FOREACH_ENUM( RadarCategory, rc )
v[pn][rc] = StringToFloat( saValues[pn*NUM_RadarCategory + rc] );
pNewNotes->SetCachedRadarValues( v );
}
bSSCFormat = true;
}
2011-02-13 11:06:34 -06:00
2011-02-11 11:39:19 -05:00
else if( sValueName=="CREDIT" )
{
pNewNotes->SetCredit( sParams[1] );
bSSCFormat = true;
}
2011-02-13 11:06:34 -06:00
2011-02-11 11:39:19 -05:00
// TimingData for Steps isn't set yet, but still prepare for it.
else if( sValueName=="BPMS" )
{
bSSCFormat = true;
}
else if( sValueName=="STOPS" )
{
bSSCFormat = true;
}
else if( sValueName=="DELAYS" )
{
bSSCFormat = true;
}
else if( sValueName=="TIMESIGNATURES" )
{
bSSCFormat = true;
}
else if( sValueName=="TICKCOUNTS" )
{
bSSCFormat = true;
}
else if( sValueName=="COMBOS" )
{
bSSCFormat = true;
}
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
else if( sValueName=="NOTES" )
{
if( pSong == NULL )
{
LOG->UserLog( "Edit file", sEditFilePath, "doesn't have a #SONG tag preceeding the first #NOTES tag." );
return false;
}
2011-02-13 11:06:34 -06:00
2011-02-11 11:39:19 -05:00
if ( !bSSCFormat && iNumParams < 7 )
2011-02-10 23:35:34 -05:00
{
LOG->UserLog( "Edit file", sEditFilePath, "has %d fields in a #NOTES tag, but should have at least 7.", iNumParams );
continue;
}
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
if( !bAddStepsToSong )
return true;
2011-02-13 11:06:34 -06:00
2011-02-11 11:39:19 -05:00
if( bSSCFormat )
{
pNewNotes->SetSMNoteData( sParams[1] );
pNewNotes->TidyUpData();
pSong->AddSteps( pNewNotes );
}
else
{
pNewNotes = new Steps;
2011-02-11 12:28:23 -05:00
SMLoader::LoadFromSMTokens(
2011-02-11 11:39:19 -05:00
sParams[1], sParams[2], sParams[3], sParams[4], sParams[5], sParams[6],
*pNewNotes);
}
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
pNewNotes->SetLoadedFromProfile( slot );
pNewNotes->SetDifficulty( Difficulty_Edit );
pNewNotes->SetFilename( sEditFilePath );
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
if( pSong->IsEditAlreadyLoaded(pNewNotes) )
{
LOG->UserLog( "Edit file", sEditFilePath, "is a duplicate of another edit that was already loaded." );
SAFE_DELETE( pNewNotes );
return false;
}
pSong->AddSteps( pNewNotes );
return true; // Only allow one Steps per edit file!
}
else
{
LOG->UserLog( "Edit file", sEditFilePath, "has an unexpected value \"%s\".", sValueName.c_str() );
}
}
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
return true;
}
void SSCLoader::TidyUpData( Song &song, bool bFromCache )
{
/*
* 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.GetBackgroundChanges(BACKGROUND_LAYER_1);
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;
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
for( unsigned i = 0; !bHasNoSongBgTag && i < bg.size(); ++i )
{
if( !bg[i].m_def.m_sFile1.CompareNoCase(NO_SONG_BG_FILE) )
{
bg.erase( bg.begin()+i );
bHasNoSongBgTag = true;
}
}
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
// If there's no -nosongbg- tag, add the song BG.
if( !bHasNoSongBgTag ) do
{
/* If we're loading cache, -nosongbg- should always be in there. We
* must not call IsAFile(song.GetBackgroundPath()) when loading cache. */
if( bFromCache )
break;
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
/* If BGChanges already exist after the last beat, don't add the
* background in the middle. */
if( !bg.empty() && bg.back().m_fStartBeat-0.0001f >= song.m_fLastBeat )
break;
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
// If the last BGA is already the song BGA, don't add a duplicate.
if( !bg.empty() && !bg.back().m_def.m_sFile1.CompareNoCase(song.m_sBackgroundFile) )
break;
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
if( !IsAFile( song.GetBackgroundPath() ) )
break;
2011-02-13 11:06:34 -06:00
2011-02-10 23:35:34 -05:00
bg.push_back( BackgroundChange(song.m_fLastBeat,song.m_sBackgroundFile) );
} while(0);
}
}
/*
2011-02-11 14:30:32 -05:00
* (c) 2011 Jason Felds
2011-02-10 23:35:34 -05:00
* All rights reserved.
*
* 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.
*
* 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.
*/