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