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 class SimpleAnimation;
54 class Error: public std::runtime_error {
56 Error(const std::string &msg) : std::runtime_error("interpreter error: " + msg) { }
60 Interpreter(const ParsedSource &source) : source(source) { }
63 Interpreter(const Interpreter &);
64 Interpreter &operator =(const Interpreter &);
70 graphics::Animation *GetAnimation(const std::string &name);
71 bool GetBoolean(const std::string &name) const;
72 const graphics::Color &GetColor(const std::string &name) const;
73 graphics::Font *GetFont(const std::string &name);
74 graphics::Frame *GetFrame(const std::string &name);
75 graphics::Gauge *GetGauge(const std::string &name);
76 battle::Hero *GetHero(const std::string &name);
77 common::Ikari *GetIkari(const std::string &name);
78 common::Item *GetItem(const std::string &name);
79 battle::Monster *GetMonster(const std::string &name);
80 int GetNumber(const std::string &name) const;
81 battle::PartyLayout *GetPartyLayout(const std::string &name);
82 const char *GetPath(const std::string &name) const;
83 common::Spell *GetSpell(const std::string &name);
84 graphics::Sprite *GetSprite(const std::string &name);
85 const char *GetString(const std::string &name) const;
86 common::TargetingMode *GetTargetingMode(const std::string &name);
87 geometry::Vector<int> GetVector(const std::string &name) const;
90 const std::vector<bool> &Booleans() const { return booleans; }
91 const std::vector<graphics::Color> &Colors() const { return colors; }
92 const std::vector<graphics::ComplexAnimation *> &ComplexAnimations() const { return complexAnimations; }
93 const std::vector<graphics::Font *> &Fonts() const { return fonts; }
94 const std::vector<graphics::Frame *> &Frames() const { return frames; }
95 const std::vector<graphics::Gauge *> &Gauges() const { return gauges; }
96 const std::vector<battle::Hero *> &Heroes() const { return heroes; }
97 const std::vector<common::Ikari *> &Ikaris() const { return ikaris; }
98 const std::vector<SDL_Surface *> &Images() const { return images; }
99 const std::vector<common::Item *> &Items() const { return items; }
100 const std::vector<battle::Monster *> &Monsters() const { return monsters; }
101 const std::vector<int> &Numbers() const { return numbers; }
102 const std::vector<battle::PartyLayout *> &PartyLayouts() const { return partyLayouts; }
103 const std::vector<graphics::SimpleAnimation *> &SimpleAnimations() const { return simpleAnimations; }
104 const std::vector<common::Spell *> &Spells() const { return spells; }
105 const std::vector<graphics::Sprite *> &Sprites() const { return sprites; }
106 const std::vector<const char *> &Strings() const { return strings; }
107 const std::vector<common::TargetingMode *> &TargetingModes() const { return targetingModes; }
108 const std::vector<geometry::Vector<int> > &Vectors() const { return vectors; }
111 void ReadDefinition(const Definition &);
112 void ReadLiteral(const Definition &);
113 void ReadObject(const Definition &);
115 graphics::Animation *GetAnimation(const Value &);
116 graphics::Color GetColor(const Value &);
117 bool GetBoolean(const Value &);
118 graphics::Font *GetFont(const Value &);
119 graphics::Frame *GetFrame(const Value &);
120 graphics::Gauge *GetGauge(const Value &);
121 battle::Hero *GetHero(const Value &);
122 common::Ikari *GetIkari(const Value &);
123 SDL_Surface *GetImage(const Value &);
124 common::Item *GetItem(const Value &);
125 int GetNumber(const Value &);
126 battle::PartyLayout *GetPartyLayout(const Value &);
127 const PropertyList *GetPropertyList(const Value &);
128 const std::vector<PropertyList *> &GetPropertyListArray(const Value &);
129 const char *GetPath(const Value &);
130 common::Spell *GetSpell(const Value &);
131 graphics::Sprite *GetSprite(const Value &);
132 const char *GetString(const Value &);
133 common::TargetingMode *GetTargetingMode(const Value &);
134 const std::vector<Value *> &GetValueArray(const Value &);
135 geometry::Vector<int> GetVector(const Value &);
137 void ReadComplexAnimation(graphics::ComplexAnimation &, const PropertyList &);
138 void ReadComplexAnimationFrame(graphics::ComplexAnimation::FrameProp &, const PropertyList &);
139 void ReadFont(graphics::Font &, const PropertyList &);
140 void ReadFrame(graphics::Frame &, const PropertyList &);
141 void ReadGauge(graphics::Gauge &, const PropertyList &);
142 void ReadHero(battle::Hero &, const PropertyList &);
143 void ReadIkari(common::Ikari &, const PropertyList &);
144 void ReadItem(common::Item &, const PropertyList &);
145 void ReadMonster(battle::Monster &, const PropertyList &);
146 void ReadPartyLayout(battle::PartyLayout &, const PropertyList &);
147 void ReadSimpleAnimation(graphics::SimpleAnimation &, const PropertyList &);
148 void ReadSpell(common::Spell &, const PropertyList &);
149 void ReadSprite(graphics::Sprite &, const PropertyList &);
150 void ReadStats(battle::Stats &, const PropertyList &);
151 void ReadTargetingMode(common::TargetingMode &, const PropertyList &);
154 const ParsedSource &source;
179 struct ParsedDefinition {
180 ParsedDefinition(const Definition *dfn, Type type, int index)
181 : dfn(dfn), type(type), index(index) { }
182 const Definition *dfn;
186 std::map<std::string, ParsedDefinition> parsedDefinitions;
188 std::map<std::string, SDL_Surface *> imageCache;
190 std::vector<bool> booleans;
191 std::vector<graphics::Color> colors;
192 std::vector<graphics::ComplexAnimation *> complexAnimations;
193 std::vector<graphics::Font *> fonts;
194 std::vector<graphics::Frame *> frames;
195 std::vector<graphics::Gauge *> gauges;
196 std::vector<battle::Hero *> heroes;
197 std::vector<common::Ikari *> ikaris;
198 std::vector<SDL_Surface *> images;
199 std::vector<common::Item *> items;
200 std::vector<battle::Monster *> monsters;
201 std::vector<int> numbers;
202 std::vector<battle::PartyLayout *> partyLayouts;
203 std::vector<PropertyList *> propertyLists;
204 std::vector<std::vector<PropertyList *> > propertyListArrays;
205 std::vector<graphics::SimpleAnimation *> simpleAnimations;
206 std::vector<common::Spell *> spells;
207 std::vector<graphics::Sprite *> sprites;
208 std::vector<const char *> strings;
209 std::vector<common::TargetingMode *> targetingModes;
210 std::vector<std::vector<Value *> > valueArrays;
211 std::vector<geometry::Vector<int> > vectors;
217 #endif /* LOADER_INTERPRETER_H_ */