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