ADL: Add verbs and nouns debug commands

This commit is contained in:
Walter van Niftrik 2016-03-27 14:36:14 +02:00 committed by Walter van Niftrik
parent 367cb511d1
commit 73dfe71b1b
3 changed files with 70 additions and 0 deletions

View File

@ -171,6 +171,7 @@ struct RoomData {
};
class AdlEngine : public Engine {
friend class Console;
public:
virtual ~AdlEngine();

View File

@ -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

View File

@ -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<Common::String, uint> &wordMap);
AdlEngine *_engine;
};