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