From 73dfe71b1beaca362463104ed90cdab8a04ea968 Mon Sep 17 00:00:00 2001 From: Walter van Niftrik Date: Sun, 27 Mar 2016 14:36:14 +0200 Subject: ADL: Add verbs and nouns debug commands --- engines/adl/adl.h | 1 + engines/adl/console.cpp | 57 +++++++++++++++++++++++++++++++++++++++++++++++++ engines/adl/console.h | 12 +++++++++++ 3 files changed, 70 insertions(+) (limited to 'engines/adl') diff --git a/engines/adl/adl.h b/engines/adl/adl.h index d9fc5908b4..4367e8b917 100644 --- a/engines/adl/adl.h +++ b/engines/adl/adl.h @@ -171,6 +171,7 @@ struct RoomData { }; class AdlEngine : public Engine { +friend class Console; public: virtual ~AdlEngine(); diff --git a/engines/adl/console.cpp b/engines/adl/console.cpp index e051716a6c..5fe7f08a18 100644 --- a/engines/adl/console.cpp +++ b/engines/adl/console.cpp @@ -21,11 +21,68 @@ */ #include "adl/console.h" +#include "adl/adl.h" namespace Adl { Console::Console(AdlEngine *engine) : GUI::Debugger() { _engine = engine; + + registerCmd("help", WRAP_METHOD(Console, Cmd_Help)); + registerCmd("nouns", WRAP_METHOD(Console, Cmd_Nouns)); + registerCmd("verbs", WRAP_METHOD(Console, Cmd_Verbs)); +} + +static Common::String toAscii(const Common::String &str) { + Common::String ascii(str); + + for (uint i = 0; i < ascii.size(); ++i) + ascii.setChar(ascii[i] & 0x7f, i); + + return ascii; +} + +bool Console::Cmd_Help(int argc, const char **argv) { + debugPrintf("Parser:\n"); + debugPrintf(" verbs - Lists the vocabulary verbs\n"); + debugPrintf(" nouns - Lists the vocabulary nouns\n"); + return true; +} + +bool Console::Cmd_Verbs(int argc, const char **argv) { + if (argc != 1) { + debugPrintf("Usage: %s\n", argv[0]); + return true; + } + + debugPrintf("Verbs in alphabetical order:\n"); + printWordMap(_engine->_verbs); + return true; +} + +bool Console::Cmd_Nouns(int argc, const char **argv) { + if (argc != 1) { + debugPrintf("Usage: %s\n", argv[0]); + return true; + } + + debugPrintf("Nouns in alphabetical order:\n"); + printWordMap(_engine->_nouns); + return true; +} + +void Console::printWordMap(const WordMap &wordMap) { + Common::StringArray words; + WordMap::const_iterator verb; + + for (verb = wordMap.begin(); verb != wordMap.end(); ++verb) + words.push_back(verb->_key); + + Common::sort(words.begin(), words.end()); + + Common::StringArray::const_iterator word; + for (word = words.begin(); word != words.end(); ++word) + debugPrintf("%s: %d\n", toAscii(*word).c_str(), wordMap[*word]); } } // End of namespace Adl diff --git a/engines/adl/console.h b/engines/adl/console.h index 56c84f08fa..d8a6525541 100644 --- a/engines/adl/console.h +++ b/engines/adl/console.h @@ -25,6 +25,12 @@ #include "gui/debugger.h" +#include "common/hashmap.h" + +namespace Common { +class String; +} + namespace Adl { class AdlEngine; @@ -34,6 +40,12 @@ public: Console(AdlEngine *engine); private: + bool Cmd_Help(int argc, const char **argv); + bool Cmd_Nouns(int argc, const char **argv); + bool Cmd_Verbs(int argc, const char **argv); + + void printWordMap(const Common::HashMap &wordMap); + AdlEngine *_engine; }; -- cgit v1.2.3