diff --git a/data/tutorials/basic_driving.tutorial b/data/tutorials/basic_driving.tutorial new file mode 100644 index 000000000..6b8db034d --- /dev/null +++ b/data/tutorials/basic_driving.tutorial @@ -0,0 +1,12 @@ + + diff --git a/src/io/file_manager.cpp b/src/io/file_manager.cpp index 71f86e89f..f793311b2 100644 --- a/src/io/file_manager.cpp +++ b/src/io/file_manager.cpp @@ -623,6 +623,14 @@ std::string FileManager::getChallengeFile(const std::string &fname) const return getConfigDir()+"/"+fname; } // getChallengeFile +//----------------------------------------------------------------------------- +/** Returns the full path of the tutorial file. */ +std::string FileManager::getTutorialFile(const std::string &fname) const +{ + return getConfigDir()+"/"+fname; +} // getTutorialFile + + //----------------------------------------------------------------------------- /** Returns true if the given name is a directory. * \param path File name to test. diff --git a/src/io/file_manager.hpp b/src/io/file_manager.hpp index bd0e49b8f..7dcdcb2cf 100644 --- a/src/io/file_manager.hpp +++ b/src/io/file_manager.hpp @@ -98,6 +98,7 @@ public: std::string getDataFile (const std::string& fname) const; std::string getHighscoreFile (const std::string& fname) const; std::string getChallengeFile (const std::string& fname) const; + std::string getTutorialFile (const std::string& fname) const; std::string getLogFile (const std::string& fname) const; std::string getItemFile (const std::string& fname) const; std::string getMusicFile (const std::string& fname) const; diff --git a/src/states_screens/tutorial_screen.cpp b/src/states_screens/tutorial_screen.cpp index cef4e47d7..b6ed00493 100644 --- a/src/states_screens/tutorial_screen.cpp +++ b/src/states_screens/tutorial_screen.cpp @@ -168,7 +168,6 @@ void TutorialScreen::eventCallback(GUIEngine::Widget* widget, const std::string& // Launch tutorial //m_tutorial_manager->getTutorial(selection)->setRace(); - // FIXME this code have to be in Tutorial class (and loaded from file xD) RaceManager::MajorRaceModeType m_major; diff --git a/src/tutorial/tutorial_data.cpp b/src/tutorial/tutorial_data.cpp index 5475432c1..83ea0d4c1 100644 --- a/src/tutorial/tutorial_data.cpp +++ b/src/tutorial/tutorial_data.cpp @@ -45,8 +45,12 @@ TutorialData::TutorialData(const std::string& filename) m_track_name = ""; m_gp_id = ""; m_energy = -1; + + std::string s_property; + int i_property; + float f_property; - XMLNode *root = new XMLNode( filename ); + XMLNode *root = new XMLNode( filename ); // Check if the file have been load correctly if(!root || root->getName()!="tutorial") @@ -56,85 +60,52 @@ TutorialData::TutorialData(const std::string& filename) msg << "Couldn't load tutorial '" << filename << "': no tutorial node."; throw std::runtime_error(msg.str()); } - - std::string s_property; - int i_property; - float f_property; - - // Mode - root->get("major", &s_property); - setMajor(s_property); - - // Minor - root->get("minor", &s_property); - setMinor(s_property); - - // Name - if(!root->get("name", &s_property) ) - error("name"); - setName( _(s_property.c_str()) ); + // Start the loading process (ordered as it is on the file) // ID if(!root->get("id", &s_property) ) error("id"); setId(s_property); + // Name + if(!root->get("name", &s_property) ) + error("name"); + setName( _(s_property.c_str()) ); + // Description if(!root->get("s_property", &s_property) ) error("description"); setTutorialDescription( _(s_property.c_str()) ); + + // Major + root->get("major", &s_property); + setMajor(s_property); + + // Minor + root->get("minor", &s_property); + setMinor(s_property); // Karts if(!root->get("karts", &i_property) ) error("karts"); setNumKarts(i_property); + // Difficulty root->get("difficulty", &s_property); setDifficulty(s_property); - // Time - root->get("time", &f_property); // one of time/position - setTime(f_property); - - // Position - root->get("position", &m_position ); // must be set - if(m_time<0 && m_position<0) - error("position/time"); - - // Energy - root->get("energy", & i_property ); // This is optional - setEnergy(i_property); - - // FIXME do we need position for the tutorials??????? - // Position is optional except in GP and FTL - /*if(!root->get("position", &s_property)) - error("position"); - set - && - //RaceManager::getWorld()->areKartsOrdered() ) // FIXME - order and optional are not the same thing - (m_minor==RaceManager::MINOR_MODE_FOLLOW_LEADER || - m_major==RaceManager::MAJOR_MODE_GRAND_PRIX)) - error("position");*/ - if(m_major==RaceManager::MAJOR_MODE_SINGLE) { // Track if (!root->get("track", &s_property )) error("track"); setTrack(s_property); - - if (!root->get("laps", &i_property)) - error("laps"); - setLaps(i_property); - } - else // GP - { - if (!root->get("gp", &m_gp_id )) error("gp"); - if (grand_prix_manager->getGrandPrix(m_gp_id) == NULL) error("gp"); } - + // Num Players + root->get("num_players", &i_property); + setNumPlayers(i_property); delete root; } // TutorialData @@ -152,7 +123,7 @@ void TutorialData::error(const char *id) const } // error // ---------------------------------------------------------------------------- -/** Checks if this challenge is valid, i.e. contains a valid track or a valid +/** Checks if this tutorial is valid, i.e. contains a valid track or a valid * GP. If incorrect data are found, STK is aborted with an error message. * (otherwise STK aborts when trying to do this challenge, which is worse). */ @@ -334,3 +305,8 @@ void TutorialData::setEnergy(int energy) { m_energy = energy; } + +void TutorialData::setNumPlayers (int num_players) +{ + this->m_num_players = num_players; +} \ No newline at end of file diff --git a/src/tutorial/tutorial_data.hpp b/src/tutorial/tutorial_data.hpp index 67afac240..c8165f2be 100644 --- a/src/tutorial/tutorial_data.hpp +++ b/src/tutorial/tutorial_data.hpp @@ -43,6 +43,8 @@ private: std::string m_track_name; int m_energy; std::string m_filename; + int m_num_players; + // void getUnlocks(const XMLNode *root, const std:: string type, REWARD_TYPE reward); void error(const char *id) const; @@ -66,6 +68,7 @@ public: void setMajor(std::string major); void setMinor(std::string minor); void setNumKarts(int num_karts); + void setNumPlayers(int num_players); virtual void check() const; virtual bool raceFinished(); diff --git a/src/tutorial/tutorial_manager.cpp b/src/tutorial/tutorial_manager.cpp index 48574847b..2f2241154 100644 --- a/src/tutorial/tutorial_manager.cpp +++ b/src/tutorial/tutorial_manager.cpp @@ -41,15 +41,14 @@ TutorialManager::TutorialManager() // in main). m_tutorial_manager = this; - // FIXME : Read tutorials from .../data // ----------------------------- std::set result; - file_manager->listFiles(result, "data/grandprix"); + file_manager->listFiles(result, "data/tutorials"); for(std::set::iterator i = result.begin(); i != result.end() ; i++) { if (StringUtils::hasSuffix(*i, ".tutorial")) - addTutorial(file_manager->getDataFile("grandprix/"+*i)); + addTutorial(file_manager->getDataFile("tutorials/"+*i)); } // Hard coded challenges can be added here. @@ -125,7 +124,7 @@ void TutorialManager::load() { std::cerr << "Tutorial file '" << filename << "' will be created." << std::endl; - save(); + //save(); if (root) delete root; return; @@ -139,10 +138,11 @@ void TutorialManager::load() delete root; } // load + //----------------------------------------------------------------------------- -void TutorialManager::save() -{ - std::ofstream tutorial_file; +//void TutorialManager::save() +//{ +// std::ofstream tutorial_file; //std::string filename = file_manager->getChallengeFile("tutorial.xml"); //challenge_file.open(filename.c_str()); @@ -163,6 +163,6 @@ void TutorialManager::save() // //challenge_file << "\n\n"; //challenge_file.close(); -} // save +//} // save diff --git a/src/tutorial/tutorial_manager.hpp b/src/tutorial/tutorial_manager.hpp index 569595d25..0d8c95c19 100644 --- a/src/tutorial/tutorial_manager.hpp +++ b/src/tutorial/tutorial_manager.hpp @@ -48,7 +48,6 @@ public: ~TutorialManager (); void addTutorial (Tutorial * m_tutorial); void addTutorial (const std::string& filename); - void save (); vector getTutorialsList();