Commit f5105ae5 authored by Bkg2k's avatar Bkg2k

Improve default metadata management

parent 370be3b9
This diff is collapsed.
......@@ -30,6 +30,18 @@ class MetadataDescriptor
static int LivingGames;
#endif
// Static default values
static const std::string DefaultValueEmulator;
static const std::string DefaultValueCore;
static const std::string DefaultValueRatio;
static const std::string DefaultValueEmpty;
static const std::string DefaultValueRating;
static const std::string DefaultValuePlayers;
static const std::string DefaultValuePlaycount;
static const std::string DefaultValueUnknown;
static const std::string DefaultValueFavorite;
static const std::string DefaultValueHidden;
//! Game node <game></game>
static const std::string GameNodeIdentifier;
//! Folder node <folder></folder>
......@@ -47,7 +59,6 @@ class MetadataDescriptor
std::string* _Ratio; //!< Specific screen ratio
std::string* _Thumbnail; //!< Thumbnail path
std::string* _Region; //!< Rom/Game Region
//std::string _RomType; //!< Rom Type (???)
float _Rating; //!< Rating from 0.0 to 1.0
int _Players; //!< Players range: LSW:from - MSW:to (allow sorting by max players)
int _ReleaseDate; //!< Release data (epoch)
......@@ -102,10 +113,9 @@ class MetadataDescriptor
* @param string PString to read
* @return read value
*/
static const std::string& ReadPString(const std::string* string)
static const std::string& ReadPString(const std::string* string, const std::string& defaultvalue)
{
static std::string emptyString;
if (string == nullptr) return emptyString;
if (string == nullptr) return defaultvalue;
return *string;
}
......@@ -413,18 +423,17 @@ class MetadataDescriptor
ObjectType Type() const { return _Type; }
const std::string& Name() const { return _Name; }
const std::string& Emulator() const { return ReadPString(_Emulator); }
const std::string& Core() const { return ReadPString(_Core); }
const std::string& Ratio() const { return ReadPString(_Ratio); }
const std::string& Description() const { return _Description; }
const std::string& Image() const { return _Image; }
const std::string& Thumbnail() const { return ReadPString(_Thumbnail); }
const std::string& Developer() const { return _Developer; }
const std::string& Publisher() const { return _Publisher; }
const std::string& Genre() const { return _Genre; }
const std::string& Region() const { return ReadPString(_Region); }
//const std::string& RomType() const { return _RomType; }
const std::string& Name() const { return _Name; }
const std::string& Emulator() const { return ReadPString(_Emulator, DefaultValueEmulator); }
const std::string& Core() const { return ReadPString(_Core, DefaultValueCore); }
const std::string& Ratio() const { return ReadPString(_Ratio, DefaultValueRatio); }
const std::string& Description() const { return _Description; }
const std::string& Image() const { return _Image; }
const std::string& Thumbnail() const { return ReadPString(_Thumbnail, DefaultValueEmpty); }
const std::string& Developer() const { return _Developer; }
const std::string& Publisher() const { return _Publisher; }
const std::string& Genre() const { return _Genre; }
const std::string& Region() const { return ReadPString(_Region, DefaultValueEmpty); }
float Rating() const { return _Rating; }
int PlayerRange() const { return _Players; }
......@@ -443,18 +452,17 @@ class MetadataDescriptor
* String accessors
*/
std::string NameAsString() const { return _Name; }
std::string EmulatorAsString() const { return ReadPString(_Emulator); }
std::string CoreAsString() const { return ReadPString(_Core); }
std::string RatioAsString() const { return ReadPString(_Ratio); }
std::string DescriptionAsString() const { return _Description; }
std::string ImageAsString() const { return _Image; }
std::string ThumbnailAsString() const { return ReadPString(_Thumbnail); }
std::string DeveloperAsString() const { return _Developer; }
std::string PublisherAsString() const { return _Publisher; }
std::string GenreAsString() const { return _Genre; }
std::string RegionAsString() const { return ReadPString(_Region); }
//std::string RomTypeAsString() const { return _RomType; }
std::string NameAsString() const { return _Name; }
std::string EmulatorAsString() const { return ReadPString(_Emulator, DefaultValueEmulator); }
std::string CoreAsString() const { return ReadPString(_Core, DefaultValueCore); }
std::string RatioAsString() const { return ReadPString(_Ratio, DefaultValueRatio); }
std::string DescriptionAsString() const { return _Description; }
std::string ImageAsString() const { return _Image; }
std::string ThumbnailAsString() const { return ReadPString(_Thumbnail, DefaultValueEmpty); }
std::string DeveloperAsString() const { return _Developer; }
std::string PublisherAsString() const { return _Publisher; }
std::string GenreAsString() const { return _Genre; }
std::string RegionAsString() const { return ReadPString(_Region, DefaultValueEmpty); }
std::string RatingAsString() const { return std::move(FloatToString(_Rating, 4)); }
std::string PlayersAsString() const { return std::move(IntToRange(_Players)); }
......@@ -483,7 +491,6 @@ class MetadataDescriptor
void SetRating(float rating) { _Rating = rating; _Dirty = true; }
void SetPlayers(int min, int max) { _Players = (max << 16) + min; _Dirty = true; }
void SetRegion(const std::string& region) { AssignPString(_Region, region); _Dirty = true; }
//void SetRomType(const std::string& romtype) { _RomType = romtype; _Dirty = true; }
void SetRomCrc32(int romcrc32) { _RomCrc32 = romcrc32; _Dirty = true; }
void SetFavorite(bool favorite) { _Favorite = favorite; _Dirty = true; }
void SetHidden(bool hidden) { _Hidden = hidden; _Dirty = true; }
......@@ -526,7 +533,6 @@ class MetadataDescriptor
bool IsDefaultPublisher() const { return _Default._Publisher == _Publisher; }
bool IsDefaultGenre() const { return _Default._Genre == _Genre; }
bool IsDefaultRegion() const { return _Default._Region == _Region; }
//bool IsDefaultRomType() const { return _Default._RomType == _RomType; }
bool IsDefaultRating() const { return _Default._Rating == _Rating; }
bool IsDefaultPlayerRange() const { return _Default._Players == _Players; }
bool IsDefaultReleaseDateEpoc() const { return _Default._ReleaseDate == _ReleaseDate; }
......@@ -548,8 +554,8 @@ class MetadataDescriptor
* Convenient Methods
*/
static bool AreGames(const MetadataDescriptor& md1, const MetadataDescriptor& md2) { return (md1._Type == md2._Type) && (md1._Type == ObjectType::Game); }
static bool AreFolders(const MetadataDescriptor& md1, const MetadataDescriptor& md2) { return (md1._Type == md2._Type) && (md1._Type == ObjectType::Folder); }
static bool AreGames(const MetadataDescriptor& md1, const MetadataDescriptor& md2) { return (md1._Type == md2._Type) && md1.IsGame(); }
static bool AreFolders(const MetadataDescriptor& md1, const MetadataDescriptor& md2) { return (md1._Type == md2._Type) && md1.IsFolder(); }
/*
* Special modifiers
......
......@@ -151,11 +151,10 @@ std::string escapePath(const boost::filesystem::path &path)
#endif
}
void SystemData::launchGame(Window* window, FileData* game, std::string netplay, std::string core, std::string ip, std::string port)
void SystemData::launchGame(Window* window, FileData* game, const std::string& netplay, const std::string& core, const std::string& ip, const std::string& port)
{
LOG(LogInfo) << "Attempting to launch game...";
AudioManager::getInstance()->deinit();
VolumeControl::getInstance()->deinit();
......@@ -177,24 +176,7 @@ void SystemData::launchGame(Window* window, FileData* game, std::string netplay,
command = strreplace(command, "%ROM_RAW%", rom_raw);
command = strreplace(command, "%EMULATOR%", game->Metadata().Emulator());
command = strreplace(command, "%CORE%", game->Metadata().Core());
command = strreplace(command, "%RATIO%", game->Metadata().RatingAsString());
/*command = strreplace(command, "%ROM%", rom);
command = strreplace(command, "%CONTROLLERSCONFIG%", controlersConfig);
command = strreplace(command, "%SYSTEM%", game->Metadata().get("system"));
command = strreplace(command, "%BASENAME%", basename);
command = strreplace(command, "%ROM_RAW%", rom_raw);
if (core != "")
{
command = strreplace(command, "%EMULATOR%", "libretro");
command = strreplace(command, "%CORE%", core);
}
else
{
command = strreplace(command, "%EMULATOR%", game->Metadata().get("emulator"));
command = strreplace(command, "%CORE%", game->Metadata().get("core"));
}
command = strreplace(command, "%RATIO%", game->Metadata().get("ratio"));*/
command = strreplace(command, "%RATIO%", game->Metadata().RatioAsString());
if (netplay == "client")
{
......@@ -234,7 +216,6 @@ void SystemData::launchGame(Window* window, FileData* game, std::string netplay,
//update number of times the game has been launched
game->Metadata().IncPlaycount();
int timesPlayed = game->Metadata().PlayCount();
//update last played time
game->Metadata().SetLastplayedNow();
......@@ -377,7 +358,9 @@ bool SystemData::loadSystemNodes(XmlNodeCollisionMap &collisionMap, XmlNodeList
}
if (!result)
{
LOG(LogError) << "missing or empty <systemList> tag!";
}
return result;
}
......@@ -410,7 +393,10 @@ bool SystemData::loadSystemList(Tree &document, XmlNodeCollisionMap &collisionMa
if (!loadXmlFile(document, filePath)) return false;
bool result = loadSystemNodes(collisionMap, nodeStore, document);
if (!result) LOG(LogWarning) << filePath << " has no systems or systemList nodes";
if (!result)
{
LOG(LogWarning) << filePath << " has no systems or systemList nodes";
}
return result;
}
......
......@@ -47,7 +47,7 @@ public:
unsigned int getFavoritesCount() const;
unsigned int getHiddenCount() const;
void launchGame(Window* window, FileData* game, std::string netplay = "", std::string core = "", std::string ip = "", std::string port = "");
void launchGame(Window* window, FileData* game, const std::string& netplay, const std::string& core, const std::string& ip, const std::string& port);
static void deleteSystems();
static bool loadConfig(); //Load the system config file at getConfigPath(). Returns true if no errors were encountered. An example will be written if the file doesn't exist.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment