4 * Created on: Aug 26, 2012
8 #ifndef LOADER_INTERPRETER_H_
9 #define LOADER_INTERPRETER_H_
11 #include "../geometry/Vector.h"
12 #include "../graphics/Color.h"
13 #include "../graphics/ComplexAnimation.h"
40 struct MenuProperties;
41 class SimpleAnimation;
55 class Error: public std::runtime_error {
57 Error(const std::string &msg) : std::runtime_error("interpreter error: " + msg) { }
61 Interpreter(const ParsedSource &source) : source(source) { }
64 Interpreter(const Interpreter &);
65 Interpreter &operator =(const Interpreter &);
71 graphics::Animation *GetAnimation(const std::string &name);
72 bool GetBoolean(const std::string &name) const;
73 const graphics::Color &GetColor(const std::string &name) const;
74 graphics::Font *GetFont(const std::string &name);
75 graphics::Frame *GetFrame(const std::string &name);
76 graphics::Gauge *GetGauge(const std::string &name);
77 battle::Hero *GetHero(const std::string &name);
78 common::Ikari *GetIkari(const std::string &name);
79 common::Item *GetItem(const std::string &name);
80 graphics::MenuProperties *GetMenuProperties(const std::string &name);
81 battle::Monster *GetMonster(const std::string &name);
82 int GetNumber(const std::string &name) const;
83 battle::PartyLayout *GetPartyLayout(const std::string &name);
84 const char *GetPath(const std::string &name) const;
85 common::Spell *GetSpell(const std::string &name);
86 graphics::Sprite *GetSprite(const std::string &name);
87 const char *GetString(const std::string &name) const;
88 common::TargetingMode *GetTargetingMode(const std::string &name);
89 geometry::Vector<int> GetVector(const std::string &name) const;
92 const std::vector<bool> &Booleans() const { return booleans; }
93 const std::vector<graphics::Color> &Colors() const { return colors; }
94 const std::vector<graphics::ComplexAnimation *> &ComplexAnimations() const { return complexAnimations; }
95 const std::vector<graphics::Font *> &Fonts() const { return fonts; }
96 const std::vector<graphics::Frame *> &Frames() const { return frames; }
97 const std::vector<graphics::Gauge *> &Gauges() const { return gauges; }
98 const std::vector<battle::Hero *> &Heroes() const { return heroes; }
99 const std::vector<common::Ikari *> &Ikaris() const { return ikaris; }
100 const std::vector<SDL_Surface *> &Images() const { return images; }
101 const std::vector<common::Item *> &Items() const { return items; }
102 const std::vector<graphics::MenuProperties *> &MenuProperties() const { return menuProperties; }
103 const std::vector<battle::Monster *> &Monsters() const { return monsters; }
104 const std::vector<int> &Numbers() const { return numbers; }
105 const std::vector<battle::PartyLayout *> &PartyLayouts() const { return partyLayouts; }
106 const std::vector<graphics::SimpleAnimation *> &SimpleAnimations() const { return simpleAnimations; }
107 const std::vector<common::Spell *> &Spells() const { return spells; }
108 const std::vector<graphics::Sprite *> &Sprites() const { return sprites; }
109 const std::vector<const char *> &Strings() const { return strings; }
110 const std::vector<common::TargetingMode *> &TargetingModes() const { return targetingModes; }
111 const std::vector<geometry::Vector<int> > &Vectors() const { return vectors; }
114 void ReadDefinition(const Definition &);
115 void ReadLiteral(const Definition &);
116 void ReadObject(const Definition &);
118 graphics::Animation *GetAnimation(const Value &);
119 graphics::Color GetColor(const Value &);
120 bool GetBoolean(const Value &);
121 graphics::Font *GetFont(const Value &);
122 graphics::Frame *GetFrame(const Value &);
123 graphics::Gauge *GetGauge(const Value &);
124 battle::Hero *GetHero(const Value &);
125 common::Ikari *GetIkari(const Value &);
126 SDL_Surface *GetImage(const Value &);
127 common::Item *GetItem(const Value &);
128 graphics::MenuProperties *GetMenuProperties(const Value &);
129 battle::Monster *GetMonster(const Value &);
130 int GetNumber(const Value &);
131 battle::PartyLayout *GetPartyLayout(const Value &);
132 const PropertyList *GetPropertyList(const Value &);
133 const std::vector<PropertyList *> &GetPropertyListArray(const Value &);
134 const char *GetPath(const Value &);
135 common::Spell *GetSpell(const Value &);
136 graphics::Sprite *GetSprite(const Value &);
137 const char *GetString(const Value &);
138 common::TargetingMode *GetTargetingMode(const Value &);
139 const std::vector<Value *> &GetValueArray(const Value &);
140 geometry::Vector<int> GetVector(const Value &);
142 void ReadComplexAnimation(graphics::ComplexAnimation &, const PropertyList &);
143 void ReadComplexAnimationFrame(graphics::ComplexAnimation::FrameProp &, const PropertyList &);
144 void ReadFont(graphics::Font &, const PropertyList &);
145 void ReadFrame(graphics::Frame &, const PropertyList &);
146 void ReadGauge(graphics::Gauge &, const PropertyList &);
147 void ReadHero(battle::Hero &, const PropertyList &);
148 void ReadIkari(common::Ikari &, const PropertyList &);
149 void ReadItem(common::Item &, const PropertyList &);
150 void ReadMenuProperties(graphics::MenuProperties &, const PropertyList &);
151 void ReadMonster(battle::Monster &, const PropertyList &);
152 void ReadPartyLayout(battle::PartyLayout &, const PropertyList &);
153 void ReadSimpleAnimation(graphics::SimpleAnimation &, const PropertyList &);
154 void ReadSpell(common::Spell &, const PropertyList &);
155 void ReadSprite(graphics::Sprite &, const PropertyList &);
156 void ReadStats(battle::Stats &, const PropertyList &);
157 void ReadTargetingMode(common::TargetingMode &, const PropertyList &);
160 const ParsedSource &source;
186 struct ParsedDefinition {
187 ParsedDefinition(const Definition *dfn, Type type, int index)
188 : dfn(dfn), type(type), index(index) { }
189 const Definition *dfn;
193 std::map<std::string, ParsedDefinition> parsedDefinitions;
195 std::map<std::string, SDL_Surface *> imageCache;
197 std::vector<bool> booleans;
198 std::vector<graphics::Color> colors;
199 std::vector<graphics::ComplexAnimation *> complexAnimations;
200 std::vector<graphics::Font *> fonts;
201 std::vector<graphics::Frame *> frames;
202 std::vector<graphics::Gauge *> gauges;
203 std::vector<battle::Hero *> heroes;
204 std::vector<common::Ikari *> ikaris;
205 std::vector<SDL_Surface *> images;
206 std::vector<common::Item *> items;
207 std::vector<graphics::MenuProperties *> menuProperties;
208 std::vector<battle::Monster *> monsters;
209 std::vector<int> numbers;
210 std::vector<battle::PartyLayout *> partyLayouts;
211 std::vector<PropertyList *> propertyLists;
212 std::vector<std::vector<PropertyList *> > propertyListArrays;
213 std::vector<graphics::SimpleAnimation *> simpleAnimations;
214 std::vector<common::Spell *> spells;
215 std::vector<graphics::Sprite *> sprites;
216 std::vector<const char *> strings;
217 std::vector<common::TargetingMode *> targetingModes;
218 std::vector<std::vector<Value *> > valueArrays;
219 std::vector<geometry::Vector<int> > vectors;
225 #endif /* LOADER_INTERPRETER_H_ */