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