Debian Codegraph @

plugins/dm.conversation/ConversationCommandInfo.cpp

raw
1 #include "ConversationCommandInfo.h"
2
3 #include "string/string.h"
4 #include "itextstream.h"
5 #include "eclass.h"
6
7 namespace conversation {
8
9 // initialise the static member variable
10 int ConversationCommandInfo::_highestId = 0;
11
12 void ConversationCommandInfo::parseFromEntityClass(const IEntityClassPtr& eclass)
13 {
14 assert(eclass != NULL); // don't accept NULL pointers
15
16 name = eclass->getAttributeValue("editor_cmdName");
17 waitUntilFinishedAllowed = (eclass->getAttributeValue("editor_waitUntilFinishedAllowed") == "1");
18 sentence = eclass->getAttributeValue("editor_sentence");
19
20 // Read the arguments
21 // Find all attributes matching "argType", this spawnarg is mandatory
22 eclass::AttributeList argTypes = eclass::getSpawnargsWithPrefix(
23 eclass, "editor_argType"
24 );
25
26 for (eclass::AttributeList::const_iterator i = argTypes.begin();
27 i != argTypes.end();
28 ++i)
29 {
30 // Cut off the "editor_argType" part and retrieve the number
31 std::string argIndex = i->getName().substr(14);
32
33 ArgumentInfo info;
34
35 info.required = (eclass->getAttributeValue("editor_argRequired" + argIndex) != "0");
36 info.description = eclass->getAttributeValue("editor_argDesc" + argIndex);
37 info.title = eclass->getAttributeValue("editor_argTitle" + argIndex);
38
39 std::string argTypeStr = eclass->getAttributeValue("editor_argType" + argIndex);
40 if (argTypeStr == "float") {
41 info.type = ArgumentInfo::ARGTYPE_FLOAT;
42 }
43 else if (argTypeStr == "int") {
44 info.type = ArgumentInfo::ARGTYPE_INT;
45 }
46 else if (argTypeStr == "string") {
47 info.type = ArgumentInfo::ARGTYPE_STRING;
48 }
49 else if (argTypeStr == "vector") {
50 info.type = ArgumentInfo::ARGTYPE_VECTOR;
51 }
52 else if (argTypeStr == "soundshader") {
53 info.type = ArgumentInfo::ARGTYPE_SOUNDSHADER;
54 }
55 else if (argTypeStr == "actor") {
56 info.type = ArgumentInfo::ARGTYPE_ACTOR;
57 }
58 else if (argTypeStr == "entity") {
59 info.type = ArgumentInfo::ARGTYPE_ENTITY;
60 }
61 else if (argTypeStr == "bool") {
62 info.type = ArgumentInfo::ARGTYPE_BOOL;
63 }
64 else {
65 rError() << "Could not determine Conversation Command Argument type: " <<
66 argTypeStr << " on entityDef " << eclass->getDeclName() << std::endl;
67 }
68
69 // add the argument to the local list
70 arguments.push_back(info);
71 }
72 }
73
74 } // namespace conversation