X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Floader%2FInterpreter.cpp;h=b0aa1a4d2e1c98dfddaf729ad168a66c91a8c606;hb=51e0a94d0e0a3bc1a4664aa9af1f20910f55201c;hp=9e076c1cb68494c46ce18c54bacf41ff578312c7;hpb=05112fcfdbd0c452c80b6786bf6121d6f63b852a;p=l2e.git diff --git a/src/loader/Interpreter.cpp b/src/loader/Interpreter.cpp index 9e076c1..b0aa1a4 100644 --- a/src/loader/Interpreter.cpp +++ b/src/loader/Interpreter.cpp @@ -14,6 +14,8 @@ #include "../graphics/SimpleAnimation.h" #include "../graphics/Sprite.h" +#include + using battle::Hero; using battle::Monster; using battle::Stats; @@ -29,6 +31,52 @@ using std::vector; namespace loader { +Animation *Interpreter::GetAnimation(const std::string &name) { + map::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::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::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::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::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::const_iterator i(source.Exports().begin()), end(source.Exports().end()); i != end; ++i) { ReadDefinition(source.GetDefinition(*i)); @@ -125,12 +173,8 @@ bool Interpreter::GetBoolean(const Value &v) { } 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) {