]> git.localhorst.tv Git - l2e.git/blob - src/loader/Interpreter.h
added interpretation of PartyLayout
[l2e.git] / src / loader / Interpreter.h
1 /*
2  * Interpreter.h
3  *
4  *  Created on: Aug 26, 2012
5  *      Author: holy
6  */
7
8 #ifndef LOADER_INTERPRETER_H_
9 #define LOADER_INTERPRETER_H_
10
11 #include "../geometry/Vector.h"
12 #include "../graphics/ComplexAnimation.h"
13
14 #include <map>
15 #include <stdexcept>
16 #include <string>
17 #include <vector>
18 #include <SDL.h>
19
20 namespace battle {
21         class Hero;
22         class Monster;
23         class PartyLayout;
24         class Stats;
25 }
26
27 namespace graphics {
28         class Animation;
29         class SimpleAnimation;
30         class Sprite;
31 }
32
33 namespace loader {
34
35 class Definition;
36 class ParsedSource;
37 class PropertyList;
38 class Value;
39
40 class Interpreter {
41
42 public:
43         class Error: public std::runtime_error {
44         public:
45                 Error(const std::string &msg) : std::runtime_error("interpreter error: " + msg) { }
46         };
47
48 public:
49         Interpreter(const ParsedSource &source) : source(source) { }
50         ~Interpreter();
51 private:
52         Interpreter(const Interpreter &);
53         Interpreter &operator =(const Interpreter &);
54
55 public:
56         void ReadSource();
57
58 public:
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;
68
69 public:
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; }
81
82 private:
83         void ReadDefinition(const Definition &);
84         void ReadLiteral(const Definition &);
85         void ReadObject(const Definition &);
86
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 &);
98
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 &);
107
108 private:
109         const ParsedSource &source;
110         enum Type {
111                 BOOLEAN,
112                 COMPLEX_ANIMATION,
113                 HERO,
114                 IMAGE,
115                 MONSTER,
116                 NUMBER,
117                 PARTY_LAYOUT,
118                 PROPERTY_LIST_ARRAY,
119                 SIMPLE_ANIMATION,
120                 SPRITE,
121                 STRING,
122                 VECTOR,
123                 VALUE_ARRAY,
124         };
125         struct ParsedDefinition {
126                 ParsedDefinition(const Definition *dfn, Type type, int index)
127                 : dfn(dfn), type(type), index(index) { }
128                 const Definition *dfn;
129                 Type type;
130                 int index;
131         };
132         std::map<std::string, ParsedDefinition> parsedDefinitions;
133
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;
148
149 };
150
151 }
152
153 #endif /* LOADER_INTERPRETER_H_ */