#include "../graphics/ComplexAnimation.h"
#include "../graphics/Font.h"
#include "../graphics/Frame.h"
+#include "../graphics/Gauge.h"
#include "../graphics/SimpleAnimation.h"
#include "../graphics/Sprite.h"
using graphics::Animation;
using graphics::Font;
using graphics::Frame;
+using graphics::Gauge;
using graphics::ComplexAnimation;
using graphics::SimpleAnimation;
using graphics::Sprite;
for (vector<Frame *>::const_iterator i(frames.begin()), end(frames.end()); i != end; ++i) {
delete *i;
}
+ for (vector<Gauge *>::const_iterator i(gauges.begin()), end(gauges.end()); i != end; ++i) {
+ delete *i;
+ }
for (vector<SDL_Surface *>::const_iterator i(images.begin()), end(images.end()); i != end; ++i) {
SDL_FreeSurface(*i);
}
}
}
+Gauge *Interpreter::GetGauge(const std::string &name) {
+ map<string, ParsedDefinition>::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<string, ParsedDefinition>::const_iterator i(parsedDefinitions.find(name));
if (i != parsedDefinitions.end()) {
}
}
+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));
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());
}
}
+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") {