]> git.localhorst.tv Git - l2e.git/blob - src/loader/Interpreter.h
interpretation of Heros and Monsters
[l2e.git] / src / loader / Interpreter.h
1 /*
2  * Interpreter.h
3  *
4  *  Created on: Aug 26, 2012
5  *      Author: holy
6  */
7
8 #ifndef LOADER_INTERPRETER_H_
9 #define LOADER_INTERPRETER_H_
10
11 #include "../geometry/Vector.h"
12 #include "../graphics/ComplexAnimation.h"
13
14 #include <map>
15 #include <set>
16 #include <stdexcept>
17 #include <string>
18 #include <vector>
19 #include <SDL.h>
20
21 namespace battle {
22         class Hero;
23         class Monster;
24         class Stats;
25 }
26
27 namespace graphics {
28         class Animation;
29         class SimpleAnimation;
30         class Sprite;
31 }
32
33 namespace loader {
34
35 class Definition;
36 class ParsedSource;
37 class PropertyList;
38 class Value;
39
40 class Interpreter {
41
42 public:
43         class Error: public std::runtime_error {
44         public:
45                 Error(const std::string &msg) : std::runtime_error("interpreter error: " + msg) { }
46         };
47
48 public:
49         Interpreter(const ParsedSource &source) : source(source) { }
50         ~Interpreter() { }
51 private:
52         Interpreter(const Interpreter &);
53         Interpreter &operator =(const Interpreter &);
54
55 public:
56         void ReadSource();
57
58 private:
59         void ReadDefinition(const Definition &);
60         void ReadLiteral(const Definition &);
61         void ReadObject(const Definition &);
62
63         graphics::Animation *GetAnimation(const Value &);
64         const std::vector<Value *> &GetValueArray(const Value &);
65         const std::vector<PropertyList *> &GetPropertyListArray(const Value &);
66         bool GetBoolean(const Value &);
67         SDL_Surface *GetImage(const Value &);
68         int GetNumber(const Value &);
69         const PropertyList *GetPropertyList(const Value &);
70         graphics::Sprite *GetSprite(const Value &);
71         const char *GetString(const Value &);
72         geometry::Vector<int> GetVector(const Value &);
73
74         void ReadComplexAnimation(graphics::ComplexAnimation &, const PropertyList &);
75         void ReadComplexAnimationFrame(graphics::ComplexAnimation::FrameProp &, const PropertyList &);
76         void ReadHero(battle::Hero &, const PropertyList &);
77         void ReadMonster(battle::Monster &, const PropertyList &);
78         void ReadSimpleAnimation(graphics::SimpleAnimation &, const PropertyList &);
79         void ReadSprite(graphics::Sprite &, const PropertyList &);
80         void ReadStats(battle::Stats &, const PropertyList &);
81
82 private:
83         const ParsedSource &source;
84         std::set<std::string> parsedDefinitions;
85
86         std::map<std::string, graphics::Animation *> animations;
87         std::map<std::string, battle::Hero *> heroes;
88         std::map<std::string, battle::Monster *> monsters;
89         std::map<std::string, int> numbers;
90         std::map<std::string, graphics::Sprite *> sprites;
91
92 };
93
94 }
95
96 #endif /* LOADER_INTERPRETER_H_ */