4 * Created on: Aug 26, 2012
8 #ifndef LOADER_INTERPRETER_H_
9 #define LOADER_INTERPRETER_H_
11 #include "../geometry/Vector.h"
12 #include "../graphics/ComplexAnimation.h"
39 class SimpleAnimation;
53 class Error: public std::runtime_error {
55 Error(const std::string &msg) : std::runtime_error("interpreter error: " + msg) { }
59 Interpreter(const ParsedSource &source) : source(source) { }
62 Interpreter(const Interpreter &);
63 Interpreter &operator =(const Interpreter &);
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 const char *GetPath(const std::string &name) const;
81 common::Spell *GetSpell(const std::string &name);
82 graphics::Sprite *GetSprite(const std::string &name);
83 const char *GetString(const std::string &name) const;
84 common::TargetingMode *GetTargetingMode(const std::string &name);
85 geometry::Vector<int> GetVector(const std::string &name) const;
88 const std::vector<bool> &Booleans() const { return booleans; }
89 const std::vector<graphics::ComplexAnimation *> &ComplexAnimations() const { return complexAnimations; }
90 const std::vector<graphics::Font *> &Fonts() const { return fonts; }
91 const std::vector<graphics::Frame *> &Frames() const { return frames; }
92 const std::vector<graphics::Gauge *> &Gauges() const { return gauges; }
93 const std::vector<battle::Hero *> &Heroes() const { return heroes; }
94 const std::vector<common::Ikari *> &Ikaris() const { return ikaris; }
95 const std::vector<SDL_Surface *> &Images() const { return images; }
96 const std::vector<common::Item *> &Items() const { return items; }
97 const std::vector<battle::Monster *> &Monsters() const { return monsters; }
98 const std::vector<int> &Numbers() const { return numbers; }
99 const std::vector<battle::PartyLayout *> &PartyLayouts() const { return partyLayouts; }
100 const std::vector<graphics::SimpleAnimation *> &SimpleAnimations() const { return simpleAnimations; }
101 const std::vector<common::Spell *> &Spells() const { return spells; }
102 const std::vector<graphics::Sprite *> &Sprites() const { return sprites; }
103 const std::vector<const char *> &Strings() const { return strings; }
104 const std::vector<common::TargetingMode *> &TargetingModes() const { return targetingModes; }
105 const std::vector<geometry::Vector<int> > &Vectors() const { return vectors; }
108 void ReadDefinition(const Definition &);
109 void ReadLiteral(const Definition &);
110 void ReadObject(const Definition &);
112 graphics::Animation *GetAnimation(const Value &);
113 bool GetBoolean(const Value &);
114 graphics::Font *GetFont(const Value &);
115 graphics::Frame *GetFrame(const Value &);
116 graphics::Gauge *GetGauge(const Value &);
117 battle::Hero *GetHero(const Value &);
118 common::Ikari *GetIkari(const Value &);
119 SDL_Surface *GetImage(const Value &);
120 common::Item *GetItem(const Value &);
121 int GetNumber(const Value &);
122 battle::PartyLayout *GetPartyLayout(const Value &);
123 const PropertyList *GetPropertyList(const Value &);
124 const std::vector<PropertyList *> &GetPropertyListArray(const Value &);
125 const char *GetPath(const Value &);
126 common::Spell *GetSpell(const Value &);
127 graphics::Sprite *GetSprite(const Value &);
128 const char *GetString(const Value &);
129 common::TargetingMode *GetTargetingMode(const Value &);
130 const std::vector<Value *> &GetValueArray(const Value &);
131 geometry::Vector<int> GetVector(const Value &);
133 void ReadComplexAnimation(graphics::ComplexAnimation &, const PropertyList &);
134 void ReadComplexAnimationFrame(graphics::ComplexAnimation::FrameProp &, const PropertyList &);
135 void ReadFont(graphics::Font &, const PropertyList &);
136 void ReadFrame(graphics::Frame &, const PropertyList &);
137 void ReadGauge(graphics::Gauge &, const PropertyList &);
138 void ReadHero(battle::Hero &, const PropertyList &);
139 void ReadIkari(common::Ikari &, const PropertyList &);
140 void ReadItem(common::Item &, const PropertyList &);
141 void ReadMonster(battle::Monster &, const PropertyList &);
142 void ReadPartyLayout(battle::PartyLayout &, const PropertyList &);
143 void ReadSimpleAnimation(graphics::SimpleAnimation &, const PropertyList &);
144 void ReadSpell(common::Spell &, const PropertyList &);
145 void ReadSprite(graphics::Sprite &, const PropertyList &);
146 void ReadStats(battle::Stats &, const PropertyList &);
147 void ReadTargetingMode(common::TargetingMode &, const PropertyList &);
150 const ParsedSource &source;
174 struct ParsedDefinition {
175 ParsedDefinition(const Definition *dfn, Type type, int index)
176 : dfn(dfn), type(type), index(index) { }
177 const Definition *dfn;
181 std::map<std::string, ParsedDefinition> parsedDefinitions;
183 std::map<std::string, SDL_Surface *> imageCache;
185 std::vector<bool> booleans;
186 std::vector<graphics::ComplexAnimation *> complexAnimations;
187 std::vector<graphics::Font *> fonts;
188 std::vector<graphics::Frame *> frames;
189 std::vector<graphics::Gauge *> gauges;
190 std::vector<battle::Hero *> heroes;
191 std::vector<common::Ikari *> ikaris;
192 std::vector<SDL_Surface *> images;
193 std::vector<common::Item *> items;
194 std::vector<battle::Monster *> monsters;
195 std::vector<int> numbers;
196 std::vector<battle::PartyLayout *> partyLayouts;
197 std::vector<PropertyList *> propertyLists;
198 std::vector<std::vector<PropertyList *> > propertyListArrays;
199 std::vector<graphics::SimpleAnimation *> simpleAnimations;
200 std::vector<common::Spell *> spells;
201 std::vector<graphics::Sprite *> sprites;
202 std::vector<const char *> strings;
203 std::vector<common::TargetingMode *> targetingModes;
204 std::vector<std::vector<Value *> > valueArrays;
205 std::vector<geometry::Vector<int> > vectors;
211 #endif /* LOADER_INTERPRETER_H_ */