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"
37 class SimpleAnimation;
51 class Error: public std::runtime_error {
53 Error(const std::string &msg) : std::runtime_error("interpreter error: " + msg) { }
57 Interpreter(const ParsedSource &source) : source(source) { }
60 Interpreter(const Interpreter &);
61 Interpreter &operator =(const Interpreter &);
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;
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; }
101 void ReadDefinition(const Definition &);
102 void ReadLiteral(const Definition &);
103 void ReadObject(const Definition &);
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 &);
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 &);
137 const ParsedSource &source;
158 struct ParsedDefinition {
159 ParsedDefinition(const Definition *dfn, Type type, int index)
160 : dfn(dfn), type(type), index(index) { }
161 const Definition *dfn;
165 std::map<std::string, ParsedDefinition> parsedDefinitions;
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;
191 #endif /* LOADER_INTERPRETER_H_ */