#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") {
class Animation;
class Font;
class Frame;
+ class Gauge;
class SimpleAnimation;
class Sprite;
}
bool GetBoolean(const std::string &name) const;
graphics::Font *GetFont(const std::string &name);
graphics::Frame *GetFrame(const std::string &name);
+ graphics::Gauge *GetGauge(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;
const std::vector<graphics::ComplexAnimation *> &ComplexAnimations() const { return complexAnimations; }
const std::vector<graphics::Font *> &Fonts() const { return fonts; }
const std::vector<graphics::Frame *> &Frames() const { return frames; }
+ const std::vector<graphics::Gauge *> &Gauges() const { return gauges; }
const std::vector<battle::Hero *> &Heroes() const { return heroes; }
const std::vector<SDL_Surface *> &Images() const { return images; }
const std::vector<battle::Monster *> &Monsters() const { return monsters; }
bool GetBoolean(const Value &);
graphics::Font *GetFont(const Value &);
graphics::Frame *GetFrame(const Value &);
+ graphics::Gauge *GetGauge(const Value &);
SDL_Surface *GetImage(const Value &);
int GetNumber(const Value &);
battle::PartyLayout *GetPartyLayout(const Value &);
void ReadComplexAnimationFrame(graphics::ComplexAnimation::FrameProp &, const PropertyList &);
void ReadFont(graphics::Font &, const PropertyList &);
void ReadFrame(graphics::Frame &, const PropertyList &);
+ void ReadGauge(graphics::Gauge &, const PropertyList &);
void ReadHero(battle::Hero &, const PropertyList &);
void ReadMonster(battle::Monster &, const PropertyList &);
void ReadPartyLayout(battle::PartyLayout &, const PropertyList &);
COMPLEX_ANIMATION,
FONT,
FRAME,
+ GAUGE,
HERO,
IMAGE,
MONSTER,
std::vector<graphics::ComplexAnimation *> complexAnimations;
std::vector<graphics::Font *> fonts;
std::vector<graphics::Frame *> frames;
+ std::vector<graphics::Gauge *> gauges;
std::vector<battle::Hero *> heroes;
std::vector<SDL_Surface *> images;
std::vector<battle::Monster *> monsters;