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