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"
31 class SimpleAnimation;
45 class Error: public std::runtime_error {
47 Error(const std::string &msg) : std::runtime_error("interpreter error: " + msg) { }
51 Interpreter(const ParsedSource &source) : source(source) { }
54 Interpreter(const Interpreter &);
55 Interpreter &operator =(const Interpreter &);
61 graphics::Animation *GetAnimation(const std::string &name);
62 bool GetBoolean(const std::string &name) const;
63 graphics::Font *GetFont(const std::string &name);
64 graphics::Frame *GetFrame(const std::string &name);
65 battle::Hero *GetHero(const std::string &name);
66 battle::Monster *GetMonster(const std::string &name);
67 int GetNumber(const std::string &name) const;
68 battle::PartyLayout *GetPartyLayout(const std::string &name);
69 graphics::Sprite *GetSprite(const std::string &name);
70 const char *GetString(const std::string &name) const;
71 geometry::Vector<int> GetVector(const std::string &name) const;
74 const std::vector<bool> &Booleans() const { return booleans; }
75 const std::vector<graphics::ComplexAnimation *> &ComplexAnimations() const { return complexAnimations; }
76 const std::vector<graphics::Font *> &Fonts() const { return fonts; }
77 const std::vector<graphics::Frame *> &Frames() const { return frames; }
78 const std::vector<battle::Hero *> &Heroes() const { return heroes; }
79 const std::vector<SDL_Surface *> &Images() const { return images; }
80 const std::vector<battle::Monster *> &Monsters() const { return monsters; }
81 const std::vector<int> &Numbers() const { return numbers; }
82 const std::vector<battle::PartyLayout *> &PartyLayouts() const { return partyLayouts; }
83 const std::vector<graphics::SimpleAnimation *> &SimpleAnimations() const { return simpleAnimations; }
84 const std::vector<graphics::Sprite *> &Sprites() const { return sprites; }
85 const std::vector<const char *> &Strings() const { return strings; }
86 const std::vector<geometry::Vector<int> > &Vectors() const { return vectors; }
89 void ReadDefinition(const Definition &);
90 void ReadLiteral(const Definition &);
91 void ReadObject(const Definition &);
93 graphics::Animation *GetAnimation(const Value &);
94 bool GetBoolean(const Value &);
95 graphics::Font *GetFont(const Value &);
96 graphics::Frame *GetFrame(const Value &);
97 SDL_Surface *GetImage(const Value &);
98 int GetNumber(const Value &);
99 battle::PartyLayout *GetPartyLayout(const Value &);
100 const PropertyList *GetPropertyList(const Value &);
101 const std::vector<PropertyList *> &GetPropertyListArray(const Value &);
102 graphics::Sprite *GetSprite(const Value &);
103 const char *GetString(const Value &);
104 const std::vector<Value *> &GetValueArray(const Value &);
105 geometry::Vector<int> GetVector(const Value &);
107 void ReadComplexAnimation(graphics::ComplexAnimation &, const PropertyList &);
108 void ReadComplexAnimationFrame(graphics::ComplexAnimation::FrameProp &, const PropertyList &);
109 void ReadFont(graphics::Font &, const PropertyList &);
110 void ReadFrame(graphics::Frame &, const PropertyList &);
111 void ReadHero(battle::Hero &, const PropertyList &);
112 void ReadMonster(battle::Monster &, const PropertyList &);
113 void ReadPartyLayout(battle::PartyLayout &, const PropertyList &);
114 void ReadSimpleAnimation(graphics::SimpleAnimation &, const PropertyList &);
115 void ReadSprite(graphics::Sprite &, const PropertyList &);
116 void ReadStats(battle::Stats &, const PropertyList &);
119 const ParsedSource &source;
137 struct ParsedDefinition {
138 ParsedDefinition(const Definition *dfn, Type type, int index)
139 : dfn(dfn), type(type), index(index) { }
140 const Definition *dfn;
144 std::map<std::string, ParsedDefinition> parsedDefinitions;
146 std::vector<bool> booleans;
147 std::vector<graphics::ComplexAnimation *> complexAnimations;
148 std::vector<graphics::Font *> fonts;
149 std::vector<graphics::Frame *> frames;
150 std::vector<battle::Hero *> heroes;
151 std::vector<SDL_Surface *> images;
152 std::vector<battle::Monster *> monsters;
153 std::vector<int> numbers;
154 std::vector<battle::PartyLayout *> partyLayouts;
155 std::vector<PropertyList *> propertyLists;
156 std::vector<std::vector<PropertyList *> > propertyListArrays;
157 std::vector<graphics::SimpleAnimation *> simpleAnimations;
158 std::vector<graphics::Sprite *> sprites;
159 std::vector<const char *> strings;
160 std::vector<std::vector<Value *> > valueArrays;
161 std::vector<geometry::Vector<int> > vectors;
167 #endif /* LOADER_INTERPRETER_H_ */