]> git.localhorst.tv Git - l2e.git/blob - src/loader/Interpreter.h
added getters for interpreted objects
[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 public:
59         graphics::Animation *GetAnimation(const std::string &name);
60         battle::Hero *GetHero(const std::string &name);
61         battle::Monster *GetMonster(const std::string &name);
62         int GetNumber(const std::string &name) const;
63         graphics::Sprite *GetSprite(const std::string &name);
64
65 private:
66         void ReadDefinition(const Definition &);
67         void ReadLiteral(const Definition &);
68         void ReadObject(const Definition &);
69
70         graphics::Animation *GetAnimation(const Value &);
71         const std::vector<Value *> &GetValueArray(const Value &);
72         const std::vector<PropertyList *> &GetPropertyListArray(const Value &);
73         bool GetBoolean(const Value &);
74         SDL_Surface *GetImage(const Value &);
75         int GetNumber(const Value &);
76         const PropertyList *GetPropertyList(const Value &);
77         graphics::Sprite *GetSprite(const Value &);
78         const char *GetString(const Value &);
79         geometry::Vector<int> GetVector(const Value &);
80
81         void ReadComplexAnimation(graphics::ComplexAnimation &, const PropertyList &);
82         void ReadComplexAnimationFrame(graphics::ComplexAnimation::FrameProp &, const PropertyList &);
83         void ReadHero(battle::Hero &, const PropertyList &);
84         void ReadMonster(battle::Monster &, const PropertyList &);
85         void ReadSimpleAnimation(graphics::SimpleAnimation &, const PropertyList &);
86         void ReadSprite(graphics::Sprite &, const PropertyList &);
87         void ReadStats(battle::Stats &, const PropertyList &);
88
89 private:
90         const ParsedSource &source;
91         std::set<std::string> parsedDefinitions;
92
93         std::map<std::string, graphics::Animation *> animations;
94         std::map<std::string, battle::Hero *> heroes;
95         std::map<std::string, battle::Monster *> monsters;
96         std::map<std::string, int> numbers;
97         std::map<std::string, graphics::Sprite *> sprites;
98
99 };
100
101 }
102
103 #endif /* LOADER_INTERPRETER_H_ */