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"
28 class SimpleAnimation;
42 class Error: public std::runtime_error {
44 Error(const std::string &msg) : std::runtime_error("interpreter error: " + msg) { }
48 Interpreter(const ParsedSource &source) : source(source) { }
51 Interpreter(const Interpreter &);
52 Interpreter &operator =(const Interpreter &);
58 graphics::Animation *GetAnimation(const std::string &name);
59 battle::Hero *GetHero(const std::string &name);
60 battle::Monster *GetMonster(const std::string &name);
61 int GetNumber(const std::string &name) const;
62 graphics::Sprite *GetSprite(const std::string &name);
65 void ReadDefinition(const Definition &);
66 void ReadLiteral(const Definition &);
67 void ReadObject(const Definition &);
69 graphics::Animation *GetAnimation(const Value &);
70 const std::vector<Value *> &GetValueArray(const Value &);
71 const std::vector<PropertyList *> &GetPropertyListArray(const Value &);
72 bool GetBoolean(const Value &);
73 SDL_Surface *GetImage(const Value &);
74 int GetNumber(const Value &);
75 const PropertyList *GetPropertyList(const Value &);
76 graphics::Sprite *GetSprite(const Value &);
77 const char *GetString(const Value &);
78 geometry::Vector<int> GetVector(const Value &);
80 void ReadComplexAnimation(graphics::ComplexAnimation &, const PropertyList &);
81 void ReadComplexAnimationFrame(graphics::ComplexAnimation::FrameProp &, const PropertyList &);
82 void ReadHero(battle::Hero &, const PropertyList &);
83 void ReadMonster(battle::Monster &, const PropertyList &);
84 void ReadSimpleAnimation(graphics::SimpleAnimation &, const PropertyList &);
85 void ReadSprite(graphics::Sprite &, const PropertyList &);
86 void ReadStats(battle::Stats &, const PropertyList &);
89 const ParsedSource &source;
99 struct ParsedDefinition {
100 ParsedDefinition(const Definition *dfn, DynamicType type, int index)
101 : dfn(dfn), type(type), index(index) { }
102 bool IsCompatible(DynamicType with) const;
103 const Definition *dfn;
107 std::map<std::string, ParsedDefinition> parsedDefinitions;
109 std::vector<graphics::Animation *> animations;
110 std::vector<battle::Hero> heroes;
111 std::vector<SDL_Surface *> images;
112 std::vector<battle::Monster> monsters;
113 std::vector<int> numbers;
114 std::vector<graphics::Sprite> sprites;
120 #endif /* LOADER_INTERPRETER_H_ */