From 1de5aca585af3e04a64a4f287dd348c0e7b4b967 Mon Sep 17 00:00:00 2001 From: Bastien Bouclet Date: Sun, 24 Dec 2017 11:01:38 +0100 Subject: ENGINES: Set the GameDescriptor decription in the constructor --- engines/advancedDetector.cpp | 4 ++-- engines/game.cpp | 52 ++++++++++++++++++++++---------------------- engines/game.h | 21 +++++++++--------- engines/scumm/detection.cpp | 5 +---- engines/sky/detection.cpp | 16 ++++++++++---- engines/sword1/detection.cpp | 14 +++++++----- engines/sword2/sword2.cpp | 3 ++- 7 files changed, 61 insertions(+), 54 deletions(-) diff --git a/engines/advancedDetector.cpp b/engines/advancedDetector.cpp index ac606d3e4b..b7bf4b40e0 100644 --- a/engines/advancedDetector.cpp +++ b/engines/advancedDetector.cpp @@ -56,8 +56,8 @@ static GameDescriptor toGameDescriptor(const ADGameDescription &g, const PlainGa else if (g.flags & ADGF_TESTING) gsl = kTestingGame; - GameDescriptor gd(g.gameId, title, g.language, g.platform, 0, gsl); - gd.updateDesc(extra); + GameDescriptor gd(g.gameId, title, g.language, g.platform, extra); + gd.gameSupportLevel = gsl; return gd; } diff --git a/engines/game.cpp b/engines/game.cpp index 1e96020fde..bdf8e322dd 100644 --- a/engines/game.cpp +++ b/engines/game.cpp @@ -41,7 +41,7 @@ GameDescriptor::GameDescriptor() : gameSupportLevel(kStableGame) { } -GameDescriptor::GameDescriptor(const PlainGameDescriptor &pgd, const Common::String &guioptions) : +GameDescriptor::GameDescriptor(const PlainGameDescriptor &pgd) : language(Common::UNK_LANG), platform(Common::kPlatformUnknown), gameSupportLevel(kStableGame) { @@ -49,21 +49,18 @@ GameDescriptor::GameDescriptor(const PlainGameDescriptor &pgd, const Common::Str gameId = pgd.gameId; preferredTarget = pgd.gameId; description = pgd.description; - - if (!guioptions.empty()) - _guiOptions = Common::getGameGUIOptionsDescription(guioptions); } -GameDescriptor::GameDescriptor(const Common::String &id, const Common::String &d, Common::Language l, Common::Platform p, const Common::String &guioptions, GameSupportLevel gsl) { +GameDescriptor::GameDescriptor(const Common::String &id, const Common::String &d, Common::Language l, Common::Platform p, const Common::String &ex) { gameId = id; preferredTarget = id; description = d; language = l; platform = p; - gameSupportLevel = gsl; + extra = ex; - if (!guioptions.empty()) - _guiOptions = Common::getGameGUIOptionsDescription(guioptions); + // Append additional information, if set, to the description. + description += updateDesc(); } void GameDescriptor::setGUIOptions(const Common::String &guioptions) { @@ -80,31 +77,34 @@ void GameDescriptor::appendGUIOptions(const Common::String &str) { _guiOptions += str; } -void GameDescriptor::updateDesc(const char *extraDesc) { +Common::String GameDescriptor::updateDesc() const { const bool hasCustomLanguage = (language != Common::UNK_LANG); const bool hasCustomPlatform = (platform != Common::kPlatformUnknown); - const bool hasExtraDesc = (extraDesc && extraDesc[0]); + const bool hasExtraDesc = !extra.empty(); // Adapt the description string if custom platform/language is set. - if (hasCustomLanguage || hasCustomPlatform || hasExtraDesc) { - Common::String descr = description; + Common::String descr; + if (!hasCustomLanguage && !hasCustomPlatform && !hasExtraDesc) + return descr; - descr += " ("; + descr += " ("; + + if (hasExtraDesc) + descr += extra; + if (hasCustomPlatform) { if (hasExtraDesc) - descr += extraDesc; - if (hasCustomPlatform) { - if (hasExtraDesc) - descr += "/"; - descr += Common::getPlatformDescription(platform); - } - if (hasCustomLanguage) { - if (hasExtraDesc || hasCustomPlatform) - descr += "/"; - descr += Common::getLanguageDescription(language); - } - descr += ")"; - description = descr; + descr += "/"; + descr += Common::getPlatformDescription(platform); + } + if (hasCustomLanguage) { + if (hasExtraDesc || hasCustomPlatform) + descr += "/"; + descr += Common::getLanguageDescription(language); } + + descr += ")"; + + return descr; } DetectionResults::DetectionResults(const DetectedGames &detectedGames) : diff --git a/engines/game.h b/engines/game.h index 053c0c85b1..d675e7bdf4 100644 --- a/engines/game.h +++ b/engines/game.h @@ -81,20 +81,12 @@ enum GameSupportLevel { class GameDescriptor { public: GameDescriptor(); - explicit GameDescriptor(const PlainGameDescriptor &pgd, const Common::String &guioptions = Common::String()); + explicit GameDescriptor(const PlainGameDescriptor &pgd); GameDescriptor(const Common::String &id, const Common::String &description, Common::Language language = Common::UNK_LANG, - Common::Platform platform = Common::kPlatformUnknown, - const Common::String &guioptions = Common::String(), - GameSupportLevel gsl = kStableGame); - - /** - * Update the description string by appending (EXTRA/PLATFORM/LANG) to it. - * Values that are missing are omitted, so e.g. (EXTRA/LANG) would be - * added if no platform has been specified but a language and an extra string. - */ - void updateDesc(const char *extraDesc = 0); + Common::Platform platform = Common::kPlatformUnknown, + const Common::String &extra = Common::String()); void setGUIOptions(const Common::String &options); void appendGUIOptions(const Common::String &str); @@ -114,6 +106,13 @@ public: GameSupportLevel gameSupportLevel; private: + /** + * Update the description string by appending (EXTRA/PLATFORM/LANG) to it. + * Values that are missing are omitted, so e.g. (EXTRA/LANG) would be + * added if no platform has been specified but a language and an extra string. + */ + Common::String updateDesc() const; + Common::String _guiOptions; }; diff --git a/engines/scumm/detection.cpp b/engines/scumm/detection.cpp index dea0d3a026..1395fc4fd7 100644 --- a/engines/scumm/detection.cpp +++ b/engines/scumm/detection.cpp @@ -1037,10 +1037,7 @@ DetectedGames ScummMetaEngine::detectGames(const Common::FSList &fslist) const { assert(g); DetectedGame game; - game.matchedGame = GameDescriptor(x->game.gameid, g->description, x->language, x->game.platform); - - // Append additional information, if set, to the description. - game.matchedGame.updateDesc(x->extra); + game.matchedGame = GameDescriptor(x->game.gameid, g->description, x->language, x->game.platform, x->extra); // Compute and set the preferred target name for this game. // Based on generateComplexID() in advancedDetector.cpp. diff --git a/engines/sky/detection.cpp b/engines/sky/detection.cpp index ffed998ab1..b8abd6bcb5 100644 --- a/engines/sky/detection.cpp +++ b/engines/sky/detection.cpp @@ -173,18 +173,26 @@ DetectedGames SkyMetaEngine::detectGames(const Common::FSList &fslist) const { // Match found, add to list of candidates, then abort inner loop. // The game detector uses US English by default. We want British // English to match the recorded voices better. - DetectedGame game; - game.matchedGame = GameDescriptor(skySetting.gameId, skySetting.description, Common::UNK_LANG, Common::kPlatformUnknown); const SkyVersion *sv = skyVersions; while (sv->dinnerTableEntries) { if (dinnerTableEntries == sv->dinnerTableEntries && (sv->dataDiskSize == dataDiskSize || sv->dataDiskSize == -1)) { - game.matchedGame.updateDesc(Common::String::format("v0.0%d %s", sv->version, sv->extraDesc).c_str()); - game.matchedGame.setGUIOptions(sv->guioptions); break; } ++sv; } + + DetectedGame game; + if (sv->dinnerTableEntries) { + Common::String extra = Common::String::format("v0.0%d %s", sv->version, sv->extraDesc); + + game.matchedGame = GameDescriptor(skySetting.gameId, skySetting.description, Common::UNK_LANG, Common::kPlatformUnknown, extra); + game.matchedGame.setGUIOptions(sv->guioptions); + + } else { + game.matchedGame = GameDescriptor(skySetting.gameId, skySetting.description); + } + detectedGames.push_back(game); } diff --git a/engines/sword1/detection.cpp b/engines/sword1/detection.cpp index 80176aee40..205640a0a6 100644 --- a/engines/sword1/detection.cpp +++ b/engines/sword1/detection.cpp @@ -214,20 +214,22 @@ DetectedGames SwordMetaEngine::detectGames(const Common::FSList &fslist) const { DetectedGame game; if (mainFilesFound && pcFilesFound && demoFilesFound) - game.matchedGame = GameDescriptor(sword1DemoSettings, GUIO2(GUIO_NOMIDI, GUIO_NOASPECT)); + game.matchedGame = GameDescriptor(sword1DemoSettings); else if (mainFilesFound && pcFilesFound && psxFilesFound) - game.matchedGame = GameDescriptor(sword1PSXSettings, GUIO2(GUIO_NOMIDI, GUIO_NOASPECT)); + game.matchedGame = GameDescriptor(sword1PSXSettings); else if (mainFilesFound && pcFilesFound && psxDemoFilesFound) - game.matchedGame = GameDescriptor(sword1PSXDemoSettings, GUIO2(GUIO_NOMIDI, GUIO_NOASPECT)); + game.matchedGame = GameDescriptor(sword1PSXDemoSettings); else if (mainFilesFound && pcFilesFound && !psxFilesFound) - game.matchedGame = GameDescriptor(sword1FullSettings, GUIO2(GUIO_NOMIDI, GUIO_NOASPECT)); + game.matchedGame = GameDescriptor(sword1FullSettings); else if (mainFilesFound && macFilesFound) - game.matchedGame = GameDescriptor(sword1MacFullSettings, GUIO2(GUIO_NOMIDI, GUIO_NOASPECT)); + game.matchedGame = GameDescriptor(sword1MacFullSettings); else if (mainFilesFound && macDemoFilesFound) - game.matchedGame = GameDescriptor(sword1MacDemoSettings, GUIO2(GUIO_NOMIDI, GUIO_NOASPECT)); + game.matchedGame = GameDescriptor(sword1MacDemoSettings); else return detectedGames; + game.matchedGame.setGUIOptions(GUIO2(GUIO_NOMIDI, GUIO_NOASPECT)); + game.matchedGame.appendGUIOptions(getGameGUIOptionsDescriptionLanguage(Common::EN_ANY)); game.matchedGame.appendGUIOptions(getGameGUIOptionsDescriptionLanguage(Common::DE_DEU)); game.matchedGame.appendGUIOptions(getGameGUIOptionsDescriptionLanguage(Common::FR_FRA)); diff --git a/engines/sword2/sword2.cpp b/engines/sword2/sword2.cpp index 67f6904cbe..231074641e 100644 --- a/engines/sword2/sword2.cpp +++ b/engines/sword2/sword2.cpp @@ -193,7 +193,8 @@ DetectedGames detectGamesImpl(const Common::FSList &fslist, bool recursion = fal // Match found, add to list of candidates, then abort inner loop. DetectedGame game; - game.matchedGame = GameDescriptor(g->gameid, g->description, Common::UNK_LANG, Common::kPlatformUnknown, GUIO2(GUIO_NOMIDI, GUIO_NOASPECT)); + game.matchedGame = GameDescriptor(g->gameid, g->description); + game.matchedGame.setGUIOptions(GUIO2(GUIO_NOMIDI, GUIO_NOASPECT)); detectedGames.push_back(game); break; -- cgit v1.2.3