]> git.localhorst.tv Git - l2e.git/blob - src/loader/Interpreter.h
split complex and simple animations in interpreter
[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 <stdexcept>
16 #include <string>
17 #include <vector>
18 #include <SDL.h>
19
20 namespace battle {
21         class Hero;
22         class Monster;
23         class Stats;
24 }
25
26 namespace graphics {
27         class Animation;
28         class SimpleAnimation;
29         class Sprite;
30 }
31
32 namespace loader {
33
34 class Definition;
35 class ParsedSource;
36 class PropertyList;
37 class Value;
38
39 class Interpreter {
40
41 public:
42         class Error: public std::runtime_error {
43         public:
44                 Error(const std::string &msg) : std::runtime_error("interpreter error: " + msg) { }
45         };
46
47 public:
48         Interpreter(const ParsedSource &source) : source(source) { }
49         ~Interpreter();
50 private:
51         Interpreter(const Interpreter &);
52         Interpreter &operator =(const Interpreter &);
53
54 public:
55         void ReadSource();
56
57 public:
58         graphics::Animation *GetAnimation(const std::string &name);
59         battle::Hero *GetHero(const std::string &name);
60         battle::Monster *GetMonster(const std::string &name);
61         int GetNumber(const std::string &name) const;
62         graphics::Sprite *GetSprite(const std::string &name);
63
64 private:
65         void ReadDefinition(const Definition &);
66         void ReadLiteral(const Definition &);
67         void ReadObject(const Definition &);
68
69         graphics::Animation *GetAnimation(const Value &);
70         const std::vector<Value *> &GetValueArray(const Value &);
71         const std::vector<PropertyList *> &GetPropertyListArray(const Value &);
72         bool GetBoolean(const Value &);
73         SDL_Surface *GetImage(const Value &);
74         int GetNumber(const Value &);
75         const PropertyList *GetPropertyList(const Value &);
76         graphics::Sprite *GetSprite(const Value &);
77         const char *GetString(const Value &);
78         geometry::Vector<int> GetVector(const Value &);
79
80         void ReadComplexAnimation(graphics::ComplexAnimation &, const PropertyList &);
81         void ReadComplexAnimationFrame(graphics::ComplexAnimation::FrameProp &, const PropertyList &);
82         void ReadHero(battle::Hero &, const PropertyList &);
83         void ReadMonster(battle::Monster &, const PropertyList &);
84         void ReadSimpleAnimation(graphics::SimpleAnimation &, const PropertyList &);
85         void ReadSprite(graphics::Sprite &, const PropertyList &);
86         void ReadStats(battle::Stats &, const PropertyList &);
87
88 private:
89         const ParsedSource &source;
90         enum Type {
91                 COMPLEX_ANIMATION,
92                 HERO,
93                 MONSTER,
94                 NUMBER,
95                 SIMPLE_ANIMATION,
96                 SPRITE,
97         };
98         struct ParsedDefinition {
99                 ParsedDefinition(const Definition *dfn, Type type, int index)
100                 : dfn(dfn), type(type), index(index) { }
101                 const Definition *dfn;
102                 Type type;
103                 int index;
104         };
105         std::map<std::string, ParsedDefinition> parsedDefinitions;
106
107         std::vector<graphics::ComplexAnimation *> complexAnimations;
108         std::vector<battle::Hero *> heroes;
109         std::vector<SDL_Surface *> images;
110         std::vector<battle::Monster *> monsters;
111         std::vector<int> numbers;
112         std::vector<graphics::SimpleAnimation *> simpleAnimations;
113         std::vector<graphics::Sprite *> sprites;
114
115 };
116
117 }
118
119 #endif /* LOADER_INTERPRETER_H_ */