mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2024-11-22 06:05:38 +00:00
Added scraper support for displaying the returned platform if it does not match the game platform.
This commit is contained in:
parent
6f35f16470
commit
5bb009e604
|
@ -153,6 +153,9 @@ namespace PlatformIds
|
|||
|
||||
const std::string getPlatformName(PlatformId id)
|
||||
{
|
||||
if (id > platformNames.size() - 1)
|
||||
return "unknown";
|
||||
|
||||
// Return the platform name.
|
||||
return platformNames[id];
|
||||
}
|
||||
|
|
|
@ -351,7 +351,7 @@ void GuiScraperSearch::stop()
|
|||
mScrapeResult = {};
|
||||
}
|
||||
|
||||
void GuiScraperSearch::onSearchDone(const std::vector<ScraperSearchResult>& results)
|
||||
void GuiScraperSearch::onSearchDone(std::vector<ScraperSearchResult>& results)
|
||||
{
|
||||
mResultList->clear();
|
||||
|
||||
|
@ -386,11 +386,57 @@ void GuiScraperSearch::onSearchDone(const std::vector<ScraperSearchResult>& resu
|
|||
ComponentListRow row;
|
||||
|
||||
for (size_t i = 0; i < results.size(); ++i) {
|
||||
// If the platform IDs returned by the scraper do not match the platform IDs of the
|
||||
// scraped game, then add the additional platform information to the end of the game
|
||||
// name (within square brackets).
|
||||
std::string gameName = results.at(i).mdl.get("name");
|
||||
std::string otherPlatforms;
|
||||
|
||||
// As the platform names are found via reverse lookup there could be multiple entries.
|
||||
// So if any of the entries match the platforms of the last search, then just keep
|
||||
// this platform ID and remove the other ones.
|
||||
for (auto& platformID : mLastSearch.system->getSystemEnvData()->mPlatformIds) {
|
||||
if (!results.at(i).platformIDs.empty() &&
|
||||
std::find(results.at(i).platformIDs.begin(), results.at(i).platformIDs.end(),
|
||||
platformID) != results.at(i).platformIDs.end()) {
|
||||
results.at(i).platformIDs.clear();
|
||||
results.at(i).platformIDs.push_back(platformID);
|
||||
}
|
||||
}
|
||||
|
||||
bool hasOtherPlatforms = false;
|
||||
|
||||
for (auto& platformID : mLastSearch.system->getSystemEnvData()->mPlatformIds) {
|
||||
if (!results.at(i).platformIDs.empty() &&
|
||||
std::find(results.at(i).platformIDs.cbegin(), results.at(i).platformIDs.cend(),
|
||||
platformID) == results.at(i).platformIDs.cend())
|
||||
hasOtherPlatforms = true;
|
||||
}
|
||||
|
||||
if (hasOtherPlatforms) {
|
||||
if (std::find(results.at(i).platformIDs.cbegin(), results.at(i).platformIDs.cend(),
|
||||
PlatformIds::PlatformId::PC) != results.at(i).platformIDs.cend()) {
|
||||
// The PC platform is a bit special as it's widely used by a number of
|
||||
// different systems. As such remove these other IDs and only display the
|
||||
// main PC ID as the list of platforms would otherwise be quite long.
|
||||
otherPlatforms = PlatformIds::getPlatformName(PlatformIds::PlatformId::PC);
|
||||
}
|
||||
else {
|
||||
for (auto& platform : results.at(i).platformIDs)
|
||||
otherPlatforms += PlatformIds::getPlatformName(platform) + "/";
|
||||
}
|
||||
}
|
||||
|
||||
if (otherPlatforms != "" && otherPlatforms.back() == '/')
|
||||
otherPlatforms.pop_back();
|
||||
|
||||
if (otherPlatforms != "")
|
||||
gameName.append(" [").append(otherPlatforms).append("]");
|
||||
|
||||
row.elements.clear();
|
||||
row.addElement(
|
||||
std::make_shared<TextComponent>(
|
||||
mWindow, Utils::String::toUpper(results.at(i).mdl.get("name")), font, color),
|
||||
false);
|
||||
row.addElement(std::make_shared<TextComponent>(
|
||||
mWindow, Utils::String::toUpper(gameName), font, color),
|
||||
false);
|
||||
row.makeAcceptInputHandler([this, i] { returnResult(mScraperResults.at(i)); });
|
||||
mResultList->addRow(row);
|
||||
}
|
||||
|
|
|
@ -108,7 +108,7 @@ private:
|
|||
|
||||
void onSearchError(const std::string& error,
|
||||
HttpReq::Status status = HttpReq::REQ_UNDEFINED_ERROR);
|
||||
void onSearchDone(const std::vector<ScraperSearchResult>& results);
|
||||
void onSearchDone(std::vector<ScraperSearchResult>& results);
|
||||
|
||||
int getSelectedIndex();
|
||||
|
||||
|
|
|
@ -333,6 +333,17 @@ namespace
|
|||
{
|
||||
ScraperSearchResult result;
|
||||
|
||||
// Platform IDs.
|
||||
if (game.HasMember("platform") && game["platform"].IsInt()) {
|
||||
for (auto& platform : gamesdb_new_platformid_map) {
|
||||
if (platform.second == std::to_string(game["platform"].GetInt()))
|
||||
result.platformIDs.push_back(platform.first);
|
||||
}
|
||||
}
|
||||
|
||||
if (result.platformIDs.empty())
|
||||
result.platformIDs.push_back(PlatformId::PLATFORM_UNKNOWN);
|
||||
|
||||
if (game.HasMember("id") && game["id"].IsInt())
|
||||
result.gameID = std::to_string(getIntOrThrow(game, "id"));
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include "AsyncHandle.h"
|
||||
#include "HttpReq.h"
|
||||
#include "MetaData.h"
|
||||
#include "PlatformId.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <functional>
|
||||
|
@ -52,6 +53,7 @@ struct ScraperSearchResult {
|
|||
|
||||
MetaDataList mdl;
|
||||
std::string gameID;
|
||||
std::vector<PlatformIds::PlatformId> platformIDs;
|
||||
|
||||
// How many more objects the scraper service allows to be downloaded
|
||||
// within a given time period.
|
||||
|
|
|
@ -445,11 +445,21 @@ void ScreenScraperRequest::processGame(const pugi::xml_document& xmldoc,
|
|||
<< result.mdl.get("players");
|
||||
}
|
||||
|
||||
// Controller (only for the Arcade and SNK Neo Geo systems).
|
||||
pugi::xml_node system = game.child("systeme");
|
||||
int platformID = system.attribute("parentid").as_int();
|
||||
int platformID = system.attribute("id").as_int();
|
||||
int parentPlatformID = system.attribute("parentid").as_int();
|
||||
|
||||
if (platformID == 75 || platformID == 142) {
|
||||
// Platform IDs.
|
||||
for (auto& platform : screenscraper_platformid_map) {
|
||||
if (platform.second == platformID || platform.second == parentPlatformID)
|
||||
result.platformIDs.push_back(platform.first);
|
||||
}
|
||||
|
||||
if (result.platformIDs.empty())
|
||||
result.platformIDs.push_back(PlatformId::PLATFORM_UNKNOWN);
|
||||
|
||||
// Controller (only for the Arcade and SNK Neo Geo systems).
|
||||
if (parentPlatformID == 75 || parentPlatformID == 142) {
|
||||
std::string controller = Utils::String::toLower(game.child("controles").text().get());
|
||||
if (!controller.empty()) {
|
||||
std::string controllerDescription = "Other";
|
||||
|
|
Loading…
Reference in a new issue