]> git.localhorst.tv Git - l2e.git/blob - src/loader/Interpreter.h
e72d4da202d43a99ae0bf8a1490c49ff7570ffbf
[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/Color.h"
13 #include "../graphics/ComplexAnimation.h"
14
15 #include <map>
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 PartyLayout;
25         class Stats;
26 }
27
28 namespace common {
29         class Ikari;
30         class Item;
31         class Spell;
32         class TargetingMode;
33 }
34
35 namespace graphics {
36         class Animation;
37         class Font;
38         class Frame;
39         class Gauge;
40         struct MenuProperties;
41         class SimpleAnimation;
42         class Sprite;
43 }
44
45 namespace loader {
46
47 class Definition;
48 class ParsedSource;
49 class PropertyList;
50 class Value;
51
52 class Interpreter {
53
54 public:
55         class Error: public std::runtime_error {
56         public:
57                 Error(const std::string &msg) : std::runtime_error("interpreter error: " + msg) { }
58         };
59
60 public:
61         Interpreter(const ParsedSource &source) : source(source) { }
62         ~Interpreter();
63 private:
64         Interpreter(const Interpreter &);
65         Interpreter &operator =(const Interpreter &);
66
67 public:
68         void ReadSource();
69
70 public:
71         graphics::Animation *GetAnimation(const std::string &name);
72         bool GetBoolean(const std::string &name) const;
73         const graphics::Color &GetColor(const std::string &name) const;
74         graphics::Font *GetFont(const std::string &name);
75         graphics::Frame *GetFrame(const std::string &name);
76         graphics::Gauge *GetGauge(const std::string &name);
77         battle::Hero *GetHero(const std::string &name);
78         common::Ikari *GetIkari(const std::string &name);
79         common::Item *GetItem(const std::string &name);
80         graphics::MenuProperties *GetMenuProperties(const std::string &name);
81         battle::Monster *GetMonster(const std::string &name);
82         int GetNumber(const std::string &name) const;
83         battle::PartyLayout *GetPartyLayout(const std::string &name);
84         const char *GetPath(const std::string &name) const;
85         common::Spell *GetSpell(const std::string &name);
86         graphics::Sprite *GetSprite(const std::string &name);
87         const char *GetString(const std::string &name) const;
88         common::TargetingMode *GetTargetingMode(const std::string &name);
89         geometry::Vector<int> GetVector(const std::string &name) const;
90
91 public:
92         const std::vector<bool> &Booleans() const { return booleans; }
93         const std::vector<graphics::Color> &Colors() const { return colors; }
94         const std::vector<graphics::ComplexAnimation *> &ComplexAnimations() const { return complexAnimations; }
95         const std::vector<graphics::Font *> &Fonts() const { return fonts; }
96         const std::vector<graphics::Frame *> &Frames() const { return frames; }
97         const std::vector<graphics::Gauge *> &Gauges() const { return gauges; }
98         const std::vector<battle::Hero *> &Heroes() const { return heroes; }
99         const std::vector<common::Ikari *> &Ikaris() const { return ikaris; }
100         const std::vector<SDL_Surface *> &Images() const { return images; }
101         const std::vector<common::Item *> &Items() const { return items; }
102         const std::vector<graphics::MenuProperties *> &MenuProperties() const { return menuProperties; }
103         const std::vector<battle::Monster *> &Monsters() const { return monsters; }
104         const std::vector<int> &Numbers() const { return numbers; }
105         const std::vector<battle::PartyLayout *> &PartyLayouts() const { return partyLayouts; }
106         const std::vector<graphics::SimpleAnimation *> &SimpleAnimations() const { return simpleAnimations; }
107         const std::vector<common::Spell *> &Spells() const { return spells; }
108         const std::vector<graphics::Sprite *> &Sprites() const { return sprites; }
109         const std::vector<const char *> &Strings() const { return strings; }
110         const std::vector<common::TargetingMode *> &TargetingModes() const { return targetingModes; }
111         const std::vector<geometry::Vector<int> > &Vectors() const { return vectors; }
112
113 private:
114         void ReadDefinition(const Definition &);
115         void ReadLiteral(const Definition &);
116         void ReadObject(const Definition &);
117
118         graphics::Animation *GetAnimation(const Value &);
119         graphics::Color GetColor(const Value &);
120         bool GetBoolean(const Value &);
121         graphics::Font *GetFont(const Value &);
122         graphics::Frame *GetFrame(const Value &);
123         graphics::Gauge *GetGauge(const Value &);
124         battle::Hero *GetHero(const Value &);
125         common::Ikari *GetIkari(const Value &);
126         SDL_Surface *GetImage(const Value &);
127         common::Item *GetItem(const Value &);
128         graphics::MenuProperties *GetMenuProperties(const Value &);
129         battle::Monster *GetMonster(const Value &);
130         int GetNumber(const Value &);
131         battle::PartyLayout *GetPartyLayout(const Value &);
132         const PropertyList *GetPropertyList(const Value &);
133         const std::vector<PropertyList *> &GetPropertyListArray(const Value &);
134         const char *GetPath(const Value &);
135         common::Spell *GetSpell(const Value &);
136         graphics::Sprite *GetSprite(const Value &);
137         const char *GetString(const Value &);
138         common::TargetingMode *GetTargetingMode(const Value &);
139         const std::vector<Value *> &GetValueArray(const Value &);
140         geometry::Vector<int> GetVector(const Value &);
141
142         void ReadComplexAnimation(graphics::ComplexAnimation &, const PropertyList &);
143         void ReadComplexAnimationFrame(graphics::ComplexAnimation::FrameProp &, const PropertyList &);
144         void ReadFont(graphics::Font &, const PropertyList &);
145         void ReadFrame(graphics::Frame &, const PropertyList &);
146         void ReadGauge(graphics::Gauge &, const PropertyList &);
147         void ReadHero(battle::Hero &, const PropertyList &);
148         void ReadIkari(common::Ikari &, const PropertyList &);
149         void ReadItem(common::Item &, const PropertyList &);
150         void ReadMenuProperties(graphics::MenuProperties &, const PropertyList &);
151         void ReadMonster(battle::Monster &, const PropertyList &);
152         void ReadPartyLayout(battle::PartyLayout &, const PropertyList &);
153         void ReadSimpleAnimation(graphics::SimpleAnimation &, const PropertyList &);
154         void ReadSpell(common::Spell &, const PropertyList &);
155         void ReadSprite(graphics::Sprite &, const PropertyList &);
156         void ReadStats(battle::Stats &, const PropertyList &);
157         void ReadTargetingMode(common::TargetingMode &, const PropertyList &);
158
159 private:
160         const ParsedSource &source;
161         enum Type {
162                 BOOLEAN,
163                 COLOR,
164                 COMPLEX_ANIMATION,
165                 FONT,
166                 FRAME,
167                 GAUGE,
168                 HERO,
169                 IKARI,
170                 IMAGE,
171                 ITEM,
172                 MENU_PROPERTIES,
173                 MONSTER,
174                 NUMBER,
175                 PARTY_LAYOUT,
176                 PATH,
177                 PROPERTY_LIST_ARRAY,
178                 SIMPLE_ANIMATION,
179                 SPELL,
180                 SPRITE,
181                 STRING,
182                 TARGETING_MODE,
183                 VECTOR,
184                 VALUE_ARRAY,
185         };
186         struct ParsedDefinition {
187                 ParsedDefinition(const Definition *dfn, Type type, int index)
188                 : dfn(dfn), type(type), index(index) { }
189                 const Definition *dfn;
190                 Type type;
191                 int index;
192         };
193         std::map<std::string, ParsedDefinition> parsedDefinitions;
194
195         std::map<std::string, SDL_Surface *> imageCache;
196
197         std::vector<bool> booleans;
198         std::vector<graphics::Color> colors;
199         std::vector<graphics::ComplexAnimation *> complexAnimations;
200         std::vector<graphics::Font *> fonts;
201         std::vector<graphics::Frame *> frames;
202         std::vector<graphics::Gauge *> gauges;
203         std::vector<battle::Hero *> heroes;
204         std::vector<common::Ikari *> ikaris;
205         std::vector<SDL_Surface *> images;
206         std::vector<common::Item *> items;
207         std::vector<graphics::MenuProperties *> menuProperties;
208         std::vector<battle::Monster *> monsters;
209         std::vector<int> numbers;
210         std::vector<battle::PartyLayout *> partyLayouts;
211         std::vector<PropertyList *> propertyLists;
212         std::vector<std::vector<PropertyList *> > propertyListArrays;
213         std::vector<graphics::SimpleAnimation *> simpleAnimations;
214         std::vector<common::Spell *> spells;
215         std::vector<graphics::Sprite *> sprites;
216         std::vector<const char *> strings;
217         std::vector<common::TargetingMode *> targetingModes;
218         std::vector<std::vector<Value *> > valueArrays;
219         std::vector<geometry::Vector<int> > vectors;
220
221 };
222
223 }
224
225 #endif /* LOADER_INTERPRETER_H_ */