]> git.localhorst.tv Git - l2e.git/blob - src/loader/Interpreter.h
added interpretation of Font and Frame 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 <stdexcept>
16 #include <string>
17 #include <vector>
18 #include <SDL.h>
19
20 namespace battle {
21         class Hero;
22         class Monster;
23         class PartyLayout;
24         class Stats;
25 }
26
27 namespace graphics {
28         class Animation;
29         class Font;
30         class Frame;
31         class SimpleAnimation;
32         class Sprite;
33 }
34
35 namespace loader {
36
37 class Definition;
38 class ParsedSource;
39 class PropertyList;
40 class Value;
41
42 class Interpreter {
43
44 public:
45         class Error: public std::runtime_error {
46         public:
47                 Error(const std::string &msg) : std::runtime_error("interpreter error: " + msg) { }
48         };
49
50 public:
51         Interpreter(const ParsedSource &source) : source(source) { }
52         ~Interpreter();
53 private:
54         Interpreter(const Interpreter &);
55         Interpreter &operator =(const Interpreter &);
56
57 public:
58         void ReadSource();
59
60 public:
61         graphics::Animation *GetAnimation(const std::string &name);
62         bool GetBoolean(const std::string &name) const;
63         graphics::Font *GetFont(const std::string &name);
64         graphics::Frame *GetFrame(const std::string &name);
65         battle::Hero *GetHero(const std::string &name);
66         battle::Monster *GetMonster(const std::string &name);
67         int GetNumber(const std::string &name) const;
68         battle::PartyLayout *GetPartyLayout(const std::string &name);
69         graphics::Sprite *GetSprite(const std::string &name);
70         const char *GetString(const std::string &name) const;
71         geometry::Vector<int> GetVector(const std::string &name) const;
72
73 public:
74         const std::vector<bool> &Booleans() const { return booleans; }
75         const std::vector<graphics::ComplexAnimation *> &ComplexAnimations() const { return complexAnimations; }
76         const std::vector<graphics::Font *> &Fonts() const { return fonts; }
77         const std::vector<graphics::Frame *> &Frames() const { return frames; }
78         const std::vector<battle::Hero *> &Heroes() const { return heroes; }
79         const std::vector<SDL_Surface *> &Images() const { return images; }
80         const std::vector<battle::Monster *> &Monsters() const { return monsters; }
81         const std::vector<int> &Numbers() const { return numbers; }
82         const std::vector<battle::PartyLayout *> &PartyLayouts() const { return partyLayouts; }
83         const std::vector<graphics::SimpleAnimation *> &SimpleAnimations() const { return simpleAnimations; }
84         const std::vector<graphics::Sprite *> &Sprites() const { return sprites; }
85         const std::vector<const char *> &Strings() const { return strings; }
86         const std::vector<geometry::Vector<int> > &Vectors() const { return vectors; }
87
88 private:
89         void ReadDefinition(const Definition &);
90         void ReadLiteral(const Definition &);
91         void ReadObject(const Definition &);
92
93         graphics::Animation *GetAnimation(const Value &);
94         bool GetBoolean(const Value &);
95         graphics::Font *GetFont(const Value &);
96         graphics::Frame *GetFrame(const Value &);
97         SDL_Surface *GetImage(const Value &);
98         int GetNumber(const Value &);
99         battle::PartyLayout *GetPartyLayout(const Value &);
100         const PropertyList *GetPropertyList(const Value &);
101         const std::vector<PropertyList *> &GetPropertyListArray(const Value &);
102         graphics::Sprite *GetSprite(const Value &);
103         const char *GetString(const Value &);
104         const std::vector<Value *> &GetValueArray(const Value &);
105         geometry::Vector<int> GetVector(const Value &);
106
107         void ReadComplexAnimation(graphics::ComplexAnimation &, const PropertyList &);
108         void ReadComplexAnimationFrame(graphics::ComplexAnimation::FrameProp &, const PropertyList &);
109         void ReadFont(graphics::Font &, const PropertyList &);
110         void ReadFrame(graphics::Frame &, const PropertyList &);
111         void ReadHero(battle::Hero &, const PropertyList &);
112         void ReadMonster(battle::Monster &, const PropertyList &);
113         void ReadPartyLayout(battle::PartyLayout &, const PropertyList &);
114         void ReadSimpleAnimation(graphics::SimpleAnimation &, const PropertyList &);
115         void ReadSprite(graphics::Sprite &, const PropertyList &);
116         void ReadStats(battle::Stats &, const PropertyList &);
117
118 private:
119         const ParsedSource &source;
120         enum Type {
121                 BOOLEAN,
122                 COMPLEX_ANIMATION,
123                 FONT,
124                 FRAME,
125                 HERO,
126                 IMAGE,
127                 MONSTER,
128                 NUMBER,
129                 PARTY_LAYOUT,
130                 PROPERTY_LIST_ARRAY,
131                 SIMPLE_ANIMATION,
132                 SPRITE,
133                 STRING,
134                 VECTOR,
135                 VALUE_ARRAY,
136         };
137         struct ParsedDefinition {
138                 ParsedDefinition(const Definition *dfn, Type type, int index)
139                 : dfn(dfn), type(type), index(index) { }
140                 const Definition *dfn;
141                 Type type;
142                 int index;
143         };
144         std::map<std::string, ParsedDefinition> parsedDefinitions;
145
146         std::vector<bool> booleans;
147         std::vector<graphics::ComplexAnimation *> complexAnimations;
148         std::vector<graphics::Font *> fonts;
149         std::vector<graphics::Frame *> frames;
150         std::vector<battle::Hero *> heroes;
151         std::vector<SDL_Surface *> images;
152         std::vector<battle::Monster *> monsters;
153         std::vector<int> numbers;
154         std::vector<battle::PartyLayout *> partyLayouts;
155         std::vector<PropertyList *> propertyLists;
156         std::vector<std::vector<PropertyList *> > propertyListArrays;
157         std::vector<graphics::SimpleAnimation *> simpleAnimations;
158         std::vector<graphics::Sprite *> sprites;
159         std::vector<const char *> strings;
160         std::vector<std::vector<Value *> > valueArrays;
161         std::vector<geometry::Vector<int> > vectors;
162
163 };
164
165 }
166
167 #endif /* LOADER_INTERPRETER_H_ */