From 35df186a286fcb394fc1fafb52eef6baecb56534 Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Sat, 11 Apr 2009 19:10:41 +0000 Subject: [PATCH] move EditCourseUtil into CourseUtil, remove WorkoutManager --- stepmania/src/CourseUtil.cpp | 165 ++++++++++++++ stepmania/src/CourseUtil.h | 22 ++ stepmania/src/GameState.cpp | 1 - stepmania/src/PercentageDisplay.cpp | 1 - stepmania/src/ScreenGameplay.cpp | 1 - stepmania/src/ScreenOptionsEditPlaylist.cpp | 6 +- stepmania/src/ScreenOptionsManageCourses.cpp | 1 - stepmania/src/ScreenOptionsManageWorkouts.cpp | 1 - stepmania/src/ScreenOptionsReviewWorkout.cpp | 1 - stepmania/src/StepMania-net2003.vcproj | 6 - stepmania/src/WorkoutManager.cpp | 202 ------------------ stepmania/src/WorkoutManager.h | 53 ----- 12 files changed, 190 insertions(+), 270 deletions(-) delete mode 100644 stepmania/src/WorkoutManager.cpp delete mode 100644 stepmania/src/WorkoutManager.h diff --git a/stepmania/src/CourseUtil.cpp b/stepmania/src/CourseUtil.cpp index 9edd0eedc0..5e97ba211b 100644 --- a/stepmania/src/CourseUtil.cpp +++ b/stepmania/src/CourseUtil.cpp @@ -13,6 +13,8 @@ #include "LocalizedString.h" #include "RageLog.h" #include "arch/Dialog/Dialog.h" +#include "RageFileManager.h" +#include "CourseWriterCRS.h" // @@ -316,6 +318,169 @@ void CourseUtil::WarnOnInvalidMods( RString sMods ) } } +int EditCourseUtil::MAX_NAME_LENGTH = 16; +int EditCourseUtil::MAX_PER_PROFILE = 32; +int EditCourseUtil::MIN_WORKOUT_MINUTES = 4; +int EditCourseUtil::MAX_WORKOUT_MINUTES = 90; +bool EditCourseUtil::s_bNewCourseNeedsName = false; + +bool EditCourseUtil::Save( Course *pCourse ) +{ + return EditCourseUtil::RenameAndSave( pCourse, pCourse->GetDisplayFullTitle() ); +} + +bool EditCourseUtil::RenameAndSave( Course *pCourse, RString sNewName ) +{ + ASSERT( !sNewName.empty() ); + + EditCourseUtil::s_bNewCourseNeedsName = false; + + RString sNewFilePath; + if( pCourse->IsAnEdit() ) + { + sNewFilePath = PROFILEMAN->GetProfileDir(ProfileSlot_Machine) + EDIT_COURSES_SUBDIR + sNewName + ".crs"; + } + else + { + RString sDir, sName, sExt; + splitpath( pCourse->m_sPath, sDir, sName, sExt ); + sNewFilePath = sDir + sNewName + sExt; + } + + // remove the old file if the name is changing + if( !pCourse->m_sPath.empty() && sNewFilePath != pCourse->m_sPath ) + { + FILEMAN->Remove( pCourse->m_sPath ); // not fatal if this fails + FlushDirCache(); + } + + pCourse->m_sMainTitle = sNewName; + pCourse->m_sPath = sNewFilePath; + return CourseWriterCRS::Write( *pCourse, pCourse->m_sPath, false ); +} + +bool EditCourseUtil::RemoveAndDeleteFile( Course *pCourse ) +{ + if( !FILEMAN->Remove( pCourse->m_sPath ) ) + return false; + FILEMAN->Remove( pCourse->GetCacheFilePath() ); + FlushDirCache(); + if( pCourse->IsAnEdit() ) + { + PROFILEMAN->LoadMachineProfile(); + } + else + { + SONGMAN->DeleteCourse( pCourse ); + delete pCourse; + } + return true; +} + +static LocalizedString YOU_MUST_SUPPLY_NAME ( "WorkoutManager", "You must supply a name for your workout." ); +static LocalizedString EDIT_NAME_CONFLICTS ( "WorkoutManager", "The name you chose conflicts with another workout. Please use a different name." ); +static LocalizedString EDIT_NAME_CANNOT_CONTAIN ( "WorkoutManager", "The workout name cannot contain any of the following characters: %s" ); +bool EditCourseUtil::ValidateEditCourseName( const RString &sAnswer, RString &sErrorOut ) +{ + if( sAnswer.empty() ) + { + sErrorOut = YOU_MUST_SUPPLY_NAME; + return false; + } + + static const RString sInvalidChars = "\\/:*?\"<>|"; + if( strpbrk(sAnswer, sInvalidChars) != NULL ) + { + sErrorOut = ssprintf( EDIT_NAME_CANNOT_CONTAIN.GetValue(), sInvalidChars.c_str() ); + return false; + } + + // Check for name conflicts + vector vpCourses; + EditCourseUtil::GetAllEditCourses( vpCourses ); + FOREACH_CONST( Course*, vpCourses, p ) + { + if( GAMESTATE->m_pCurCourse == *p ) + continue; // don't comepare name against ourself + + if( (*p)->GetDisplayFullTitle() == sAnswer ) + { + sErrorOut = EDIT_NAME_CONFLICTS; + return false; + } + } + + return true; +} + +void EditCourseUtil::UpdateAndSetTrail() +{ + StepsType st = GAMESTATE->m_pCurStyle->m_StepsType; + Trail *pTrail = GAMESTATE->m_pCurCourse->GetTrailForceRegenCache( st ); + ASSERT( pTrail ); + GAMESTATE->m_pCurTrail[PLAYER_1].Set( pTrail ); +} + +void EditCourseUtil::PrepareForPlay() +{ + GAMESTATE->m_pCurSong.Set( NULL ); // CurSong will be set if we back out. Set it back to NULL so that ScreenStage won't show the last song. + GAMESTATE->m_PlayMode.Set( PLAY_MODE_ENDLESS ); + GAMESTATE->m_bSideIsJoined[0] = true; + + PROFILEMAN->GetProfile(ProfileSlot_Player1)->m_GoalType = GoalType_Time; + Course *pCourse = GAMESTATE->m_pCurCourse; + PROFILEMAN->GetProfile(ProfileSlot_Player1)->m_iGoalSeconds = pCourse->m_fGoalSeconds; +} + +void EditCourseUtil::GetAllEditCourses( vector &vpCoursesOut ) +{ + vector vpCoursesTemp; + SONGMAN->GetAllCourses( vpCoursesTemp, false ); + FOREACH_CONST( Course*, vpCoursesTemp, c ) + { + if( (*c)->GetLoadedFromProfileSlot() != ProfileSlot_Invalid ) + vpCoursesOut.push_back( *c ); + } +} + +void EditCourseUtil::LoadDefaults( Course &out ) +{ + out = Course(); + + out.m_fGoalSeconds = 0; + + // pick a default name + // XXX: Make this localizable + for( int i=0; i<10000; i++ ) + { + out.m_sMainTitle = ssprintf("Workout %d", i+1); + bool bNameInUse = false; + + vector vpCourses; + EditCourseUtil::GetAllEditCourses( vpCourses ); + FOREACH_CONST( Course*, vpCourses, p ) + { + if( out.m_sMainTitle == (*p)->m_sMainTitle ) + { + bNameInUse = true; + break; + } + } + + if( !bNameInUse ) + break; + } + + vector vpSongs; + SONGMAN->GetPreferredSortSongs( vpSongs ); + for( int i=0; i<(int)vpSongs.size() && i<6; i++ ) + { + CourseEntry ce; + ce.songID.FromSong( vpSongs[i] ); + ce.stepsCriteria.m_difficulty = Difficulty_Easy; + out.m_vEntries.push_back( ce ); + } +} ////////////////////////////////// // CourseID diff --git a/stepmania/src/CourseUtil.h b/stepmania/src/CourseUtil.h index c8f82178ab..bde71be95c 100644 --- a/stepmania/src/CourseUtil.h +++ b/stepmania/src/CourseUtil.h @@ -38,6 +38,28 @@ namespace CourseUtil void WarnOnInvalidMods( RString sMods ); }; +namespace EditCourseUtil +{ + void UpdateAndSetTrail(); + void PrepareForPlay(); + void LoadDefaults( Course &out ); + bool RemoveAndDeleteFile( Course *pCourse ); + bool ValidateEditCourseName( const RString &sAnswer, RString &sErrorOut ); + void GetAllEditCourses( vector &vpCoursesOut ); + bool Save( Course *pCourse ); + bool RenameAndSave( Course *pCourse, RString sName ); + + bool ValidateEditCourseNametName( const RString &sAnswer, RString &sErrorOut ); + + extern int MAX_NAME_LENGTH; + extern int MAX_PER_PROFILE; + extern int MIN_WORKOUT_MINUTES; + extern int MAX_WORKOUT_MINUTES; + + extern bool s_bNewCourseNeedsName; // if true, we are working with a Course that has never been named +}; + + class CourseID { public: diff --git a/stepmania/src/GameState.cpp b/stepmania/src/GameState.cpp index 418ccf127b..e528938b31 100644 --- a/stepmania/src/GameState.cpp +++ b/stepmania/src/GameState.cpp @@ -37,7 +37,6 @@ #include "UnlockManager.h" #include "ScreenManager.h" #include "Screen.h" -#include "WorkoutManager.h" #include #include diff --git a/stepmania/src/PercentageDisplay.cpp b/stepmania/src/PercentageDisplay.cpp index dfce9b70d4..7fcb50572b 100644 --- a/stepmania/src/PercentageDisplay.cpp +++ b/stepmania/src/PercentageDisplay.cpp @@ -9,7 +9,6 @@ #include "StageStats.h" #include "PlayerState.h" #include "XmlFile.h" -#include "WorkoutManager.h" #include "Course.h" diff --git a/stepmania/src/ScreenGameplay.cpp b/stepmania/src/ScreenGameplay.cpp index b0f9895b13..c3efb5b8d4 100644 --- a/stepmania/src/ScreenGameplay.cpp +++ b/stepmania/src/ScreenGameplay.cpp @@ -58,7 +58,6 @@ #include "SongUtil.h" #include "Song.h" #include "XmlFileUtil.h" -#include "WorkoutManager.h" // // Defines diff --git a/stepmania/src/ScreenOptionsEditPlaylist.cpp b/stepmania/src/ScreenOptionsEditPlaylist.cpp index 1ba53f0ac9..1d43e0240f 100644 --- a/stepmania/src/ScreenOptionsEditPlaylist.cpp +++ b/stepmania/src/ScreenOptionsEditPlaylist.cpp @@ -9,7 +9,7 @@ #include "GameState.h" #include "ScreenPrompt.h" #include "LocalizedString.h" -#include "WorkoutManager.h" +#include "CourseUtil.h" #include "song.h" #include "Style.h" #include "Steps.h" @@ -173,9 +173,9 @@ void ScreenOptionsEditPlaylist::BeginScreen() DEFAULT_FAIL(rowIndex); case WorkoutDetailsRow_Minutes: pHand->m_Def.m_vsChoices.push_back( MakeMinutesString(0) ); - for( int i=MIN_WORKOUT_MINUTES; i<=20; i+=2 ) + for( int i=EditCourseUtil::MIN_WORKOUT_MINUTES; i<=20; i+=2 ) pHand->m_Def.m_vsChoices.push_back( MakeMinutesString(i) ); - for( int i=20; i<=MAX_WORKOUT_MINUTES; i+=5 ) + for( int i=20; i<=EditCourseUtil::MAX_WORKOUT_MINUTES; i+=5 ) pHand->m_Def.m_vsChoices.push_back( MakeMinutesString(i) ); break; } diff --git a/stepmania/src/ScreenOptionsManageCourses.cpp b/stepmania/src/ScreenOptionsManageCourses.cpp index 4b4c96ffbf..41d3ff6303 100644 --- a/stepmania/src/ScreenOptionsManageCourses.cpp +++ b/stepmania/src/ScreenOptionsManageCourses.cpp @@ -18,7 +18,6 @@ #include "CourseWriterCRS.h" #include "RageFileManager.h" #include "PrefsManager.h" -#include "WorkoutManager.h" AutoScreenMessage( SM_BackFromRename ) AutoScreenMessage( SM_BackFromDelete ) diff --git a/stepmania/src/ScreenOptionsManageWorkouts.cpp b/stepmania/src/ScreenOptionsManageWorkouts.cpp index a1120116e7..f8ca14d090 100644 --- a/stepmania/src/ScreenOptionsManageWorkouts.cpp +++ b/stepmania/src/ScreenOptionsManageWorkouts.cpp @@ -11,7 +11,6 @@ #include "ScreenPrompt.h" #include "StatsManager.h" #include "PrefsManager.h" -#include "WorkoutManager.h" #include "ProfileManager.h" #include "GameManager.h" #include "CourseUtil.h" diff --git a/stepmania/src/ScreenOptionsReviewWorkout.cpp b/stepmania/src/ScreenOptionsReviewWorkout.cpp index 5ce8abe04c..7ddb2ddc39 100644 --- a/stepmania/src/ScreenOptionsReviewWorkout.cpp +++ b/stepmania/src/ScreenOptionsReviewWorkout.cpp @@ -11,7 +11,6 @@ #include "SongManager.h" #include "SongUtil.h" #include "ScreenTextEntry.h" -#include "WorkoutManager.h" #include "GameManager.h" #include "Profile.h" #include "ScreenPrompt.h" diff --git a/stepmania/src/StepMania-net2003.vcproj b/stepmania/src/StepMania-net2003.vcproj index 35a187d1f5..cb6106f470 100644 --- a/stepmania/src/StepMania-net2003.vcproj +++ b/stepmania/src/StepMania-net2003.vcproj @@ -3195,12 +3195,6 @@ cl /Zl /nologo /c verstub.cpp /Fo"$(IntDir)"\ - - - - GetDisplayFullTitle() ); -} - -bool EditCourseUtil::RenameAndSave( Course *pCourse, RString sNewName ) -{ - ASSERT( !sNewName.empty() ); - - EditCourseUtil::s_bNewCourseNeedsName = false; - - RString sNewFilePath; - if( pCourse->IsAnEdit() ) - { - sNewFilePath = PROFILEMAN->GetProfileDir(ProfileSlot_Machine) + EDIT_COURSES_SUBDIR + sNewName + ".crs"; - } - else - { - RString sDir, sName, sExt; - splitpath( pCourse->m_sPath, sDir, sName, sExt ); - sNewFilePath = sDir + sNewName + sExt; - } - - // remove the old file if the name is changing - if( !pCourse->m_sPath.empty() && sNewFilePath != pCourse->m_sPath ) - { - FILEMAN->Remove( pCourse->m_sPath ); // not fatal if this fails - FlushDirCache(); - } - - pCourse->m_sMainTitle = sNewName; - pCourse->m_sPath = sNewFilePath; - return CourseWriterCRS::Write( *pCourse, pCourse->m_sPath, false ); -} - -bool EditCourseUtil::RemoveAndDeleteFile( Course *pCourse ) -{ - if( !FILEMAN->Remove( pCourse->m_sPath ) ) - return false; - FILEMAN->Remove( pCourse->GetCacheFilePath() ); - FlushDirCache(); - if( pCourse->IsAnEdit() ) - { - PROFILEMAN->LoadMachineProfile(); - } - else - { - SONGMAN->DeleteCourse( pCourse ); - delete pCourse; - } - return true; -} - -static LocalizedString YOU_MUST_SUPPLY_NAME ( "WorkoutManager", "You must supply a name for your workout." ); -static LocalizedString EDIT_NAME_CONFLICTS ( "WorkoutManager", "The name you chose conflicts with another workout. Please use a different name." ); -static LocalizedString EDIT_NAME_CANNOT_CONTAIN ( "WorkoutManager", "The workout name cannot contain any of the following characters: %s" ); -bool EditCourseUtil::ValidateEditCourseName( const RString &sAnswer, RString &sErrorOut ) -{ - if( sAnswer.empty() ) - { - sErrorOut = YOU_MUST_SUPPLY_NAME; - return false; - } - - static const RString sInvalidChars = "\\/:*?\"<>|"; - if( strpbrk(sAnswer, sInvalidChars) != NULL ) - { - sErrorOut = ssprintf( EDIT_NAME_CANNOT_CONTAIN.GetValue(), sInvalidChars.c_str() ); - return false; - } - - // Check for name conflicts - vector vpCourses; - EditCourseUtil::GetAllEditCourses( vpCourses ); - FOREACH_CONST( Course*, vpCourses, p ) - { - if( GAMESTATE->m_pCurCourse == *p ) - continue; // don't comepare name against ourself - - if( (*p)->GetDisplayFullTitle() == sAnswer ) - { - sErrorOut = EDIT_NAME_CONFLICTS; - return false; - } - } - - return true; -} - -void EditCourseUtil::UpdateAndSetTrail() -{ - StepsType st = GAMESTATE->m_pCurStyle->m_StepsType; - Trail *pTrail = GAMESTATE->m_pCurCourse->GetTrailForceRegenCache( st ); - ASSERT( pTrail ); - GAMESTATE->m_pCurTrail[PLAYER_1].Set( pTrail ); -} - -void EditCourseUtil::PrepareForPlay() -{ - GAMESTATE->m_pCurSong.Set( NULL ); // CurSong will be set if we back out. Set it back to NULL so that ScreenStage won't show the last song. - GAMESTATE->m_PlayMode.Set( PLAY_MODE_ENDLESS ); - GAMESTATE->m_bSideIsJoined[0] = true; - - PROFILEMAN->GetProfile(ProfileSlot_Player1)->m_GoalType = GoalType_Time; - Course *pCourse = GAMESTATE->m_pCurCourse; - PROFILEMAN->GetProfile(ProfileSlot_Player1)->m_iGoalSeconds = pCourse->m_fGoalSeconds; -} - -void EditCourseUtil::GetAllEditCourses( vector &vpCoursesOut ) -{ - vector vpCoursesTemp; - SONGMAN->GetAllCourses( vpCoursesTemp, false ); - FOREACH_CONST( Course*, vpCoursesTemp, c ) - { - if( (*c)->GetLoadedFromProfileSlot() != ProfileSlot_Invalid ) - vpCoursesOut.push_back( *c ); - } -} - -void EditCourseUtil::LoadDefaults( Course &out ) -{ - out = Course(); - - out.m_fGoalSeconds = 0; - - // pick a default name - // XXX: Make this localizable - for( int i=0; i<10000; i++ ) - { - out.m_sMainTitle = ssprintf("Workout %d", i+1); - bool bNameInUse = false; - - vector vpCourses; - EditCourseUtil::GetAllEditCourses( vpCourses ); - FOREACH_CONST( Course*, vpCourses, p ) - { - if( out.m_sMainTitle == (*p)->m_sMainTitle ) - { - bNameInUse = true; - break; - } - } - - if( !bNameInUse ) - break; - } - - vector vpSongs; - SONGMAN->GetPreferredSortSongs( vpSongs ); - for( int i=0; i<(int)vpSongs.size() && i<6; i++ ) - { - CourseEntry ce; - ce.songID.FromSong( vpSongs[i] ); - ce.stepsCriteria.m_difficulty = Difficulty_Easy; - out.m_vEntries.push_back( ce ); - } -} - - -/* - * (c) 2003-2004 Chris Danford - * 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. - */ diff --git a/stepmania/src/WorkoutManager.h b/stepmania/src/WorkoutManager.h deleted file mode 100644 index f1498c2898..0000000000 --- a/stepmania/src/WorkoutManager.h +++ /dev/null @@ -1,53 +0,0 @@ -#ifndef WorkoutManager_H -#define WorkoutManager_H - -class Course; - -const int MIN_WORKOUT_MINUTES = 4; -const int MAX_WORKOUT_MINUTES = 90; - -namespace EditCourseUtil -{ - void UpdateAndSetTrail(); - void PrepareForPlay(); - void LoadDefaults( Course &out ); - bool RemoveAndDeleteFile( Course *pCourse ); - bool ValidateEditCourseName( const RString &sAnswer, RString &sErrorOut ); - void GetAllEditCourses( vector &vpCoursesOut ); - bool Save( Course *pCourse ); - bool RenameAndSave( Course *pCourse, RString sName ); - - bool ValidateEditCourseNametName( const RString &sAnswer, RString &sErrorOut ); - - extern int MAX_NAME_LENGTH; - extern int MAX_PER_PROFILE; - extern bool s_bNewCourseNeedsName; // if true, we are working with a Course that has never been named -}; - - -#endif - -/* - * (c) 2003-2004 Chris Danford - * 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. - */