support loading of course edits
This commit is contained in:
+2
-429
@@ -8,7 +8,6 @@
|
||||
#include "GameState.h"
|
||||
#include "RageException.h"
|
||||
#include "RageLog.h"
|
||||
#include "MsdFile.h"
|
||||
#include "PlayerOptions.h"
|
||||
#include "SongOptions.h"
|
||||
#include "SongCacheIndex.h"
|
||||
@@ -22,6 +21,7 @@
|
||||
#include "Foreach.h"
|
||||
#include "UnlockManager.h"
|
||||
#include <limits.h>
|
||||
#include "CourseLoaderCRS.h"
|
||||
|
||||
|
||||
static const CString CourseTypeNames[] = {
|
||||
@@ -124,306 +124,12 @@ PlayMode Course::GetPlayMode() const
|
||||
}
|
||||
}
|
||||
|
||||
void Course::LoadFromCRSFile( CString sPath )
|
||||
{
|
||||
Init();
|
||||
|
||||
m_sPath = sPath; // save path
|
||||
|
||||
// save group name
|
||||
{
|
||||
CStringArray parts;
|
||||
split( sPath, "/", parts, false );
|
||||
if( parts.size() >= 4 ) // e.g. "/Courses/blah/fun.cvs"
|
||||
m_sGroupName = parts[parts.size()-2];
|
||||
}
|
||||
|
||||
|
||||
bool bUseCache = true;
|
||||
{
|
||||
/* First look in the cache for this course. Don't bother
|
||||
* honoring FastLoad for checking the course hash, since
|
||||
* courses are normally grouped into a few directories, not
|
||||
* one directory per course. XXX: if !FastLoad, regen
|
||||
* cache if the used songs have changed */
|
||||
unsigned uHash = SONGINDEX->GetCacheHash( m_sPath );
|
||||
if( !DoesFileExist(GetCacheFilePath()) )
|
||||
bUseCache = false;
|
||||
if( !PREFSMAN->m_bFastLoad && GetHashForDirectory(m_sPath) != uHash )
|
||||
bUseCache = false; // this cache is out of date
|
||||
}
|
||||
|
||||
if( bUseCache )
|
||||
{
|
||||
CString sCacheFile = GetCacheFilePath();
|
||||
LOG->Trace( "Course::LoadFromCRSFile(\"%s\") (\"%s\")", sPath.c_str(), sCacheFile.c_str() );
|
||||
sPath = sCacheFile.c_str();
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG->Trace( "Course::LoadFromCRSFile(\"%s\")", sPath.c_str() );
|
||||
}
|
||||
|
||||
MsdFile msd;
|
||||
if( !msd.ReadFile(sPath) )
|
||||
RageException::Throw( "Error opening CRS file '%s'.", sPath.c_str() );
|
||||
|
||||
const CString sFName = SetExtension( m_sPath, "" );
|
||||
|
||||
CStringArray arrayPossibleBanners;
|
||||
GetDirListing( sFName + "*.png", arrayPossibleBanners, false, true );
|
||||
GetDirListing( sFName + "*.jpg", arrayPossibleBanners, false, true );
|
||||
GetDirListing( sFName + "*.bmp", arrayPossibleBanners, false, true );
|
||||
GetDirListing( sFName + "*.gif", arrayPossibleBanners, false, true );
|
||||
if( !arrayPossibleBanners.empty() )
|
||||
m_sBannerPath = arrayPossibleBanners[0];
|
||||
|
||||
AttackArray attacks;
|
||||
float fGainSeconds = 0;
|
||||
for( unsigned i=0; i<msd.GetNumValues(); i++ )
|
||||
{
|
||||
CString sValueName = msd.GetParam(i, 0);
|
||||
const MsdFile::value_t &sParams = msd.GetValue(i);
|
||||
|
||||
// handle the data
|
||||
if( 0 == stricmp(sValueName, "COURSE") )
|
||||
m_sMainTitle = sParams[1];
|
||||
else if( 0 == stricmp(sValueName, "COURSETRANSLIT") )
|
||||
m_sMainTitleTranslit = sParams[1];
|
||||
else if( 0 == stricmp(sValueName, "REPEAT") )
|
||||
{
|
||||
CString str = sParams[1];
|
||||
str.MakeLower();
|
||||
if( str.Find("yes") != -1 )
|
||||
m_bRepeat = true;
|
||||
}
|
||||
|
||||
else if( 0 == stricmp(sValueName, "LIVES") )
|
||||
m_iLives = atoi( sParams[1] );
|
||||
|
||||
else if( 0 == stricmp(sValueName, "GAINSECONDS") )
|
||||
fGainSeconds = strtof( sParams[1], NULL );
|
||||
|
||||
else if( 0 == stricmp(sValueName, "METER") )
|
||||
{
|
||||
if( sParams.params.size() == 2 )
|
||||
m_iCustomMeter[DIFFICULTY_MEDIUM] = atoi( sParams[1] ); /* compat */
|
||||
else if( sParams.params.size() == 3 )
|
||||
{
|
||||
const CourseDifficulty cd = StringToCourseDifficulty( sParams[1] );
|
||||
if( cd == DIFFICULTY_INVALID )
|
||||
{
|
||||
LOG->Warn( "Course file '%s' contains an invalid #METER string: \"%s\"",
|
||||
sPath.c_str(), sParams[1].c_str() );
|
||||
continue;
|
||||
}
|
||||
m_iCustomMeter[cd] = atoi( sParams[2] );
|
||||
}
|
||||
}
|
||||
|
||||
else if( 0 == stricmp(sValueName, "MODS") )
|
||||
{
|
||||
Attack attack;
|
||||
float end = -9999;
|
||||
for( unsigned j = 1; j < sParams.params.size(); ++j )
|
||||
{
|
||||
CStringArray sBits;
|
||||
split( sParams[j], "=", sBits, false );
|
||||
if( sBits.size() < 2 )
|
||||
continue;
|
||||
|
||||
TrimLeft( sBits[0] );
|
||||
TrimRight( sBits[0] );
|
||||
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];
|
||||
if( end != -9999 )
|
||||
{
|
||||
ASSERT_M( end >= attack.fStartSecond, ssprintf("Attack ends before it starts. end %f, start %f", end, attack.fStartSecond) );
|
||||
attack.fSecsRemaining = end - attack.fStartSecond;
|
||||
end = -9999;
|
||||
}
|
||||
|
||||
// warn on invalid so we catch bogus mods on load
|
||||
PlayerOptions po;
|
||||
po.FromString( attack.sModifiers, true );
|
||||
|
||||
attacks.push_back( attack );
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG->Warn( "Unexpected value named '%s'", sBits[0].c_str() );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
else if( 0 == stricmp(sValueName, "SONG") )
|
||||
{
|
||||
CourseEntry new_entry;
|
||||
|
||||
// infer entry::Type from the first param
|
||||
if( sParams[1].Left(strlen("BEST")) == "BEST" )
|
||||
{
|
||||
new_entry.iChooseIndex = atoi( sParams[1].Right(sParams[1].size()-strlen("BEST")) ) - 1;
|
||||
CLAMP( new_entry.iChooseIndex, 0, 500 );
|
||||
new_entry.songSort = SongSort_MostPlays;
|
||||
}
|
||||
else if( sParams[1].Left(strlen("WORST")) == "WORST" )
|
||||
{
|
||||
new_entry.iChooseIndex = atoi( sParams[1].Right(sParams[1].size()-strlen("WORST")) ) - 1;
|
||||
CLAMP( new_entry.iChooseIndex, 0, 500 );
|
||||
new_entry.songSort = SongSort_FewestPlays;
|
||||
}
|
||||
else if( sParams[1] == "*" )
|
||||
{
|
||||
new_entry.bSecret = true;
|
||||
}
|
||||
else if( sParams[1].Right(1) == "*" )
|
||||
{
|
||||
new_entry.bSecret = true;
|
||||
CString sSong = sParams[1];
|
||||
sSong.Replace( "\\", "/" );
|
||||
CStringArray bits;
|
||||
split( sSong, "/", bits );
|
||||
if( bits.size() == 2 )
|
||||
{
|
||||
new_entry.sSongGroup = bits[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG->Warn( "Course file '%s' contains a random_within_group entry '%s' that is invalid. "
|
||||
"Song should be in the format '<group>/*'.",
|
||||
sPath.c_str(), sSong.c_str());
|
||||
}
|
||||
|
||||
if( !SONGMAN->DoesSongGroupExist(new_entry.sSongGroup) )
|
||||
{
|
||||
/* XXX: We need a place to put "user warnings". This is too loud for info.txt--
|
||||
* it obscures important warnings--and regular users never look there, anyway. */
|
||||
LOG->Trace( "Course file '%s' random_within_group entry '%s' specifies a group that doesn't exist. "
|
||||
"This entry will be ignored.",
|
||||
sPath.c_str(), sSong.c_str());
|
||||
continue; // skip this #SONG
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
CString sSong = sParams[1];
|
||||
new_entry.pSong = SONGMAN->FindSong( sSong );
|
||||
|
||||
if( new_entry.pSong == NULL )
|
||||
{
|
||||
/* XXX: We need a place to put "user warnings". This is too loud for info.txt--
|
||||
* it obscures important warnings--and regular users never look there, anyway. */
|
||||
LOG->Trace( "Course file '%s' contains a fixed song entry '%s' that does not exist. "
|
||||
"This entry will be ignored.",
|
||||
sPath.c_str(), sSong.c_str());
|
||||
continue; // skip this #SONG
|
||||
}
|
||||
}
|
||||
|
||||
new_entry.baseDifficulty = StringToDifficulty( sParams[2] );
|
||||
if( new_entry.baseDifficulty == DIFFICULTY_INVALID )
|
||||
{
|
||||
int retval = sscanf( sParams[2], "%d..%d", &new_entry.iLowMeter, &new_entry.iHighMeter );
|
||||
if( retval == 1 )
|
||||
new_entry.iHighMeter = new_entry.iLowMeter;
|
||||
else if( retval != 2 )
|
||||
{
|
||||
LOG->Warn("Course file '%s' contains an invalid difficulty setting: \"%s\", 3..6 used instead",
|
||||
sPath.c_str(), sParams[2].c_str());
|
||||
new_entry.iLowMeter = 3;
|
||||
new_entry.iHighMeter = 6;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
/* If "showcourse" or "noshowcourse" is in the list, force new_entry.secret
|
||||
* on or off. */
|
||||
CStringArray mods;
|
||||
split( sParams[3], ",", mods, true );
|
||||
for( int j = (int) mods.size()-1; j >= 0 ; --j )
|
||||
{
|
||||
CString &sMod = mods[j];
|
||||
TrimLeft( sMod );
|
||||
TrimRight( sMod );
|
||||
if( !sMod.CompareNoCase("showcourse") )
|
||||
new_entry.bSecret = false;
|
||||
else if( !sMod.CompareNoCase("noshowcourse") )
|
||||
new_entry.bSecret = true;
|
||||
else if( !sMod.CompareNoCase("nodifficult") )
|
||||
new_entry.bNoDifficult = true;
|
||||
else
|
||||
continue;
|
||||
mods.erase(mods.begin() + j);
|
||||
}
|
||||
new_entry.sModifiers = join( ",", mods );
|
||||
}
|
||||
|
||||
new_entry.attacks = attacks;
|
||||
new_entry.fGainSeconds = fGainSeconds;
|
||||
attacks.clear();
|
||||
|
||||
m_vEntries.push_back( new_entry );
|
||||
}
|
||||
else if( bUseCache && !stricmp(sValueName, "RADAR") )
|
||||
{
|
||||
StepsType st = (StepsType) atoi(sParams[1]);
|
||||
CourseDifficulty cd = (CourseDifficulty) atoi(sParams[2]);
|
||||
|
||||
RadarValues rv;
|
||||
rv.FromString( sParams[3] );
|
||||
m_RadarCache[CacheEntry(st, cd)] = rv;
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG->Warn( "Unexpected value named '%s'", sValueName.c_str() );
|
||||
}
|
||||
}
|
||||
static TitleSubst tsub("courses");
|
||||
|
||||
TitleFields title;
|
||||
title.Title = m_sMainTitle;
|
||||
title.TitleTranslit = m_sMainTitleTranslit;
|
||||
tsub.Subst( title );
|
||||
m_sMainTitle = title.Title;
|
||||
m_sMainTitleTranslit = title.TitleTranslit;
|
||||
|
||||
/* Cache and load the course banner. Only bother doing this if at least one
|
||||
* song was found in the course. */
|
||||
if( m_sBannerPath != "" && !m_vEntries.empty() )
|
||||
BANNERCACHE->CacheBanner( m_sBannerPath );
|
||||
|
||||
/* Cache each trail RadarValues that's slow to load, so we
|
||||
* don't have to do it at runtime. */
|
||||
if( !bUseCache )
|
||||
{
|
||||
CalculateRadarValues();
|
||||
|
||||
/* If we have any cache data, write the cache file. */
|
||||
if( m_RadarCache.size() )
|
||||
{
|
||||
CString sCachePath = GetCacheFilePath();
|
||||
Save( sCachePath, true );
|
||||
|
||||
SONGINDEX->AddCacheIndex( m_sPath, GetHashForFile(m_sPath) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Course::RevertFromDisk()
|
||||
{
|
||||
// trying to catch invalid an Course
|
||||
ASSERT( !m_sPath.empty() );
|
||||
|
||||
LoadFromCRSFile( m_sPath );
|
||||
CourseLoaderCRS::LoadFromCRSFile( m_sPath, *this );
|
||||
}
|
||||
|
||||
CString Course::GetCacheFilePath() const
|
||||
@@ -454,139 +160,6 @@ void Course::Init()
|
||||
m_iTrailCacheSeed = 0;
|
||||
}
|
||||
|
||||
void Course::Save( CString sPath, bool bSavingCache )
|
||||
{
|
||||
ASSERT( !m_bIsAutogen );
|
||||
|
||||
/* By default, save to the file we loaded from. */
|
||||
if( sPath == "" )
|
||||
sPath = m_sPath;
|
||||
|
||||
RageFile f;
|
||||
if( !f.Open( sPath, RageFile::WRITE ) )
|
||||
{
|
||||
LOG->Warn( "Could not write course file '%s': %s", sPath.c_str(), f.GetError().c_str() );
|
||||
return;
|
||||
}
|
||||
|
||||
f.PutLine( ssprintf("#COURSE:%s;", m_sMainTitle.c_str()) );
|
||||
if( m_sMainTitleTranslit != "" )
|
||||
f.PutLine( ssprintf("#COURSETRANSLIT:%s;", m_sMainTitleTranslit.c_str()) );
|
||||
if( m_bRepeat )
|
||||
f.PutLine( "#REPEAT:YES;" );
|
||||
if( m_iLives != -1 )
|
||||
f.PutLine( ssprintf("#LIVES:%i;", m_iLives) );
|
||||
|
||||
FOREACH_CourseDifficulty( cd )
|
||||
{
|
||||
if( m_iCustomMeter[cd] == -1 )
|
||||
continue;
|
||||
f.PutLine( ssprintf("#METER:%s:%i;", CourseDifficultyToString(cd).c_str(), m_iCustomMeter[cd]) );
|
||||
}
|
||||
|
||||
if( bSavingCache )
|
||||
{
|
||||
f.PutLine( "// cache tags:" );
|
||||
|
||||
RadarCache_t::const_iterator it;
|
||||
for( it = m_RadarCache.begin(); it != m_RadarCache.end(); ++it )
|
||||
{
|
||||
// #RADAR:type:difficulty:value,value,value...;
|
||||
const CacheEntry &entry = it->first;
|
||||
StepsType st = entry.first;
|
||||
CourseDifficulty cd = entry.second;
|
||||
|
||||
CStringArray asRadarValues;
|
||||
const RadarValues &rv = it->second;
|
||||
for( int r=0; r < NUM_RADAR_CATEGORIES; r++ )
|
||||
asRadarValues.push_back( ssprintf("%.3f", rv[r]) );
|
||||
CString sLine = ssprintf( "#RADAR:%i:%i:", st, cd );
|
||||
sLine += join( ",", asRadarValues ) + ";";
|
||||
f.PutLine( sLine );
|
||||
}
|
||||
f.PutLine( "// end cache tags" );
|
||||
}
|
||||
|
||||
for( unsigned i=0; i<m_vEntries.size(); i++ )
|
||||
{
|
||||
const CourseEntry& entry = m_vEntries[i];
|
||||
|
||||
for( unsigned j = 0; j < entry.attacks.size(); ++j )
|
||||
{
|
||||
if( j == 0 )
|
||||
f.PutLine( "#MODS:" );
|
||||
|
||||
const Attack &a = entry.attacks[j];
|
||||
f.Write( ssprintf( " TIME=%.2f:LEN=%.2f:MODS=%s",
|
||||
a.fStartSecond, a.fSecsRemaining, a.sModifiers.c_str() ) );
|
||||
|
||||
if( j+1 < entry.attacks.size() )
|
||||
f.Write( ":" );
|
||||
else
|
||||
f.Write( ";" );
|
||||
f.PutLine( "" );
|
||||
}
|
||||
|
||||
if( entry.fGainSeconds > 0 )
|
||||
f.PutLine( ssprintf("#GAINSECONDS:%f;", entry.fGainSeconds) );
|
||||
|
||||
if( entry.songSort == SongSort_MostPlays && entry.iChooseIndex != -1 )
|
||||
{
|
||||
f.Write( ssprintf( "#SONG:BEST%d", entry.iChooseIndex+1 ) );
|
||||
}
|
||||
else if( entry.songSort == SongSort_FewestPlays && entry.iChooseIndex != -1 )
|
||||
{
|
||||
f.Write( ssprintf( "#SONG:WORST%d", entry.iChooseIndex+1 ) );
|
||||
}
|
||||
else if( entry.pSong )
|
||||
{
|
||||
// strip off everything but the group name and song dir
|
||||
CStringArray as;
|
||||
ASSERT( entry.pSong != NULL );
|
||||
split( entry.pSong->GetSongDir(), "/", as );
|
||||
ASSERT( as.size() >= 2 );
|
||||
CString sGroup = as[ as.size()-2 ];
|
||||
CString sSong = as[ as.size()-1 ];
|
||||
f.Write( "#SONG:" + sGroup + '/' + sSong );
|
||||
}
|
||||
else if( !entry.sSongGroup.empty() )
|
||||
{
|
||||
f.Write( ssprintf( "#SONG:%s/*", entry.sSongGroup.c_str() ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
f.Write( "#SONG:*" );
|
||||
}
|
||||
|
||||
f.Write( ":" );
|
||||
if( entry.baseDifficulty != DIFFICULTY_INVALID )
|
||||
f.Write( DifficultyToString(entry.baseDifficulty) );
|
||||
else if( entry.iLowMeter != -1 && entry.iHighMeter != -1 )
|
||||
f.Write( ssprintf( "%d..%d", entry.iLowMeter, entry.iHighMeter ) );
|
||||
f.Write( ":" );
|
||||
|
||||
CString sModifiers = entry.sModifiers;
|
||||
bool bDefaultSecret = entry.IsRandomSong();
|
||||
if( bDefaultSecret != entry.bSecret )
|
||||
{
|
||||
if( sModifiers != "" )
|
||||
sModifiers += ",";
|
||||
sModifiers += entry.bSecret? "noshowcourse":"showcourse";
|
||||
}
|
||||
|
||||
if( entry.bNoDifficult )
|
||||
{
|
||||
if( sModifiers != "" )
|
||||
sModifiers += ",";
|
||||
sModifiers += "nodifficult";
|
||||
}
|
||||
f.Write( sModifiers );
|
||||
|
||||
f.PutLine( ";" );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Course::AutogenEndlessFromGroup( CString sGroupName, Difficulty diff )
|
||||
{
|
||||
m_bIsAutogen = true;
|
||||
|
||||
Reference in New Issue
Block a user