mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2024-11-22 22:25:38 +00:00
Add user rating and last time played to game data
That should be about it...
This commit is contained in:
parent
d99134763f
commit
c61a470694
|
@ -62,6 +62,17 @@ bool FolderData::compareRating(const FileData* file1, const FileData* file2)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool FolderData::compareUserRating(const FileData* file1, const FileData* file2)
|
||||||
|
{
|
||||||
|
//we need game data. try to cast
|
||||||
|
const GameData * game1 = dynamic_cast<const GameData*>(file1);
|
||||||
|
const GameData * game2 = dynamic_cast<const GameData*>(file2);
|
||||||
|
if (game1 != nullptr && game2 != nullptr) {
|
||||||
|
return game1->getUserRating() < game2->getUserRating();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool FolderData::compareTimesPlayed(const FileData* file1, const FileData* file2)
|
bool FolderData::compareTimesPlayed(const FileData* file1, const FileData* file2)
|
||||||
{
|
{
|
||||||
//we need game data. try to cast
|
//we need game data. try to cast
|
||||||
|
@ -73,6 +84,17 @@ bool FolderData::compareTimesPlayed(const FileData* file1, const FileData* file2
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool FolderData::compareLastPlayed(const FileData* file1, const FileData* file2)
|
||||||
|
{
|
||||||
|
//we need game data. try to cast
|
||||||
|
const GameData * game1 = dynamic_cast<const GameData*>(file1);
|
||||||
|
const GameData * game2 = dynamic_cast<const GameData*>(file2);
|
||||||
|
if (game1 != nullptr && game2 != nullptr) {
|
||||||
|
return game1->getLastPlayed() < game2->getLastPlayed();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
//sort this folder and any subfolders
|
//sort this folder and any subfolders
|
||||||
void FolderData::sort()
|
void FolderData::sort()
|
||||||
{
|
{
|
||||||
|
|
|
@ -28,7 +28,9 @@ public:
|
||||||
|
|
||||||
static bool compareFileName(const FileData* file1, const FileData* file2);
|
static bool compareFileName(const FileData* file1, const FileData* file2);
|
||||||
static bool compareRating(const FileData* file1, const FileData* file2);
|
static bool compareRating(const FileData* file1, const FileData* file2);
|
||||||
|
static bool compareUserRating(const FileData* file1, const FileData* file2);
|
||||||
static bool compareTimesPlayed(const FileData* file1, const FileData* file2);
|
static bool compareTimesPlayed(const FileData* file1, const FileData* file2);
|
||||||
|
static bool compareLastPlayed(const FileData* file1, const FileData* file2);
|
||||||
private:
|
private:
|
||||||
SystemData* mSystem;
|
SystemData* mSystem;
|
||||||
std::string mPath;
|
std::string mPath;
|
||||||
|
|
|
@ -10,11 +10,13 @@ const std::string GameData::xmlTagPath = "path";
|
||||||
const std::string GameData::xmlTagDescription = "desc";
|
const std::string GameData::xmlTagDescription = "desc";
|
||||||
const std::string GameData::xmlTagImagePath = "image";
|
const std::string GameData::xmlTagImagePath = "image";
|
||||||
const std::string GameData::xmlTagRating = "rating";
|
const std::string GameData::xmlTagRating = "rating";
|
||||||
|
const std::string GameData::xmlTagUserRating = "userrating";
|
||||||
const std::string GameData::xmlTagTimesPlayed = "timesplayed";
|
const std::string GameData::xmlTagTimesPlayed = "timesplayed";
|
||||||
|
const std::string GameData::xmlTagLastPlayed = "lastplayed";
|
||||||
|
|
||||||
|
|
||||||
GameData::GameData(SystemData* system, std::string path, std::string name)
|
GameData::GameData(SystemData* system, std::string path, std::string name)
|
||||||
: mSystem(system), mPath(path), mName(name), mRating(0.0f), mTimesPlayed(0)
|
: mSystem(system), mPath(path), mName(name), mRating(0.0f), mUserRating(0.0f), mTimesPlayed(0), mLastPlayed(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,6 +75,16 @@ void GameData::setRating(float rating)
|
||||||
mRating = rating;
|
mRating = rating;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float GameData::getUserRating() const
|
||||||
|
{
|
||||||
|
return mUserRating;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GameData::setUserRating(float rating)
|
||||||
|
{
|
||||||
|
mUserRating = rating;
|
||||||
|
}
|
||||||
|
|
||||||
size_t GameData::getTimesPlayed() const
|
size_t GameData::getTimesPlayed() const
|
||||||
{
|
{
|
||||||
return mTimesPlayed;
|
return mTimesPlayed;
|
||||||
|
@ -83,6 +95,16 @@ void GameData::setTimesPlayed(size_t timesPlayed)
|
||||||
mTimesPlayed = timesPlayed;
|
mTimesPlayed = timesPlayed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::time_t GameData::getLastPlayed() const
|
||||||
|
{
|
||||||
|
return mLastPlayed;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GameData::setLastPlayed(std::time_t lastPlayed)
|
||||||
|
{
|
||||||
|
mLastPlayed = lastPlayed;
|
||||||
|
}
|
||||||
|
|
||||||
std::string GameData::getBashPath() const
|
std::string GameData::getBashPath() const
|
||||||
{
|
{
|
||||||
//a quick and dirty way to insert a backslash before most characters that would mess up a bash path
|
//a quick and dirty way to insert a backslash before most characters that would mess up a bash path
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
#define _GAMEDATA_H_
|
#define _GAMEDATA_H_
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <ctime>
|
||||||
|
|
||||||
#include "FileData.h"
|
#include "FileData.h"
|
||||||
#include "SystemData.h"
|
#include "SystemData.h"
|
||||||
|
|
||||||
|
@ -18,7 +20,9 @@ public:
|
||||||
static const std::string xmlTagDescription;
|
static const std::string xmlTagDescription;
|
||||||
static const std::string xmlTagImagePath;
|
static const std::string xmlTagImagePath;
|
||||||
static const std::string xmlTagRating;
|
static const std::string xmlTagRating;
|
||||||
|
static const std::string xmlTagUserRating;
|
||||||
static const std::string xmlTagTimesPlayed;
|
static const std::string xmlTagTimesPlayed;
|
||||||
|
static const std::string xmlTagLastPlayed;
|
||||||
|
|
||||||
GameData(SystemData* system, std::string path, std::string name);
|
GameData(SystemData* system, std::string path, std::string name);
|
||||||
|
|
||||||
|
@ -37,9 +41,15 @@ public:
|
||||||
float getRating() const;
|
float getRating() const;
|
||||||
void setRating(float rating);
|
void setRating(float rating);
|
||||||
|
|
||||||
|
float getUserRating() const;
|
||||||
|
void setUserRating(float rating);
|
||||||
|
|
||||||
size_t getTimesPlayed() const;
|
size_t getTimesPlayed() const;
|
||||||
void setTimesPlayed(size_t timesPlayed);
|
void setTimesPlayed(size_t timesPlayed);
|
||||||
|
|
||||||
|
std::time_t getLastPlayed() const;
|
||||||
|
void setLastPlayed(std::time_t lastPlayed);
|
||||||
|
|
||||||
std::string getBashPath() const;
|
std::string getBashPath() const;
|
||||||
std::string getBaseName() const;
|
std::string getBaseName() const;
|
||||||
|
|
||||||
|
@ -53,7 +63,9 @@ private:
|
||||||
std::string mDescription;
|
std::string mDescription;
|
||||||
std::string mImagePath;
|
std::string mImagePath;
|
||||||
float mRating;
|
float mRating;
|
||||||
|
float mUserRating;
|
||||||
size_t mTimesPlayed;
|
size_t mTimesPlayed;
|
||||||
|
std::time_t mLastPlayed;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -95,8 +95,9 @@ void SystemData::launchGame(Window* window, GameData* game)
|
||||||
VolumeControl::getInstance()->init();
|
VolumeControl::getInstance()->init();
|
||||||
AudioManager::getInstance()->init();
|
AudioManager::getInstance()->init();
|
||||||
|
|
||||||
//update number of times the game has been launched
|
//update number of times the game has been launched and the time
|
||||||
game->setTimesPlayed(game->getTimesPlayed() + 1);
|
game->setTimesPlayed(game->getTimesPlayed() + 1);
|
||||||
|
game->setLastPlayed(std::time(nullptr));
|
||||||
}
|
}
|
||||||
|
|
||||||
void SystemData::populateFolder(FolderData* folder)
|
void SystemData::populateFolder(FolderData* folder)
|
||||||
|
|
|
@ -186,12 +186,24 @@ void parseGamelist(SystemData* system)
|
||||||
std::istringstream(gameNode.child(GameData::xmlTagRating.c_str()).text().get()) >> rating;
|
std::istringstream(gameNode.child(GameData::xmlTagRating.c_str()).text().get()) >> rating;
|
||||||
game->setRating(rating);
|
game->setRating(rating);
|
||||||
}
|
}
|
||||||
|
if(gameNode.child(GameData::xmlTagUserRating.c_str()))
|
||||||
|
{
|
||||||
|
float userRating;
|
||||||
|
std::istringstream(gameNode.child(GameData::xmlTagUserRating.c_str()).text().get()) >> userRating;
|
||||||
|
game->setUserRating(userRating);
|
||||||
|
}
|
||||||
if(gameNode.child(GameData::xmlTagTimesPlayed.c_str()))
|
if(gameNode.child(GameData::xmlTagTimesPlayed.c_str()))
|
||||||
{
|
{
|
||||||
size_t timesPlayed;
|
size_t timesPlayed;
|
||||||
std::istringstream(gameNode.child(GameData::xmlTagTimesPlayed.c_str()).text().get()) >> timesPlayed;
|
std::istringstream(gameNode.child(GameData::xmlTagTimesPlayed.c_str()).text().get()) >> timesPlayed;
|
||||||
game->setTimesPlayed(timesPlayed);
|
game->setTimesPlayed(timesPlayed);
|
||||||
}
|
}
|
||||||
|
if(gameNode.child(GameData::xmlTagLastPlayed.c_str()))
|
||||||
|
{
|
||||||
|
std::time_t lastPlayed;
|
||||||
|
std::istringstream(gameNode.child(GameData::xmlTagLastPlayed.c_str()).text().get()) >> lastPlayed;
|
||||||
|
game->setLastPlayed(lastPlayed);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
LOG(LogWarning) << "Game at \"" << path << "\" does not exist!";
|
LOG(LogWarning) << "Game at \"" << path << "\" does not exist!";
|
||||||
|
@ -223,8 +235,15 @@ void addGameDataNode(pugi::xml_node & parent, const GameData * game)
|
||||||
//all other values are added regardless of their value
|
//all other values are added regardless of their value
|
||||||
pugi::xml_node ratingNode = newGame.append_child(GameData::xmlTagRating.c_str());
|
pugi::xml_node ratingNode = newGame.append_child(GameData::xmlTagRating.c_str());
|
||||||
ratingNode.text().set(std::to_string((long double)game->getRating()).c_str());
|
ratingNode.text().set(std::to_string((long double)game->getRating()).c_str());
|
||||||
|
|
||||||
|
pugi::xml_node userRatingNode = newGame.append_child(GameData::xmlTagUserRating.c_str());
|
||||||
|
userRatingNode.text().set(std::to_string((long double)game->getUserRating()).c_str());
|
||||||
|
|
||||||
pugi::xml_node timesPlayedNode = newGame.append_child(GameData::xmlTagTimesPlayed.c_str());
|
pugi::xml_node timesPlayedNode = newGame.append_child(GameData::xmlTagTimesPlayed.c_str());
|
||||||
timesPlayedNode.text().set(std::to_string((unsigned long long)game->getTimesPlayed()).c_str());
|
timesPlayedNode.text().set(std::to_string((unsigned long long)game->getTimesPlayed()).c_str());
|
||||||
|
|
||||||
|
pugi::xml_node lastPlayedNode = newGame.append_child(GameData::xmlTagLastPlayed.c_str());
|
||||||
|
lastPlayedNode.text().set(std::to_string((unsigned long long)game->getLastPlayed()).c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateGamelist(SystemData* system)
|
void updateGamelist(SystemData* system)
|
||||||
|
|
Loading…
Reference in a new issue