Solving Issue 1180 - Load addon GPs from local folder
This commit is contained in:
parent
8600d3bc61
commit
c09a3172f1
@ -396,6 +396,9 @@ namespace UserConfigParams
|
|||||||
PARAM_DEFAULT( BoolUserConfigParam(false, "player_last",
|
PARAM_DEFAULT( BoolUserConfigParam(false, "player_last",
|
||||||
&m_gp_start_order,
|
&m_gp_start_order,
|
||||||
"Always put the player at the back or not (Bully mode).") );
|
"Always put the player at the back or not (Bully mode).") );
|
||||||
|
PARAM_PREFIX StringUserConfigParam m_additional_gp_directory
|
||||||
|
PARAM_DEFAULT( StringUserConfigParam("", "additional_gp_directory",
|
||||||
|
"Directory with additional GP's."));
|
||||||
|
|
||||||
// ---- Video
|
// ---- Video
|
||||||
PARAM_PREFIX GroupUserConfigParam m_video_group
|
PARAM_PREFIX GroupUserConfigParam m_video_group
|
||||||
|
@ -112,7 +112,8 @@ public:
|
|||||||
void checkAndCreateDirForAddons(const std::string &dir);
|
void checkAndCreateDirForAddons(const std::string &dir);
|
||||||
bool removeFile(const std::string &name) const;
|
bool removeFile(const std::string &name) const;
|
||||||
bool removeDirectory(const std::string &name) const;
|
bool removeDirectory(const std::string &name) const;
|
||||||
std::vector<std::string>getMusicDirs() const;
|
std::vector<std::string>
|
||||||
|
getMusicDirs() const;
|
||||||
std::string getAssetChecked(AssetType type, const std::string& name,
|
std::string getAssetChecked(AssetType type, const std::string& name,
|
||||||
bool abort_on_error=false) const;
|
bool abort_on_error=false) const;
|
||||||
std::string getAsset(AssetType type, const std::string &name) const;
|
std::string getAsset(AssetType type, const std::string &name) const;
|
||||||
|
28
src/main.cpp
28
src/main.cpp
@ -392,8 +392,10 @@ void cmdLineHelp()
|
|||||||
{
|
{
|
||||||
Log::info("main",
|
Log::info("main",
|
||||||
"Usage: %s [OPTIONS]\n\n"
|
"Usage: %s [OPTIONS]\n\n"
|
||||||
|
|
||||||
"Run SuperTuxKart, a racing game with go-kart that features"
|
"Run SuperTuxKart, a racing game with go-kart that features"
|
||||||
" the Tux and friends.\n\n"
|
" the Tux and friends.\n\n"
|
||||||
|
|
||||||
"Options:\n"
|
"Options:\n"
|
||||||
" -N, --no-start-screen Immediately start race without showing a "
|
" -N, --no-start-screen Immediately start race without showing a "
|
||||||
"menu.\n"
|
"menu.\n"
|
||||||
@ -403,6 +405,8 @@ void cmdLineHelp()
|
|||||||
" --gp=NAME Start the specified Grand Prix.\n"
|
" --gp=NAME Start the specified Grand Prix.\n"
|
||||||
" --stk-config=FILE use ./data/FILE instead of "
|
" --stk-config=FILE use ./data/FILE instead of "
|
||||||
"./data/stk_config.xml\n"
|
"./data/stk_config.xml\n"
|
||||||
|
" --add-gp-dir=DIR Load Grand Prixs in DIR. Setting will be saved "
|
||||||
|
"in config.xml\n"
|
||||||
" -k, --numkarts=NUM Number of karts on the racetrack.\n"
|
" -k, --numkarts=NUM Number of karts on the racetrack.\n"
|
||||||
" --kart=NAME Use kart number NAME.\n"
|
" --kart=NAME Use kart number NAME.\n"
|
||||||
" --ai=a,b,... Use the karts a, b, ... for the AI.\n"
|
" --ai=a,b,... Use the karts a, b, ... for the AI.\n"
|
||||||
@ -467,8 +471,7 @@ int handleCmdLinePreliminary()
|
|||||||
cmdLineHelp();
|
cmdLineHelp();
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
if( CommandLine::has("--gamepad-visualisation") ||
|
if( CommandLine::has("--gamepad-visualisation") )
|
||||||
CommandLine::has("--gamepad-visualization") )
|
|
||||||
UserConfigParams::m_gamepad_visualisation=true;
|
UserConfigParams::m_gamepad_visualisation=true;
|
||||||
if( CommandLine::has("--debug=memory"))
|
if( CommandLine::has("--debug=memory"))
|
||||||
UserConfigParams::m_verbosity |= UserConfigParams::LOG_MEMORY;
|
UserConfigParams::m_verbosity |= UserConfigParams::LOG_MEMORY;
|
||||||
@ -543,9 +546,10 @@ int handleCmdLinePreliminary()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Log::fatal("main", "Error: --screensize argument must be "
|
Log::fatal("main", "Error: --screensize argument must be given as "
|
||||||
"given as WIDTHxHEIGHT");
|
"WIDTHxHEIGHT");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -589,6 +593,19 @@ int handleCmdLinePreliminary()
|
|||||||
if(CommandLine::has("--log", &n))
|
if(CommandLine::has("--log", &n))
|
||||||
Log::setLogLevel(n);
|
Log::setLogLevel(n);
|
||||||
|
|
||||||
|
// Enable loading GP's from local directory
|
||||||
|
if(CommandLine::has("--add-gp-dir", &s))
|
||||||
|
{
|
||||||
|
// Ensure that the path ends with a /
|
||||||
|
if (s[s.size()] == '/')
|
||||||
|
UserConfigParams::m_additional_gp_directory = s;
|
||||||
|
else
|
||||||
|
UserConfigParams::m_additional_gp_directory = s + "/";
|
||||||
|
|
||||||
|
Log::info("main", "Additional Grand Prix will be loaded from %s",
|
||||||
|
UserConfigParams::m_additional_gp_directory.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
} // handleCmdLinePreliminary
|
} // handleCmdLinePreliminary
|
||||||
|
|
||||||
@ -1144,7 +1161,8 @@ int main(int argc, char *argv[] )
|
|||||||
// Both item_manager and powerup_manager load models and therefore
|
// Both item_manager and powerup_manager load models and therefore
|
||||||
// textures from the model directory. To avoid reading the
|
// textures from the model directory. To avoid reading the
|
||||||
// materials.xml twice, we do this here once for both:
|
// materials.xml twice, we do this here once for both:
|
||||||
file_manager->pushTextureSearchPath(file_manager->getAsset(FileManager::MODEL,""));
|
file_manager->pushTextureSearchPath(file_manager->getAsset(
|
||||||
|
FileManager::MODEL,""));
|
||||||
const std::string materials_file =
|
const std::string materials_file =
|
||||||
file_manager->getAsset(FileManager::MODEL,"materials.xml");
|
file_manager->getAsset(FileManager::MODEL,"materials.xml");
|
||||||
if(materials_file!="")
|
if(materials_file!="")
|
||||||
|
@ -32,15 +32,29 @@
|
|||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
GrandPrixData::GrandPrixData(const std::string filename) throw(std::logic_error)
|
GrandPrixData::GrandPrixData(const std::string filename) throw(std::logic_error)
|
||||||
|
{
|
||||||
|
load_from_file(file_manager->getAsset(FileManager::GRANDPRIX, filename),
|
||||||
|
filename);
|
||||||
|
}
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
GrandPrixData::GrandPrixData(const std::string dir, const std::string filename)
|
||||||
|
throw(std::logic_error)
|
||||||
|
{
|
||||||
|
assert(dir[dir.size()] == '/');
|
||||||
|
load_from_file(dir + filename, filename);
|
||||||
|
}
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
void GrandPrixData::load_from_file(const std::string fullpath,
|
||||||
|
const std::string filename)
|
||||||
{
|
{
|
||||||
m_filename = filename;
|
m_filename = filename;
|
||||||
m_id = StringUtils::getBasename(StringUtils::removeExtension(filename));
|
m_id = StringUtils::getBasename(StringUtils::removeExtension(filename));
|
||||||
|
|
||||||
XMLNode* root = file_manager->createXMLTree(file_manager->getAsset(FileManager::GRANDPRIX,filename));
|
XMLNode * root = file_manager->createXMLTree(fullpath);
|
||||||
if (!root)
|
if (!root)
|
||||||
{
|
{
|
||||||
Log::error("GrandPrixData","Error while trying to read grandprix file '%s'",
|
Log::error("GrandPrixData","Error while trying to read grandprix file "
|
||||||
filename.c_str());
|
"'%s'", fullpath.c_str());
|
||||||
throw std::logic_error("File not found");
|
throw std::logic_error("File not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,8 +65,9 @@ GrandPrixData::GrandPrixData(const std::string filename) throw(std::logic_error)
|
|||||||
std::string temp_name;
|
std::string temp_name;
|
||||||
if (root->get("name", &temp_name) == 0)
|
if (root->get("name", &temp_name) == 0)
|
||||||
{
|
{
|
||||||
Log::error("GrandPrixData", "Error while trying to read grandprix file '%s' : "
|
Log::error("GrandPrixData", "Error while trying to read grandprix "
|
||||||
"missing 'name' attribute\n", filename.c_str());
|
"file '%s' : missing 'name' attribute\n",
|
||||||
|
fullpath.c_str());
|
||||||
delete root;
|
delete root;
|
||||||
throw std::logic_error("File contents are incomplete or corrupt");
|
throw std::logic_error("File contents are incomplete or corrupt");
|
||||||
}
|
}
|
||||||
@ -61,8 +76,9 @@ GrandPrixData::GrandPrixData(const std::string filename) throw(std::logic_error)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Log::error("GrandPrixData", "Error while trying to read grandprix file '%s' : "
|
Log::error("GrandPrixData", "Error while trying to read grandprix file "
|
||||||
"Root node has an unexpected name\n", filename.c_str());
|
"'%s' : Root node has an unexpected name\n",
|
||||||
|
fullpath.c_str());
|
||||||
delete root;
|
delete root;
|
||||||
throw std::logic_error("File contents are incomplete or corrupt");
|
throw std::logic_error("File contents are incomplete or corrupt");
|
||||||
}
|
}
|
||||||
@ -87,11 +103,13 @@ GrandPrixData::GrandPrixData(const std::string filename) throw(std::logic_error)
|
|||||||
|
|
||||||
if (!idFound || !lapFound)
|
if (!idFound || !lapFound)
|
||||||
{
|
{
|
||||||
Log::error("GrandPrixData", "Error while trying to read grandprix file '%s' : "
|
Log::error("GrandPrixData", "Error while trying to read "
|
||||||
"<track> tag does not have idi and laps reverse attributes. \n",
|
"grandprix file '%s' : <track> tag does not have "
|
||||||
filename.c_str());
|
"idi and laps reverse attributes. \n",
|
||||||
|
fullpath.c_str());
|
||||||
delete root;
|
delete root;
|
||||||
throw std::logic_error("File contents are incomplete or corrupt");
|
throw std::logic_error("File contents are incomplete or "
|
||||||
|
"corrupt");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure the track really is reversible
|
// Make sure the track really is reversible
|
||||||
@ -110,22 +128,22 @@ GrandPrixData::GrandPrixData(const std::string filename) throw(std::logic_error)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::cerr << "Unknown node in Grand Prix XML file : " << node->getName().c_str() << std::endl;
|
Log::error("Unknown node in Grand Prix XML file: %s/n",
|
||||||
|
node->getName().c_str());
|
||||||
delete root;
|
delete root;
|
||||||
throw std::runtime_error("Unknown node in sfx XML file");
|
throw std::runtime_error("Unknown node in sfx XML file");
|
||||||
}
|
}
|
||||||
}// nend for
|
}// end for
|
||||||
|
|
||||||
delete root;
|
delete root;
|
||||||
|
|
||||||
// sanity checks
|
// sanity checks
|
||||||
if (!foundName)
|
if (!foundName)
|
||||||
{
|
{
|
||||||
Log::error("GrandPrixData", "Error while trying to read grandprix file '%s' : "
|
Log::error("GrandPrixData", "Error while trying to read grandprix file "
|
||||||
"missing 'name' attribute\n", filename.c_str());
|
"'%s' : missing 'name' attribute\n", fullpath.c_str());
|
||||||
throw std::logic_error("File contents are incomplete or corrupt");
|
throw std::logic_error("File contents are incomplete or corrupt");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
bool GrandPrixData::checkConsistency(bool chatty) const
|
bool GrandPrixData::checkConsistency(bool chatty) const
|
||||||
@ -149,7 +167,6 @@ bool GrandPrixData::checkConsistency(bool chatty) const
|
|||||||
return true;
|
return true;
|
||||||
} // checkConsistency
|
} // checkConsistency
|
||||||
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
/** Returns true if the track is available. This is used to test if Fort Magma
|
/** Returns true if the track is available. This is used to test if Fort Magma
|
||||||
* is available (this way FortMagma is not used in the last Grand Prix in
|
* is available (this way FortMagma is not used in the last Grand Prix in
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
#include "utils/translation.hpp"
|
#include "utils/translation.hpp"
|
||||||
|
#include "io/file_manager.hpp"
|
||||||
|
|
||||||
/** Simple class that hold the data relevant to a 'grand_prix', aka. a number
|
/** Simple class that hold the data relevant to a 'grand_prix', aka. a number
|
||||||
* of races that has to be completed one after the other
|
* of races that has to be completed one after the other
|
||||||
@ -34,6 +35,7 @@
|
|||||||
*/
|
*/
|
||||||
class GrandPrixData
|
class GrandPrixData
|
||||||
{
|
{
|
||||||
|
private:
|
||||||
/** The name of the grand prix. */
|
/** The name of the grand prix. */
|
||||||
irr::core::stringw m_name;
|
irr::core::stringw m_name;
|
||||||
|
|
||||||
@ -63,6 +65,7 @@ class GrandPrixData
|
|||||||
/** Whether the track in question should be done in reverse mode */
|
/** Whether the track in question should be done in reverse mode */
|
||||||
std::vector<bool> m_reversed;
|
std::vector<bool> m_reversed;
|
||||||
|
|
||||||
|
void load_from_file(const std::string fullpath, const std::string filename);
|
||||||
bool isTrackAvailable(const std::string &id) const;
|
bool isTrackAvailable(const std::string &id) const;
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -70,8 +73,11 @@ public:
|
|||||||
#if (defined(WIN32) || defined(_WIN32)) && !defined(__MINGW32__)
|
#if (defined(WIN32) || defined(_WIN32)) && !defined(__MINGW32__)
|
||||||
#pragma warning(disable:4290)
|
#pragma warning(disable:4290)
|
||||||
#endif
|
#endif
|
||||||
GrandPrixData (const std::string filename) throw(std::logic_error);
|
|
||||||
GrandPrixData () {}; // empty for initialising
|
GrandPrixData () {}; // empty for initialising
|
||||||
|
GrandPrixData (const std::string filename) throw(std::logic_error);
|
||||||
|
GrandPrixData (const std::string dir, const std::string filename)
|
||||||
|
throw(std::logic_error);
|
||||||
|
|
||||||
|
|
||||||
bool checkConsistency(bool chatty=true) const;
|
bool checkConsistency(bool chatty=true) const;
|
||||||
const std::vector<std::string>& getTrackNames() const;
|
const std::vector<std::string>& getTrackNames() const;
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#include <set>
|
#include <set>
|
||||||
#include "io/file_manager.hpp"
|
#include "io/file_manager.hpp"
|
||||||
#include "utils/string_utils.hpp"
|
#include "utils/string_utils.hpp"
|
||||||
|
#include "config/user_config.hpp"
|
||||||
|
|
||||||
GrandPrixManager *grand_prix_manager = NULL;
|
GrandPrixManager *grand_prix_manager = NULL;
|
||||||
|
|
||||||
@ -33,10 +34,34 @@ GrandPrixManager::GrandPrixManager()
|
|||||||
for(std::set<std::string>::iterator i = result.begin();
|
for(std::set<std::string>::iterator i = result.begin();
|
||||||
i != result.end() ; i++)
|
i != result.end() ; i++)
|
||||||
{
|
{
|
||||||
if (StringUtils::hasSuffix(*i, ".grandprix")) load(*i);
|
if (StringUtils::hasSuffix(*i, ".grandprix"))
|
||||||
} // for i
|
{
|
||||||
} // GrandPrixManager
|
try
|
||||||
|
{ m_gp_data.push_back(new GrandPrixData(*i)); }
|
||||||
|
catch (std::logic_error& er)
|
||||||
|
{ Log::error("GrandPrixManager", "Ignoring GP %s ( %s ) \n",
|
||||||
|
i->c_str(), er.what()); }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load additional Grand Prixs
|
||||||
|
const std::string dir = UserConfigParams::m_additional_gp_directory;
|
||||||
|
if(dir != "") {
|
||||||
|
file_manager->listFiles(result, dir);
|
||||||
|
for(std::set<std::string>::iterator i = result.begin();
|
||||||
|
i != result.end() ; i++)
|
||||||
|
{
|
||||||
|
if (StringUtils::hasSuffix(*i, ".grandprix"))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{ m_gp_data.push_back(new GrandPrixData(dir, *i)); }
|
||||||
|
catch (std::logic_error& er)
|
||||||
|
{ Log::error("GrandPrixManager", "Ignoring GP %s ( %s ) \n",
|
||||||
|
i->c_str(), er.what()); }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} // GrandPrixManager
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
GrandPrixManager::~GrandPrixManager()
|
GrandPrixManager::~GrandPrixManager()
|
||||||
{
|
{
|
||||||
@ -50,22 +75,11 @@ GrandPrixManager::~GrandPrixManager()
|
|||||||
const GrandPrixData* GrandPrixManager::getGrandPrix(const std::string& s) const
|
const GrandPrixData* GrandPrixManager::getGrandPrix(const std::string& s) const
|
||||||
{
|
{
|
||||||
for(unsigned int i=0; i<m_gp_data.size(); i++)
|
for(unsigned int i=0; i<m_gp_data.size(); i++)
|
||||||
if(m_gp_data[i]->getId()==s) return m_gp_data[i];
|
if(m_gp_data[i]->getId() == s)
|
||||||
|
return m_gp_data[i];
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
} // getGrandPrix
|
} // getGrandPrix
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
void GrandPrixManager::load(const std::string& filename)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
m_gp_data.push_back(new GrandPrixData(filename));
|
|
||||||
}
|
|
||||||
catch (std::logic_error& er)
|
|
||||||
{
|
|
||||||
Log::error("GrandPrixManager", "Ignoring GP %s ( %s ) \n", filename.c_str(), er.what());
|
|
||||||
}
|
|
||||||
} // load
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
void GrandPrixManager::checkConsistency()
|
void GrandPrixManager::checkConsistency()
|
||||||
{
|
{
|
||||||
|
@ -34,7 +34,6 @@ private:
|
|||||||
public:
|
public:
|
||||||
GrandPrixManager();
|
GrandPrixManager();
|
||||||
~GrandPrixManager();
|
~GrandPrixManager();
|
||||||
void load(const std::string &filename);
|
|
||||||
const GrandPrixData* getGrandPrix(int i) const {return m_gp_data[i]; }
|
const GrandPrixData* getGrandPrix(int i) const {return m_gp_data[i]; }
|
||||||
const GrandPrixData* getGrandPrix(const std::string& s) const;
|
const GrandPrixData* getGrandPrix(const std::string& s) const;
|
||||||
unsigned int getNumberOfGrandPrix() const {return m_gp_data.size();}
|
unsigned int getNumberOfGrandPrix() const {return m_gp_data.size();}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user