-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c61ab02
commit 7f78b5b
Showing
14 changed files
with
563 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
// | ||
// SuperTuxKart - a fun racing game with go-kart | ||
// Copyright (C) 2012-2015 SuperTuxKart-Team | ||
// | ||
// This program is free software; you can redistribute it and/or | ||
// modify it under the terms of the GNU General Public License | ||
// as published by the Free Software Foundation; either version 3 | ||
// of the License, or (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with this program; if not, write to the Free Software | ||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
|
||
#include "config/favorite_track_status.hpp" | ||
|
||
#include "config/player_manager.hpp" | ||
#include "io/utf_writer.hpp" | ||
#include "io/xml_node.hpp" | ||
#include "utils/string_utils.hpp" | ||
|
||
const std::string FavoriteTrackStatus::DEFAULT_FAVORITE_GROUP_NAME = "Favorites"; | ||
|
||
//------------------------------------------------------------------------------ | ||
FavoriteTrackStatus::FavoriteTrackStatus(const XMLNode* node) | ||
{ | ||
std::vector<XMLNode*> xml_favorite_tracks; | ||
std::vector<XMLNode*> xml_favorite_groups; | ||
|
||
if (node) | ||
{ | ||
node->getNodes("track", xml_favorite_tracks); | ||
node->getNodes("group", xml_favorite_groups); | ||
} | ||
for (unsigned int i = 0; i < xml_favorite_tracks.size(); i++) | ||
{ | ||
std::string temp_string; | ||
xml_favorite_tracks[i]->get("ident", &temp_string); | ||
m_favorite_tracks[DEFAULT_FAVORITE_GROUP_NAME].insert(temp_string); | ||
} | ||
for (unsigned int i = 0; i < xml_favorite_groups.size(); i++) | ||
{ | ||
std::string temp_group_string; | ||
std::vector<XMLNode*> temp_group; | ||
|
||
xml_favorite_groups[i]->get("name", &temp_group_string); | ||
xml_favorite_groups[i]->getNodes("track", temp_group); | ||
|
||
for (unsigned int j = 0; j < temp_group.size(); j++) | ||
{ | ||
std::string temp_string; | ||
temp_group[j]->get("ident", &temp_string); | ||
m_favorite_tracks[temp_group_string].insert(temp_string); | ||
} | ||
} | ||
} // FavoriteTrackStatus | ||
|
||
//------------------------------------------------------------------------------ | ||
FavoriteTrackStatus::~FavoriteTrackStatus() | ||
{ | ||
|
||
} // ~FavoriteTrackStatus | ||
|
||
//------------------------------------------------------------------------------ | ||
/** Adds a new favorite track to this player profile and to the group | ||
* of favorite tracks of the Track Manager. | ||
* To be used only if this player profile is the current player. | ||
*/ | ||
bool FavoriteTrackStatus::isFavoriteTrack(std::string ident) | ||
{ | ||
return m_favorite_tracks[DEFAULT_FAVORITE_GROUP_NAME].find(ident) | ||
!= m_favorite_tracks[DEFAULT_FAVORITE_GROUP_NAME].end(); | ||
} // addFavoriteTrack | ||
|
||
//------------------------------------------------------------------------------ | ||
/** Adds a new favorite track to this player profile and to the group | ||
* of favorite tracks of the Track Manager. | ||
*/ | ||
void FavoriteTrackStatus::addFavoriteTrack(std::string ident, std::string group) | ||
{ | ||
m_favorite_tracks[group].insert(ident); | ||
} // addFavoriteTrack | ||
|
||
//------------------------------------------------------------------------------ | ||
/** Removes a favorite track from this player profile and from the group | ||
* of favorite tracks of the Track Manager. | ||
*/ | ||
void FavoriteTrackStatus::removeFavoriteTrack(std::string ident, std::string group) | ||
{ | ||
if (m_favorite_tracks[group].find(ident) != m_favorite_tracks[group].end()) | ||
{ | ||
m_favorite_tracks[group].erase(ident); | ||
} | ||
} // removeFavoriteTrack | ||
|
||
//------------------------------------------------------------------------------ | ||
/** Writes the data for this player to the specified UTFWriter. | ||
* \param out The utf writer to write the data to. | ||
*/ | ||
void FavoriteTrackStatus::save(UTFWriter &out) | ||
{ | ||
out << " <favorites>\n"; | ||
for (auto it_group = m_favorite_tracks.begin(); it_group != m_favorite_tracks.end(); it_group++) | ||
{ | ||
std::string group_name = it_group->first; | ||
|
||
if (group_name == DEFAULT_FAVORITE_GROUP_NAME) | ||
{ | ||
for (auto it_track = it_group->second.begin(); it_track != it_group->second.end(); it_track++) | ||
{ | ||
out << " <track ident=\"" << *it_track << "\"/>\n"; | ||
} | ||
} | ||
else | ||
{ | ||
out << " <group name=\"" << group_name << "\">\n"; | ||
for (auto it_track = it_group->second.begin(); it_track != it_group->second.end(); it_track++) | ||
{ | ||
out << " <track ident=\"" << *it_track << "\"/>\n"; | ||
} | ||
out << " </group>\n"; | ||
} | ||
} | ||
out << " </favorites>\n"; | ||
} // save |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// | ||
// SuperTuxKart - a fun racing game with go-kart | ||
// Copyright (C) 2024 SuperTuxKart-Team | ||
// | ||
// This program is free software; you can redistribute it and/or | ||
// modify it under the terms of the GNU General Public License | ||
// as published by the Free Software Foundation; either version 3 | ||
// of the License, or (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with this program; if not, write to the Free Software | ||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
|
||
#ifndef HEADER_FAVORITE_TRACK_STATUS_HPP | ||
#define HEADER_FAVORITE_TRACK_STATUS_HPP | ||
|
||
#include "utils/leak_check.hpp" | ||
|
||
#include <irrString.h> | ||
|
||
#include <set> | ||
#include <string> | ||
#include <unordered_map> | ||
|
||
using namespace irr; | ||
|
||
class TrackManager; | ||
class UTFWriter; | ||
class XMLNode; | ||
|
||
/** Class for managing player profiles (name, usage frequency, | ||
* etc.). All PlayerProfiles are managed by the PlayerManager. | ||
* A PlayerProfile keeps track of the story mode progress using an instance | ||
* of StoryModeStatus, and achievements with AchievementsStatus. All data | ||
* is saved in the players.xml file. | ||
* This class also defines the interface for handling online data. All of | ||
* the online handling is done in the derived class OnlinePlayerProfile, | ||
* where the interface is fully implemented. | ||
* \ingroup config | ||
*/ | ||
class FavoriteTrackStatus | ||
{ | ||
private: | ||
LEAK_CHECK() | ||
|
||
/** unordered_map<Group Name, set<Track Name> > .*/ | ||
std::unordered_map<std::string, std::set<std::string> > m_favorite_tracks; | ||
|
||
public: | ||
friend class TrackManager; | ||
|
||
static const std::string DEFAULT_FAVORITE_GROUP_NAME; | ||
|
||
FavoriteTrackStatus(const XMLNode *node); | ||
|
||
virtual ~FavoriteTrackStatus(); | ||
|
||
void save(UTFWriter &out); | ||
|
||
bool isFavoriteTrack(std::string ident); | ||
|
||
void addFavoriteTrack(std::string ident, std::string group = DEFAULT_FAVORITE_GROUP_NAME); | ||
|
||
void removeFavoriteTrack(std::string ident, std::string group = DEFAULT_FAVORITE_GROUP_NAME); | ||
}; // class PlayerProfile | ||
|
||
#endif | ||
|
||
/*EOF*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.