]> git.localhorst.tv Git - l2e.git/blob - src/loader/Interpreter.cpp
268fab9379954f35cad3e5abdaa99fa6578215ac
[l2e.git] / src / loader / Interpreter.cpp
1 /*
2  * Interpreter.cpp
3  *
4  *  Created on: Aug 26, 2012
5  *      Author: holy
6  */
7
8 #include "Interpreter.h"
9
10 #include "ParsedSource.h"
11 #include "../battle/Monster.h"
12
13 using battle::Monster;
14 using std::map;
15 using std::set;
16 using std::string;
17
18 namespace loader {
19
20 void Interpreter::ReadSource() {
21         for (set<string>::const_iterator i(source.Exports().begin()), end(source.Exports().end()); i != end; ++i) {
22                 const Definition &dfn(source.GetDefinition(*i));
23                 if (dfn.HasLiteralValue()) {
24                         ReadLiteral(dfn);
25                 } else {
26                         ReadObject(dfn);
27                 }
28         }
29 }
30
31 void Interpreter::ReadLiteral(const Definition &dfn) {
32         switch (dfn.GetLiteral()->GetType()) {
33                 case Literal::ARRAY_VALUES:
34                         throw Error("unhandled literal: array of values");
35                         break;
36                 case Literal::ARRAY_PROPS:
37                         throw Error("unhandled literal: array of values");
38                         break;
39                 case Literal::BOOLEAN:
40                         throw Error("unhandled literal: array of values");
41                         break;
42                 case Literal::COLOR:
43                         throw Error("unhandled literal: array of values");
44                         break;
45                 case Literal::NUMBER:
46                         throw Error("unhandled literal: array of values");
47                         break;
48                 case Literal::STRING:
49                         throw Error("unhandled literal: array of values");
50                         break;
51                 case Literal::VECTOR:
52                         throw Error("unhandled literal: array of values");
53                         break;
54                 case Literal::OBJECT:
55                         throw Error("unhandled literal: array of values");
56                         break;
57         }
58 }
59
60 void Interpreter::ReadObject(const Definition &dfn) {
61         if (dfn.TypeName() == "Monster") {
62                 monsters.resize(monsters.size() + 1);
63                 ReadMonster(monsters.back(), *dfn.GetProperties());
64         } else {
65                 throw Error("unhandled object: " + dfn.TypeName());
66         }
67 }
68
69
70 void Interpreter::ReadMonster(Monster &m, const PropertyList &props) {
71         for (PropertyList::ConstIterator i(props.Begin()), end(props.End()); i != end; ++i) {
72                 if (i->first == "name") {
73                         if (i->second->IsLiteral()) {
74                                 m.SetName(i->second->GetLiteral().GetString().c_str());
75                         } else {
76                                 throw Error("identifier resolution not implemented");
77                         }
78                 } else {
79                         throw Error("unknown monster property: " + i->first);
80                 }
81         }
82 }
83
84 }