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"
41 struct MenuProperties;
42 class SimpleAnimation;
56 class Error: public std::runtime_error {
58 Error(const std::string &msg) : std::runtime_error("interpreter error: " + msg) { }
62 Interpreter(const ParsedSource &source) : source(source) { }
65 Interpreter(const Interpreter &);
66 Interpreter &operator =(const Interpreter &);
72 graphics::Animation *GetAnimation(const std::string &name);
73 battle::Resources *GetBattleResources(const std::string &name);
74 bool GetBoolean(const std::string &name) const;
75 const graphics::Color &GetColor(const std::string &name) const;
76 graphics::Font *GetFont(const std::string &name);
77 graphics::Frame *GetFrame(const std::string &name);
78 graphics::Gauge *GetGauge(const std::string &name);
79 battle::Hero *GetHero(const std::string &name);
80 common::Ikari *GetIkari(const std::string &name);
81 common::Item *GetItem(const std::string &name);
82 graphics::MenuProperties *GetMenuProperties(const std::string &name);
83 battle::Monster *GetMonster(const std::string &name);
84 int GetNumber(const std::string &name) const;
85 battle::PartyLayout *GetPartyLayout(const std::string &name);
86 const char *GetPath(const std::string &name) const;
87 common::Spell *GetSpell(const std::string &name);
88 graphics::Sprite *GetSprite(const std::string &name);
89 const char *GetString(const std::string &name) const;
90 common::TargetingMode *GetTargetingMode(const std::string &name);
91 geometry::Vector<int> GetVector(const std::string &name) const;
94 const std::vector<battle::Resources *> &BattleResources() const { return battleResources; }
95 const std::vector<bool> &Booleans() const { return booleans; }
96 const std::vector<graphics::Color> &Colors() const { return colors; }
97 const std::vector<graphics::ComplexAnimation *> &ComplexAnimations() const { return complexAnimations; }
98 const std::vector<graphics::Font *> &Fonts() const { return fonts; }
99 const std::vector<graphics::Frame *> &Frames() const { return frames; }
100 const std::vector<graphics::Gauge *> &Gauges() const { return gauges; }
101 const std::vector<battle::Hero *> &Heroes() const { return heroes; }
102 const std::vector<common::Ikari *> &Ikaris() const { return ikaris; }
103 const std::vector<SDL_Surface *> &Images() const { return images; }
104 const std::vector<common::Item *> &Items() const { return items; }
105 const std::vector<graphics::MenuProperties *> &MenuProperties() const { return menuProperties; }
106 const std::vector<battle::Monster *> &Monsters() const { return monsters; }
107 const std::vector<int> &Numbers() const { return numbers; }
108 const std::vector<battle::PartyLayout *> &PartyLayouts() const { return partyLayouts; }
109 const std::vector<graphics::SimpleAnimation *> &SimpleAnimations() const { return simpleAnimations; }
110 const std::vector<common::Spell *> &Spells() const { return spells; }
111 const std::vector<graphics::Sprite *> &Sprites() const { return sprites; }
112 const std::vector<const char *> &Strings() const { return strings; }
113 const std::vector<common::TargetingMode *> &TargetingModes() const { return targetingModes; }
114 const std::vector<geometry::Vector<int> > &Vectors() const { return vectors; }
117 void ReadDefinition(const Definition &);
118 void ReadLiteral(const Definition &);
119 void ReadObject(const Definition &);
121 graphics::Animation *GetAnimation(const Value &);
122 battle::Resources *GetBattleResources(const Value &);
123 graphics::Color GetColor(const Value &);
124 bool GetBoolean(const Value &);
125 graphics::Font *GetFont(const Value &);
126 graphics::Frame *GetFrame(const Value &);
127 graphics::Gauge *GetGauge(const Value &);
128 battle::Hero *GetHero(const Value &);
129 common::Ikari *GetIkari(const Value &);
130 SDL_Surface *GetImage(const Value &);
131 common::Item *GetItem(const Value &);
132 graphics::MenuProperties *GetMenuProperties(const Value &);
133 battle::Monster *GetMonster(const Value &);
134 int GetNumber(const Value &);
135 battle::PartyLayout *GetPartyLayout(const Value &);
136 const PropertyList *GetPropertyList(const Value &);
137 const std::vector<PropertyList *> &GetPropertyListArray(const Value &);
138 const char *GetPath(const Value &);
139 common::Spell *GetSpell(const Value &);
140 graphics::Sprite *GetSprite(const Value &);
141 const char *GetString(const Value &);
142 common::TargetingMode *GetTargetingMode(const Value &);
143 const std::vector<Value *> &GetValueArray(const Value &);
144 geometry::Vector<int> GetVector(const Value &);
146 void ReadBattleResources(battle::Resources &, const PropertyList &);
147 void ReadComplexAnimation(graphics::ComplexAnimation &, const PropertyList &);
148 void ReadComplexAnimationFrame(graphics::ComplexAnimation::FrameProp &, const PropertyList &);
149 void ReadFont(graphics::Font &, const PropertyList &);
150 void ReadFrame(graphics::Frame &, const PropertyList &);
151 void ReadGauge(graphics::Gauge &, const PropertyList &);
152 void ReadHero(battle::Hero &, const PropertyList &);
153 void ReadIkari(common::Ikari &, const PropertyList &);
154 void ReadItem(common::Item &, const PropertyList &);
155 void ReadMenuProperties(graphics::MenuProperties &, const PropertyList &);
156 void ReadMonster(battle::Monster &, const PropertyList &);
157 void ReadPartyLayout(battle::PartyLayout &, const PropertyList &);
158 void ReadSimpleAnimation(graphics::SimpleAnimation &, const PropertyList &);
159 void ReadSpell(common::Spell &, const PropertyList &);
160 void ReadSprite(graphics::Sprite &, const PropertyList &);
161 void ReadStats(battle::Stats &, const PropertyList &);
162 void ReadTargetingMode(common::TargetingMode &, const PropertyList &);
165 const ParsedSource &source;
192 struct ParsedDefinition {
193 ParsedDefinition(const Definition *dfn, Type type, int index)
194 : dfn(dfn), type(type), index(index) { }
195 const Definition *dfn;
199 std::map<std::string, ParsedDefinition> parsedDefinitions;
201 std::map<std::string, SDL_Surface *> imageCache;
203 std::vector<battle::Resources *> battleResources;
204 std::vector<bool> booleans;
205 std::vector<graphics::Color> colors;
206 std::vector<graphics::ComplexAnimation *> complexAnimations;
207 std::vector<graphics::Font *> fonts;
208 std::vector<graphics::Frame *> frames;
209 std::vector<graphics::Gauge *> gauges;
210 std::vector<battle::Hero *> heroes;
211 std::vector<common::Ikari *> ikaris;
212 std::vector<SDL_Surface *> images;
213 std::vector<common::Item *> items;
214 std::vector<graphics::MenuProperties *> menuProperties;
215 std::vector<battle::Monster *> monsters;
216 std::vector<int> numbers;
217 std::vector<battle::PartyLayout *> partyLayouts;
218 std::vector<PropertyList *> propertyLists;
219 std::vector<std::vector<PropertyList *> > propertyListArrays;
220 std::vector<graphics::SimpleAnimation *> simpleAnimations;
221 std::vector<common::Spell *> spells;
222 std::vector<graphics::Sprite *> sprites;
223 std::vector<const char *> strings;
224 std::vector<common::TargetingMode *> targetingModes;
225 std::vector<std::vector<Value *> > valueArrays;
226 std::vector<geometry::Vector<int> > vectors;
232 #endif /* LOADER_INTERPRETER_H_ */