From 1c347c79118a0bf9b3b746730e1814a318b41c77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaakko=20Ker=C3=A4nen?= Date: Tue, 28 Jan 2014 20:13:22 +0200 Subject: [PATCH] Refactor|Game: Added a method for getting a text description MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The same information that is printed with ‘inspectgame’. --- doomsday/client/include/game.h | 19 ++++++++---- doomsday/client/src/game.cpp | 56 +++++++++++++++++++++++++--------- 2 files changed, 54 insertions(+), 21 deletions(-) diff --git a/doomsday/client/include/game.h b/doomsday/client/include/game.h index eb6af47024..c71ccc3300 100644 --- a/doomsday/client/include/game.h +++ b/doomsday/client/include/game.h @@ -77,6 +77,12 @@ class Game : public de::game::Game */ String const &statusAsText() const; + /** + * Returns information about the game as styled text. Printed by "inspectgame", + * for instance. + */ + String description() const; + /** * Returns the unique identifier of the plugin which registered the game. */ @@ -165,14 +171,15 @@ class Game : public de::game::Game static void printBanner(Game const &game); /** - * Print the list of resource files for @a Game. + * Composes a list of the resource files of the game. * - * @param game Game to list the files of. - * @param rflags Only consider files whose @ref fileFlags match - * this value. If @c <0 the flags are ignored. - * @param printStatus @c true to include the current availability/load status - * of each file. + * @param rflags Only consider files whose @ref fileFlags match + * this value. If @c <0 the flags are ignored. + * @param withStatus @c true to include the current availability/load status + * of each file. */ + String filesAsText(int rflags, bool withStatus = true) const; + static void printFiles(Game const &game, int rflags, bool printStatus = true); /// Register the console commands, variables, etc..., of this module. diff --git a/doomsday/client/src/game.cpp b/doomsday/client/src/game.cpp index b784f4ab14..77ec99e583 100644 --- a/doomsday/client/src/game.cpp +++ b/doomsday/client/src/game.cpp @@ -26,6 +26,7 @@ #include #include +#include #include namespace de { @@ -113,6 +114,23 @@ String const &Game::statusAsText() const return statusTexts[int(status())]; } +String Game::description() const +{ + return String(_E(b) "%1 - %2\n" _E(.) + _E(l) "IdentityKey: " _E(.)_E(i) "%3 " _E(.) + _E(l) "PluginId: " _E(.)_E(i) "%4\n" _E(.) + _E(D) "Startup resources:\n" _E(.) "%5\n" + _E(D) "Other resources:\n" _E(.) "%6\n" + _E(D) "Status: " _E(.) "%7") + .arg(title()) + .arg(author()) + .arg(identityKey()) + .arg(int(pluginId())) + .arg(filesAsText(FF_STARTUP)) + .arg(filesAsText(0, false)) + .arg(statusAsText()); +} + pluginid_t Game::pluginId() const { return d->pluginId; @@ -215,25 +233,26 @@ void Game::printBanner(Game const &game) LOG_MSG(_E(R) "\n"); } -void Game::printFiles(Game const &game, int rflags, bool printStatus) +String Game::filesAsText(int rflags, bool withStatus) const { - int numPrinted = 0; + String text; // Group output by resource class. - Manifests const &manifests = game.manifests(); + Manifests const &manifs = manifests(); for(uint i = 0; i < RESOURCECLASS_COUNT; ++i) { resourceclassid_t const classId = resourceclassid_t(i); - for(Manifests::const_iterator i = manifests.find(classId); - i != manifests.end() && i.key() == classId; ++i) + for(Manifests::const_iterator i = manifs.find(classId); + i != manifs.end() && i.key() == classId; ++i) { ResourceManifest &manifest = **i; if(rflags >= 0 && (rflags & manifest.fileFlags())) { bool const resourceFound = (manifest.fileFlags() & FF_FOUND) != 0; - String text; - if(printStatus) + if(!text.isEmpty()) text += "\n" _E(0); + + if(withStatus) { text += (resourceFound? " " : _E(1) " ! " _E(.)); } @@ -243,26 +262,29 @@ void Game::printFiles(Game const &game, int rflags, bool printStatus) .arg(!resourceFound? _E(D) : "") .arg(manifest.names().join(_E(l) " or " _E(.))); - if(printStatus) + if(withStatus) { text += String(": ") + _E(>) + (!resourceFound? _E(b) "missing " _E(.) : ""); if(resourceFound) { text += String(_E(C) "\"%1\"").arg(NativePath(manifest.resolvedPath(false/*don't try to locate*/)).expand().pretty()); } + text += _E(<); } - LOG_RES_MSG("") << text; - numPrinted += 1; + text += _E(<); } } } - /* - if(numPrinted == 0) - { - LOG_RES_MSG(" None"); - }*/ + if(text.isEmpty()) return " " DENG2_CHAR_MDASH; + + return text; +} + +void Game::printFiles(Game const &game, int rflags, bool printStatus) +{ + LOG_RES_MSG("") << game.filesAsText(rflags, printStatus); } D_CMD(InspectGame) @@ -296,6 +318,9 @@ D_CMD(InspectGame) DENG2_ASSERT(!game->isNull()); + LOG_MSG("") << game->description(); + +/* LOG_MSG(_E(b) "%s - %s") << game->title() << game->author(); LOG_MSG(_E(l) "IdentityKey: " _E(.) _E(i) "%s " _E(.) _E(l) "PluginId: " _E(.) _E(i) "%s") @@ -308,6 +333,7 @@ D_CMD(InspectGame) Game::printFiles(*game, 0, false); LOG_MSG(_E(D) "Status: " _E(.) _E(b)) << game->statusAsText(); + */ return true; }