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