X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=src%2Floader%2FInterpreter.cpp;h=f616c1a394a0f803d0fee0a828b5f53abf3c32b0;hb=d003612c783c271285c437e47f4ab671405fa402;hp=d5a61a669a9bd177c023325cfec12031664395d1;hpb=f6d399c08f0878459bcd1c6b3f4958f300243a71;p=l2e.git
diff --git a/src/loader/Interpreter.cpp b/src/loader/Interpreter.cpp
index d5a61a6..f616c1a 100644
--- a/src/loader/Interpreter.cpp
+++ b/src/loader/Interpreter.cpp
@@ -14,6 +14,7 @@
#include "../graphics/ComplexAnimation.h"
#include "../graphics/Font.h"
#include "../graphics/Frame.h"
+#include "../graphics/Gauge.h"
#include "../graphics/SimpleAnimation.h"
#include "../graphics/Sprite.h"
@@ -28,6 +29,7 @@ using battle::Stats;
using graphics::Animation;
using graphics::Font;
using graphics::Frame;
+using graphics::Gauge;
using graphics::ComplexAnimation;
using graphics::SimpleAnimation;
using graphics::Sprite;
@@ -53,6 +55,9 @@ Interpreter::~Interpreter() {
for (vector::const_iterator i(frames.begin()), end(frames.end()); i != end; ++i) {
delete *i;
}
+ for (vector::const_iterator i(gauges.begin()), end(gauges.end()); i != end; ++i) {
+ delete *i;
+ }
for (vector::const_iterator i(images.begin()), end(images.end()); i != end; ++i) {
SDL_FreeSurface(*i);
}
@@ -128,6 +133,19 @@ Frame *Interpreter::GetFrame(const std::string &name) {
}
}
+Gauge *Interpreter::GetGauge(const std::string &name) {
+ map::const_iterator i(parsedDefinitions.find(name));
+ if (i != parsedDefinitions.end()) {
+ if (i->second.type == GAUGE) {
+ return gauges[i->second.index];
+ } else {
+ throw Error("cannot cast " + i->second.dfn->TypeName() + " to Gauge");
+ }
+ } else {
+ throw Error("access to undefined Gauge " + name);
+ }
+}
+
Hero *Interpreter::GetHero(const std::string &name) {
map::const_iterator i(parsedDefinitions.find(name));
if (i != parsedDefinitions.end()) {
@@ -327,6 +345,17 @@ Frame *Interpreter::GetFrame(const Value &v) {
}
}
+Gauge *Interpreter::GetGauge(const Value &v) {
+ if (v.IsLiteral()) {
+ Gauge *g(new Gauge);
+ ReadGauge(*g, *v.GetLiteral().GetProperties());
+ return g;
+ } else {
+ ReadDefinition(source.GetDefinition(v.GetIdentifier()));
+ return GetGauge(v.GetIdentifier());
+ }
+}
+
SDL_Surface *Interpreter::GetImage(const Value &v) {
const char *file(GetString(v));
SDL_Surface *image(IMG_Load(file));
@@ -427,6 +456,12 @@ void Interpreter::ReadObject(const Definition &dfn) {
frames.push_back(frame);
ReadFrame(*frame, *dfn.GetProperties());
parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, FRAME, index)));
+ } else if (dfn.TypeName() == "Gauge") {
+ Gauge *gauge(new Gauge);
+ int index(gauges.size());
+ gauges.push_back(gauge);
+ ReadGauge(*gauge, *dfn.GetProperties());
+ parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, GAUGE, index)));
} else if (dfn.TypeName() == "Hero") {
Hero *hero(new Hero);
int index(heroes.size());
@@ -528,6 +563,28 @@ void Interpreter::ReadFrame(Frame &f, const PropertyList &props) {
}
}
+void Interpreter::ReadGauge(Gauge &g, const PropertyList &props) {
+ for (PropertyList::ConstIterator i(props.Begin()), end(props.End()); i != end; ++i) {
+ if (i->first == "image") {
+ g.SetSurface(GetImage(*i->second));
+ } else if (i->first == "full") {
+ g.SetFullOffset(GetVector(*i->second));
+ } else if (i->first == "empty") {
+ g.SetEmptyOffset(GetVector(*i->second));
+ } else if (i->first == "height") {
+ g.SetHeight(GetNumber(*i->second));
+ } else if (i->first == "start") {
+ g.SetStartWidth(GetNumber(*i->second));
+ } else if (i->first == "repeat") {
+ g.SetRepeatWidth(GetNumber(*i->second));
+ } else if (i->first == "end") {
+ g.SetEndWidth(GetNumber(*i->second));
+ } else {
+ throw Error("unknown Gauge property: " + i->first);
+ }
+ }
+}
+
void Interpreter::ReadHero(Hero &h, const PropertyList &props) {
for (PropertyList::ConstIterator i(props.Begin()), end(props.End()); i != end; ++i) {
if (i->first == "name") {