#include "../graphics/SimpleAnimation.h"
#include "../graphics/Sprite.h"
+#include <SDL_image.h>
+
using battle::Hero;
using battle::Monster;
using battle::Stats;
namespace loader {
+Animation *Interpreter::GetAnimation(const std::string &name) {
+ map<string, Animation *>::const_iterator i(animations.find(name));
+ if (i != animations.end()) {
+ return i->second;
+ } else {
+ throw Error("access to undefined Animation " + name);
+ }
+}
+
+Hero *Interpreter::GetHero(const std::string &name) {
+ map<string, Hero *>::const_iterator i(heroes.find(name));
+ if (i != heroes.end()) {
+ return i->second;
+ } else {
+ throw Error("access to undefined Hero " + name);
+ }
+}
+
+Monster *Interpreter::GetMonster(const std::string &name) {
+ map<string, Monster *>::const_iterator i(monsters.find(name));
+ if (i != monsters.end()) {
+ return i->second;
+ } else {
+ throw Error("access to undefined Monster " + name);
+ }
+}
+
+int Interpreter::GetNumber(const std::string &name) const {
+ map<string, int>::const_iterator i(numbers.find(name));
+ if (i != numbers.end()) {
+ return i->second;
+ } else {
+ throw Error("access to undefined Number " + name);
+ }
+}
+
+Sprite *Interpreter::GetSprite(const std::string &name) {
+ map<string, Sprite *>::const_iterator i(sprites.find(name));
+ if (i != sprites.end()) {
+ return i->second;
+ } else {
+ throw Error("access to undefined Sprite " + name);
+ }
+}
+
+
void Interpreter::ReadSource() {
for (set<string>::const_iterator i(source.Exports().begin()), end(source.Exports().end()); i != end; ++i) {
ReadDefinition(source.GetDefinition(*i));
}
SDL_Surface *Interpreter::GetImage(const Value &v) {
- if (v.IsLiteral()) {
- // TODO: image lookup
- return NULL;
- } else {
- throw Error("identifier resolution not implemented for images");
- }
+ const char *file(GetString(v));
+ return IMG_Load(file);
}
int Interpreter::GetNumber(const Value &v) {
public:
void ReadSource();
+public:
+ graphics::Animation *GetAnimation(const std::string &name);
+ battle::Hero *GetHero(const std::string &name);
+ battle::Monster *GetMonster(const std::string &name);
+ int GetNumber(const std::string &name) const;
+ graphics::Sprite *GetSprite(const std::string &name);
+
private:
void ReadDefinition(const Definition &);
void ReadLiteral(const Definition &);