From 2fe060e5c9491ddd7c8f639aab5d7c58c7c73092 Mon Sep 17 00:00:00 2001 From: Bastien Bouclet Date: Sun, 6 May 2018 16:26:57 +0200 Subject: ENGINES: Cleanup DetectedGame initialization in the AD --- engines/advancedDetector.cpp | 96 ++++++++++++++++++++------------------------ engines/advancedDetector.h | 3 -- engines/game.cpp | 5 +-- 3 files changed, 44 insertions(+), 60 deletions(-) (limited to 'engines') diff --git a/engines/advancedDetector.cpp b/engines/advancedDetector.cpp index 8e7ec4856f..c7b5c18892 100644 --- a/engines/advancedDetector.cpp +++ b/engines/advancedDetector.cpp @@ -33,33 +33,16 @@ #include "engines/advancedDetector.h" #include "engines/obsolete.h" -DetectedGame AdvancedMetaEngine::toDetectedGame(const ADDetectedGame &adGame) const { - const char *title; - const char *extra; +static Common::String sanitizeName(const char *name) { + Common::String res; - if (adGame.desc->flags & ADGF_USEEXTRAASTITLE) { - title = adGame.desc->extra; - extra = ""; - } else { - const PlainGameDescriptor *pgd = findPlainGameDescriptor(adGame.desc->gameId, _gameIds); - title = pgd->description; - extra = adGame.desc->extra; + while (*name) { + if (Common::isAlnum(*name)) + res += tolower(*name); + name++; } - DetectedGame game(adGame.desc->gameId, title, adGame.desc->language, adGame.desc->platform, extra); - game.engineName = getName(); - game.hasUnknownFiles = adGame.hasUnknownFiles; - game.matchedFiles = adGame.matchedFiles; - - game.gameSupportLevel = kStableGame; - if (adGame.desc->flags & ADGF_UNSTABLE) - game.gameSupportLevel = kUnstableGame; - else if (adGame.desc->flags & ADGF_TESTING) - game.gameSupportLevel = kTestingGame; - - updateGameDescriptor(game, adGame.desc); - - return game; + return res; } /** @@ -68,8 +51,14 @@ DetectedGame AdvancedMetaEngine::toDetectedGame(const ADDetectedGame &adGame) co * or (if ADGF_DEMO has been set) * GAMEID-demo-PLAFORM-LANG */ -static Common::String generatePreferredTarget(const Common::String &id, const ADGameDescription *desc) { - Common::String res(id); +static Common::String generatePreferredTarget(const ADGameDescription *desc) { + Common::String res; + + if (desc->flags & ADGF_AUTOGENTARGET && desc->extra && *desc->extra) { + res = sanitizeName(desc->extra); + } else { + res = desc->gameId; + } if (desc->flags & ADGF_DEMO) { res = res + "-demo"; @@ -90,42 +79,43 @@ static Common::String generatePreferredTarget(const Common::String &id, const AD return res; } -static Common::String sanitizeName(const char *name) { - Common::String res; - - while (*name) { - if (Common::isAlnum(*name)) - res += tolower(*name); - name++; - } +DetectedGame AdvancedMetaEngine::toDetectedGame(const ADDetectedGame &adGame) const { + const ADGameDescription *desc = adGame.desc; - return res; -} + const char *gameId = _singleId ? _singleId : desc->gameId; -void AdvancedMetaEngine::updateGameDescriptor(DetectedGame &desc, const ADGameDescription *realDesc) const { - if (_singleId) { - desc.preferredTarget = desc.gameId; - desc.gameId = _singleId; + const char *title; + const char *extra; + if (desc->flags & ADGF_USEEXTRAASTITLE) { + title = desc->extra; + extra = ""; + } else { + const PlainGameDescriptor *pgd = findPlainGameDescriptor(desc->gameId, _gameIds); + title = pgd->description; + extra = desc->extra; } - if (desc.preferredTarget.empty()) - desc.preferredTarget = desc.gameId; + DetectedGame game(gameId, title, desc->language, desc->platform, extra); + game.hasUnknownFiles = adGame.hasUnknownFiles; + game.matchedFiles = adGame.matchedFiles; + game.preferredTarget = generatePreferredTarget(desc); - if (realDesc->flags & ADGF_AUTOGENTARGET) { - if (*realDesc->extra) - desc.preferredTarget = sanitizeName(realDesc->extra); - } + game.gameSupportLevel = kStableGame; + if (desc->flags & ADGF_UNSTABLE) + game.gameSupportLevel = kUnstableGame; + else if (desc->flags & ADGF_TESTING) + game.gameSupportLevel = kTestingGame; - desc.preferredTarget = generatePreferredTarget(desc.preferredTarget, realDesc); + game.setGUIOptions(desc->guiOptions + _guiOptions); + game.appendGUIOptions(getGameGUIOptionsDescriptionLanguage(desc->language)); - if (_flags & kADFlagUseExtraAsHint) - desc.extra = realDesc->extra; + if (desc->flags & ADGF_ADDENGLISH) + game.appendGUIOptions(getGameGUIOptionsDescriptionLanguage(Common::EN_ANY)); - desc.setGUIOptions(realDesc->guiOptions + _guiOptions); - desc.appendGUIOptions(getGameGUIOptionsDescriptionLanguage(realDesc->language)); + if (_flags & kADFlagUseExtraAsHint) + game.extra = desc->extra; - if (realDesc->flags & ADGF_ADDENGLISH) - desc.appendGUIOptions(getGameGUIOptionsDescriptionLanguage(Common::EN_ANY)); + return game; } bool cleanupPirated(ADDetectedGames &matched) { diff --git a/engines/advancedDetector.h b/engines/advancedDetector.h index 9f2016465d..326cb79c49 100644 --- a/engines/advancedDetector.h +++ b/engines/advancedDetector.h @@ -320,9 +320,6 @@ protected: */ ADDetectedGame detectGameFilebased(const FileMap &allFiles, const Common::FSList &fslist, const ADFileBasedFallback *fileBasedFallback) const; - // TODO - void updateGameDescriptor(DetectedGame &desc, const ADGameDescription *realDesc) const; - /** * Compose a hashmap of all files in fslist. * Includes nifty stuff like removing trailing dots and ignoring case. diff --git a/engines/game.cpp b/engines/game.cpp index d23a006a4c..3823000bce 100644 --- a/engines/game.cpp +++ b/engines/game.cpp @@ -75,10 +75,7 @@ DetectedGame::DetectedGame(const Common::String &id, const Common::String &d, Co } void DetectedGame::setGUIOptions(const Common::String &guioptions) { - if (guioptions.empty()) - _guiOptions.clear(); - else - _guiOptions = Common::getGameGUIOptionsDescription(guioptions); + _guiOptions = Common::getGameGUIOptionsDescription(guioptions); } void DetectedGame::appendGUIOptions(const Common::String &str) { -- cgit v1.2.3