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"
32 class SimpleAnimation;
46 class Error: public std::runtime_error {
48 Error(const std::string &msg) : std::runtime_error("interpreter error: " + msg) { }
52 Interpreter(const ParsedSource &source) : source(source) { }
55 Interpreter(const Interpreter &);
56 Interpreter &operator =(const Interpreter &);
62 graphics::Animation *GetAnimation(const std::string &name);
63 bool GetBoolean(const std::string &name) const;
64 graphics::Font *GetFont(const std::string &name);
65 graphics::Frame *GetFrame(const std::string &name);
66 graphics::Gauge *GetGauge(const std::string &name);
67 battle::Hero *GetHero(const std::string &name);
68 battle::Monster *GetMonster(const std::string &name);
69 int GetNumber(const std::string &name) const;
70 battle::PartyLayout *GetPartyLayout(const std::string &name);
71 graphics::Sprite *GetSprite(const std::string &name);
72 const char *GetString(const std::string &name) const;
73 geometry::Vector<int> GetVector(const std::string &name) const;
76 const std::vector<bool> &Booleans() const { return booleans; }
77 const std::vector<graphics::ComplexAnimation *> &ComplexAnimations() const { return complexAnimations; }
78 const std::vector<graphics::Font *> &Fonts() const { return fonts; }
79 const std::vector<graphics::Frame *> &Frames() const { return frames; }
80 const std::vector<graphics::Gauge *> &Gauges() const { return gauges; }
81 const std::vector<battle::Hero *> &Heroes() const { return heroes; }
82 const std::vector<SDL_Surface *> &Images() const { return images; }
83 const std::vector<battle::Monster *> &Monsters() const { return monsters; }
84 const std::vector<int> &Numbers() const { return numbers; }
85 const std::vector<battle::PartyLayout *> &PartyLayouts() const { return partyLayouts; }
86 const std::vector<graphics::SimpleAnimation *> &SimpleAnimations() const { return simpleAnimations; }
87 const std::vector<graphics::Sprite *> &Sprites() const { return sprites; }
88 const std::vector<const char *> &Strings() const { return strings; }
89 const std::vector<geometry::Vector<int> > &Vectors() const { return vectors; }
92 void ReadDefinition(const Definition &);
93 void ReadLiteral(const Definition &);
94 void ReadObject(const Definition &);
96 graphics::Animation *GetAnimation(const Value &);
97 bool GetBoolean(const Value &);
98 graphics::Font *GetFont(const Value &);
99 graphics::Frame *GetFrame(const Value &);
100 graphics::Gauge *GetGauge(const Value &);
101 SDL_Surface *GetImage(const Value &);
102 int GetNumber(const Value &);
103 battle::PartyLayout *GetPartyLayout(const Value &);
104 const PropertyList *GetPropertyList(const Value &);
105 const std::vector<PropertyList *> &GetPropertyListArray(const Value &);
106 graphics::Sprite *GetSprite(const Value &);
107 const char *GetString(const Value &);
108 const std::vector<Value *> &GetValueArray(const Value &);
109 geometry::Vector<int> GetVector(const Value &);
111 void ReadComplexAnimation(graphics::ComplexAnimation &, const PropertyList &);
112 void ReadComplexAnimationFrame(graphics::ComplexAnimation::FrameProp &, const PropertyList &);
113 void ReadFont(graphics::Font &, const PropertyList &);
114 void ReadFrame(graphics::Frame &, const PropertyList &);
115 void ReadGauge(graphics::Gauge &, const PropertyList &);
116 void ReadHero(battle::Hero &, const PropertyList &);
117 void ReadMonster(battle::Monster &, const PropertyList &);
118 void ReadPartyLayout(battle::PartyLayout &, const PropertyList &);
119 void ReadSimpleAnimation(graphics::SimpleAnimation &, const PropertyList &);
120 void ReadSprite(graphics::Sprite &, const PropertyList &);
121 void ReadStats(battle::Stats &, const PropertyList &);
124 const ParsedSource &source;
143 struct ParsedDefinition {
144 ParsedDefinition(const Definition *dfn, Type type, int index)
145 : dfn(dfn), type(type), index(index) { }
146 const Definition *dfn;
150 std::map<std::string, ParsedDefinition> parsedDefinitions;
152 std::vector<bool> booleans;
153 std::vector<graphics::ComplexAnimation *> complexAnimations;
154 std::vector<graphics::Font *> fonts;
155 std::vector<graphics::Frame *> frames;
156 std::vector<graphics::Gauge *> gauges;
157 std::vector<battle::Hero *> heroes;
158 std::vector<SDL_Surface *> images;
159 std::vector<battle::Monster *> monsters;
160 std::vector<int> numbers;
161 std::vector<battle::PartyLayout *> partyLayouts;
162 std::vector<PropertyList *> propertyLists;
163 std::vector<std::vector<PropertyList *> > propertyListArrays;
164 std::vector<graphics::SimpleAnimation *> simpleAnimations;
165 std::vector<graphics::Sprite *> sprites;
166 std::vector<const char *> strings;
167 std::vector<std::vector<Value *> > valueArrays;
168 std::vector<geometry::Vector<int> > vectors;
174 #endif /* LOADER_INTERPRETER_H_ */