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"
29 class SimpleAnimation;
43 class Error: public std::runtime_error {
45 Error(const std::string &msg) : std::runtime_error("interpreter error: " + msg) { }
49 Interpreter(const ParsedSource &source) : source(source) { }
52 Interpreter(const Interpreter &);
53 Interpreter &operator =(const Interpreter &);
59 graphics::Animation *GetAnimation(const std::string &name);
60 bool GetBoolean(const std::string &name) const;
61 battle::Hero *GetHero(const std::string &name);
62 battle::Monster *GetMonster(const std::string &name);
63 int GetNumber(const std::string &name) const;
64 battle::PartyLayout *GetPartyLayout(const std::string &name);
65 graphics::Sprite *GetSprite(const std::string &name);
66 const char *GetString(const std::string &name) const;
67 geometry::Vector<int> GetVector(const std::string &name) const;
70 const std::vector<bool> &Booleans() const { return booleans; }
71 const std::vector<graphics::ComplexAnimation *> &ComplexAnimations() const { return complexAnimations; }
72 const std::vector<battle::Hero *> &Heroes() const { return heroes; }
73 const std::vector<SDL_Surface *> &Images() const { return images; }
74 const std::vector<battle::Monster *> &Monsters() const { return monsters; }
75 const std::vector<int> &Numbers() const { return numbers; }
76 const std::vector<battle::PartyLayout *> &PartyLayouts() const { return partyLayouts; }
77 const std::vector<graphics::SimpleAnimation *> &SimpleAnimations() const { return simpleAnimations; }
78 const std::vector<graphics::Sprite *> &Sprites() const { return sprites; }
79 const std::vector<const char *> &Strings() const { return strings; }
80 const std::vector<geometry::Vector<int> > &Vectors() const { return vectors; }
83 void ReadDefinition(const Definition &);
84 void ReadLiteral(const Definition &);
85 void ReadObject(const Definition &);
87 graphics::Animation *GetAnimation(const Value &);
88 bool GetBoolean(const Value &);
89 SDL_Surface *GetImage(const Value &);
90 int GetNumber(const Value &);
91 battle::PartyLayout *GetPartyLayout(const Value &);
92 const PropertyList *GetPropertyList(const Value &);
93 const std::vector<PropertyList *> &GetPropertyListArray(const Value &);
94 graphics::Sprite *GetSprite(const Value &);
95 const char *GetString(const Value &);
96 const std::vector<Value *> &GetValueArray(const Value &);
97 geometry::Vector<int> GetVector(const Value &);
99 void ReadComplexAnimation(graphics::ComplexAnimation &, const PropertyList &);
100 void ReadComplexAnimationFrame(graphics::ComplexAnimation::FrameProp &, const PropertyList &);
101 void ReadHero(battle::Hero &, const PropertyList &);
102 void ReadMonster(battle::Monster &, const PropertyList &);
103 void ReadPartyLayout(battle::PartyLayout &, const PropertyList &);
104 void ReadSimpleAnimation(graphics::SimpleAnimation &, const PropertyList &);
105 void ReadSprite(graphics::Sprite &, const PropertyList &);
106 void ReadStats(battle::Stats &, const PropertyList &);
109 const ParsedSource &source;
125 struct ParsedDefinition {
126 ParsedDefinition(const Definition *dfn, Type type, int index)
127 : dfn(dfn), type(type), index(index) { }
128 const Definition *dfn;
132 std::map<std::string, ParsedDefinition> parsedDefinitions;
134 std::vector<bool> booleans;
135 std::vector<graphics::ComplexAnimation *> complexAnimations;
136 std::vector<battle::Hero *> heroes;
137 std::vector<SDL_Surface *> images;
138 std::vector<battle::Monster *> monsters;
139 std::vector<int> numbers;
140 std::vector<battle::PartyLayout *> partyLayouts;
141 std::vector<PropertyList *> propertyLists;
142 std::vector<std::vector<PropertyList *> > propertyListArrays;
143 std::vector<graphics::SimpleAnimation *> simpleAnimations;
144 std::vector<graphics::Sprite *> sprites;
145 std::vector<const char *> strings;
146 std::vector<std::vector<Value *> > valueArrays;
147 std::vector<geometry::Vector<int> > vectors;
153 #endif /* LOADER_INTERPRETER_H_ */