add new tutorial folder and a file containing the configuration
first tutorial configuration file Add to file_manager.cpp the method to check the tutorial file tutorial data, to implement the XML loading git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@7386 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
2fed00594d
commit
840a77ed38
12
data/tutorials/basic_driving.tutorial
Normal file
12
data/tutorials/basic_driving.tutorial
Normal file
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0"?>
|
||||
<challenge
|
||||
id="basic_driving"
|
||||
name="Basic Driving tutorial"
|
||||
description="Come first in the At World's End Grand Prix with 3 Expert AI karts."
|
||||
major="grandprix"
|
||||
minor="timetrial"
|
||||
track="canyon"
|
||||
difficulty="easy"
|
||||
karts="1"
|
||||
num_players="1"
|
||||
/>
|
@ -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.
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
@ -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();
|
||||
|
@ -41,15 +41,14 @@ TutorialManager::TutorialManager()
|
||||
// in main).
|
||||
m_tutorial_manager = this;
|
||||
|
||||
// FIXME : Read tutorials from .../data
|
||||
// -----------------------------
|
||||
std::set<std::string> result;
|
||||
file_manager->listFiles(result, "data/grandprix");
|
||||
file_manager->listFiles(result, "data/tutorials");
|
||||
for(std::set<std::string>::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 << "</challenges>\n\n";
|
||||
//challenge_file.close();
|
||||
} // save
|
||||
//} // save
|
||||
|
||||
|
||||
|
@ -48,7 +48,6 @@ public:
|
||||
~TutorialManager ();
|
||||
void addTutorial (Tutorial * m_tutorial);
|
||||
void addTutorial (const std::string& filename);
|
||||
void save ();
|
||||
|
||||
vector <const Tutorial*> getTutorialsList();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user