1180 Loading Grand Prix's from locale directory

This commit is contained in:
konstin 2014-03-06 11:30:51 +01:00
parent c09a3172f1
commit b561f440ba
6 changed files with 138 additions and 93 deletions

View File

@ -144,6 +144,48 @@ void PlayerManager::deletePlayer(PlayerProfile *player)
m_all_players.erase(player); m_all_players.erase(player);
} // deletePlayer } // deletePlayer
// ----------------------------------------------------------------------------
/** This function makes sure that a current player is defined. This is called
* when a screen skipping command line option is given (-N, -R, ...), in
* which case there might not be a current player (if no default player is
* set in players.xml, i.e. the 'remember be' option was not picked ). Since
* a lot of code depends on having a local player, just set the most
* frequently used non-guest to be the current player.
*/
void PlayerManager::enforceCurrentPlayer()
{
if (m_current_player) return;
PlayerProfile *player;
for_in(player, m_all_players)
{
if (!player->isGuestAccount())
{
Log::info("PlayerManager", "Enfocring current player '%ls'.",
player->getName().c_str() );
m_current_player = player;
return;
}
} // for player in m_all_players
// This shouldn't happen - but just in case: add the default players
// again, and search again for a non-guest player.
addDefaultPlayer();
for_in(player, m_all_players)
{
if (!player->isGuestAccount())
{
Log::info("PlayerManager", "Enfocring current player '%s'.",
player->getName().c_str());
m_current_player = player;
return;
}
} // for player in m_all_players
// Now this really really should not happen.
Log::fatal("PlayerManager", "Failed to find a non-guest player.");
} // enforceCurrentPlayer
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
/** Called when no player profiles exists. It creates two players: one /** Called when no player profiles exists. It creates two players: one
* guest player, and one non-guest player for whic hit tries to guess a * guest player, and one non-guest player for whic hit tries to guess a

View File

@ -78,6 +78,7 @@ public:
void deletePlayer(PlayerProfile *player); void deletePlayer(PlayerProfile *player);
void setCurrentPlayer(PlayerProfile *player, bool remember_me); void setCurrentPlayer(PlayerProfile *player, bool remember_me);
const PlayerProfile *getPlayerById(unsigned int id); const PlayerProfile *getPlayerById(unsigned int id);
void enforceCurrentPlayer();
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
/** Returns the current player. */ /** Returns the current player. */
PlayerProfile* getCurrentPlayer() { return m_current_player; } PlayerProfile* getCurrentPlayer() { return m_current_player; }

View File

@ -392,21 +392,19 @@ 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"
" -R, --race-now Same as -N but also skip the ready-set-go phase " " -R, --race-now Same as -N but also skip the ready-set-go phase"
"and the music.\n" " and the music.\n"
" -t, --track=NAME Start at track NAME.\n" " -t, --track=NAME Start at track NAME.\n"
" --gp=NAME Start the specified Grand Prix.\n" " --gp=NAME Start the specified Grand Prix.\n"
" --stk-config=FILE use ./data/FILE instead of "
"./data/stk_config.xml\n"
" --add-gp-dir=DIR Load Grand Prixs in DIR. Setting will be saved " " --add-gp-dir=DIR Load Grand Prixs in DIR. Setting will be saved "
"in config.xml\n" "in config.xml\n"
" --stk-config=FILE use ./data/FILE instead of "
"./data/stk_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"
@ -471,7 +469,8 @@ 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;
@ -501,14 +500,14 @@ int handleCmdLinePreliminary()
if( CommandLine::has( "--stk-config", &s)) if( CommandLine::has( "--stk-config", &s))
{ {
stk_config->load(file_manager->getAsset(s)); stk_config->load(file_manager->getAsset(s));
Log::info("main", "STK config will be read from %s.", s.c_str()); Log::info("main", "STK config will be read from %s.",s.c_str());
} }
if( CommandLine::has( "--trackdir", &s)) if( CommandLine::has( "--trackdir", &s))
TrackManager::addTrackSearchDir(s); TrackManager::addTrackSearchDir(s);
if( CommandLine::has( "--kartdir", &s)) if( CommandLine::has( "--kartdir", &s))
KartPropertiesManager::addKartSearchDir(s); KartPropertiesManager::addKartSearchDir(s);
if( CommandLine::has("--no-graphics") || if( CommandLine::has( "--no-graphics") ||
CommandLine::has("-l" ) ) CommandLine::has("-l" ) )
{ {
ProfileWorld::disableGraphics(); ProfileWorld::disableGraphics();
@ -546,10 +545,9 @@ int handleCmdLinePreliminary()
} }
else else
{ {
Log::fatal("main", "Error: --screensize argument must be given as " Log::fatal("main", "Error: --screensize argument must be "
"WIDTHxHEIGHT"); "given as WIDTHxHEIGHT");
} }
} }
@ -587,12 +585,6 @@ int handleCmdLinePreliminary()
Log::info("main", "=============================="); Log::info("main", "==============================");
} // --verbose or -v } // --verbose or -v
int n;
if(CommandLine::has("--xmas", &n))
UserConfigParams::m_xmas_mode = n;
if(CommandLine::has("--log", &n))
Log::setLogLevel(n);
// Enable loading GP's from local directory // Enable loading GP's from local directory
if(CommandLine::has("--add-gp-dir", &s)) if(CommandLine::has("--add-gp-dir", &s))
{ {
@ -602,10 +594,16 @@ int handleCmdLinePreliminary()
else else
UserConfigParams::m_additional_gp_directory = s + "/"; UserConfigParams::m_additional_gp_directory = s + "/";
Log::info("main", "Additional Grand Prix will be loaded from %s", Log::info("main", "Additional Grand Prix's will be loaded from %s",
UserConfigParams::m_additional_gp_directory.c_str()); UserConfigParams::m_additional_gp_directory.c_str());
} }
int n;
if(CommandLine::has("--xmas", &n))
UserConfigParams::m_xmas_mode = n;
if(CommandLine::has("--log", &n))
Log::setLogLevel(n);
return 0; return 0;
} // handleCmdLinePreliminary } // handleCmdLinePreliminary
@ -1078,18 +1076,43 @@ void initRest()
} // initRest } // initRest
//============================================================================= //=============================================================================
#ifdef BREAKPAD void askForInternetPermission()
bool ShowDumpResults(const wchar_t* dump_path,
const wchar_t* minidump_id,
void* context,
EXCEPTION_POINTERS* exinfo,
MDRawAssertionInfo* assertion,
bool succeeded)
{ {
wprintf(L"Path: %s id %s.\n", dump_path, minidump_id); if (UserConfigParams::m_internet_status ==
return succeeded; Online::RequestManager::IPERM_NOT_ASKED)
} {
#endif class ConfirmServer :
public MessageDialog::IConfirmDialogListener
{
public:
virtual void onConfirm()
{
UserConfigParams::m_internet_status =
Online::RequestManager::IPERM_ALLOWED;
GUIEngine::ModalDialog::dismiss();
} // onConfirm
// --------------------------------------------------------
virtual void onCancel()
{
UserConfigParams::m_internet_status =
Online::RequestManager::IPERM_NOT_ALLOWED;
GUIEngine::ModalDialog::dismiss();
} // onCancel
}; // ConfirmServer
new MessageDialog(_("SuperTuxKart may connect to a server "
"to download add-ons and notify you of updates. Would you "
"like this feature to be enabled? (To change this setting "
"at a later time, go to options, select tab "
"'User Interface', and edit \"Allow STK to connect to the "
"Internet\")."),
MessageDialog::MESSAGE_DIALOG_CONFIRM,
new ConfirmServer(), true);
}
} // askForInternetPermission
//=============================================================================
#if defined(DEBUG) && defined(WIN32) && !defined(__CYGWIN__) #if defined(DEBUG) && defined(WIN32) && !defined(__CYGWIN__)
#pragma comment(linker, "/SUBSYSTEM:console") #pragma comment(linker, "/SUBSYSTEM:console")
@ -1098,10 +1121,6 @@ bool ShowDumpResults(const wchar_t* dump_path,
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
int main(int argc, char *argv[] ) int main(int argc, char *argv[] )
{ {
#ifdef BREAKPAD
google_breakpad::ExceptionHandler eh(L"C:\\Temp", NULL, ShowDumpResults,
NULL, google_breakpad::ExceptionHandler::HANDLER_ALL);
#endif
CommandLine::init(argc, argv); CommandLine::init(argc, argv);
CrashReporting::installHandlers(); CrashReporting::installHandlers();
@ -1161,8 +1180,7 @@ 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( file_manager->pushTextureSearchPath(file_manager->getAsset(FileManager::MODEL,""));
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!="")
@ -1227,40 +1245,15 @@ int main(int argc, char *argv[] )
wiimote_manager->askUserToConnectWiimotes(); wiimote_manager->askUserToConnectWiimotes();
} }
#endif #endif
if(UserConfigParams::m_internet_status == askForInternetPermission();
Online::RequestManager::IPERM_NOT_ASKED)
{
class ConfirmServer :
public MessageDialog::IConfirmDialogListener
{
public:
virtual void onConfirm()
{
UserConfigParams::m_internet_status =
Online::RequestManager::IPERM_ALLOWED;
GUIEngine::ModalDialog::dismiss();
} // onConfirm
// --------------------------------------------------------
virtual void onCancel()
{
UserConfigParams::m_internet_status =
Online::RequestManager::IPERM_NOT_ALLOWED;
GUIEngine::ModalDialog::dismiss();
} // onCancel
}; // ConfirmServer
new MessageDialog(_("SuperTuxKart may connect to a server "
"to download add-ons and notify you of updates. Would you "
"like this feature to be enabled? (To change this setting "
"at a later time, go to options, select tab "
"'User Interface', and edit \"Allow STK to connect to the "
"Internet\")."),
MessageDialog::MESSAGE_DIALOG_CONFIRM,
new ConfirmServer(), true);
}
} }
else else
{ {
// Skip the start screen. This esp. means that no login screen is
// displayed (if necessary), so we have to make sure there is
// a current player
PlayerManager::get()->enforceCurrentPlayer();
InputDevice *device; InputDevice *device;
// Use keyboard 0 by default in --no-start-screen // Use keyboard 0 by default in --no-start-screen

View File

@ -37,10 +37,14 @@ GrandPrixManager::GrandPrixManager()
if (StringUtils::hasSuffix(*i, ".grandprix")) if (StringUtils::hasSuffix(*i, ".grandprix"))
{ {
try try
{ m_gp_data.push_back(new GrandPrixData(*i)); } {
catch (std::logic_error& er) m_gp_data.push_back(new GrandPrixData(*i));
{ Log::error("GrandPrixManager", "Ignoring GP %s ( %s ) \n", }
i->c_str(), er.what()); } catch (std::logic_error& e)
{
Log::error("GrandPrixManager", "Ignoring GP %s ( %s ) \n",
i->c_str(), e.what());
}
} }
} }
@ -54,10 +58,14 @@ GrandPrixManager::GrandPrixManager()
if (StringUtils::hasSuffix(*i, ".grandprix")) if (StringUtils::hasSuffix(*i, ".grandprix"))
{ {
try try
{ m_gp_data.push_back(new GrandPrixData(dir, *i)); } {
catch (std::logic_error& er) m_gp_data.push_back(new GrandPrixData(dir, *i));
{ Log::error("GrandPrixManager", "Ignoring GP %s ( %s ) \n", }
i->c_str(), er.what()); } catch (std::logic_error& e)
{
Log::error("GrandPrixManager", "Ignoring GP %s ( %s ) \n",
i->c_str(), e.what());
}
} }
} }
} }

View File

@ -34,9 +34,10 @@ private:
public: public:
GrandPrixManager(); GrandPrixManager();
~GrandPrixManager(); ~GrandPrixManager();
const GrandPrixData* getGrandPrix(int i) const {return m_gp_data[i]; } void load(const std::string &filename);
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(); }
void checkConsistency(); void checkConsistency();
}; // GrandPrixManager }; // GrandPrixManager