#include "../battle/Monster.h"
#include "../battle/PartyLayout.h"
#include "../graphics/ComplexAnimation.h"
+#include "../graphics/Font.h"
+#include "../graphics/Frame.h"
#include "../graphics/SimpleAnimation.h"
#include "../graphics/Sprite.h"
using battle::PartyLayout;
using battle::Stats;
using graphics::Animation;
+using graphics::Font;
+using graphics::Frame;
using graphics::ComplexAnimation;
using graphics::SimpleAnimation;
using graphics::Sprite;
for (vector<Hero *>::const_iterator i(heroes.begin()), end(heroes.end()); i != end; ++i) {
delete *i;
}
+ for (vector<Font *>::const_iterator i(fonts.begin()), end(fonts.end()); i != end; ++i) {
+ delete *i;
+ }
+ for (vector<Frame *>::const_iterator i(frames.begin()), end(frames.end()); i != end; ++i) {
+ delete *i;
+ }
for (vector<SDL_Surface *>::const_iterator i(images.begin()), end(images.end()); i != end; ++i) {
SDL_FreeSurface(*i);
}
}
}
+Font *Interpreter::GetFont(const std::string &name) {
+ map<string, ParsedDefinition>::const_iterator i(parsedDefinitions.find(name));
+ if (i != parsedDefinitions.end()) {
+ if (i->second.type == FONT) {
+ return fonts[i->second.index];
+ } else {
+ throw Error("cannot cast " + i->second.dfn->TypeName() + " to Font");
+ }
+ } else {
+ throw Error("access to undefined Font " + name);
+ }
+}
+
+Frame *Interpreter::GetFrame(const std::string &name) {
+ map<string, ParsedDefinition>::const_iterator i(parsedDefinitions.find(name));
+ if (i != parsedDefinitions.end()) {
+ if (i->second.type == FRAME) {
+ return frames[i->second.index];
+ } else {
+ throw Error("cannot cast " + i->second.dfn->TypeName() + " to Frame");
+ }
+ } else {
+ throw Error("access to undefined Frame " + name);
+ }
+}
+
Hero *Interpreter::GetHero(const std::string &name) {
map<string, ParsedDefinition>::const_iterator i(parsedDefinitions.find(name));
if (i != parsedDefinitions.end()) {
}
}
+Font *Interpreter::GetFont(const Value &v) {
+ if (v.IsLiteral()) {
+ Font *f(new Font);
+ ReadFont(*f, *v.GetLiteral().GetProperties());
+ return f;
+ } else {
+ ReadDefinition(source.GetDefinition(v.GetIdentifier()));
+ return GetFont(v.GetIdentifier());
+ }
+}
+
+Frame *Interpreter::GetFrame(const Value &v) {
+ if (v.IsLiteral()) {
+ Frame *f(new Frame);
+ ReadFrame(*f, *v.GetLiteral().GetProperties());
+ return f;
+ } else {
+ ReadDefinition(source.GetDefinition(v.GetIdentifier()));
+ return GetFrame(v.GetIdentifier());
+ }
+}
+
SDL_Surface *Interpreter::GetImage(const Value &v) {
const char *file(GetString(v));
SDL_Surface *image(IMG_Load(file));
complexAnimations.push_back(animation);
ReadComplexAnimation(*animation, *dfn.GetProperties());
parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, COMPLEX_ANIMATION, index)));
+ } else if (dfn.TypeName() == "Font") {
+ Font *font(new Font);
+ int index(fonts.size());
+ fonts.push_back(font);
+ ReadFont(*font, *dfn.GetProperties());
+ parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, FONT, index)));
+ } else if (dfn.TypeName() == "Frame") {
+ Frame *frame(new Frame);
+ int index(frames.size());
+ frames.push_back(frame);
+ ReadFrame(*frame, *dfn.GetProperties());
+ parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, FRAME, index)));
} else if (dfn.TypeName() == "Hero") {
Hero *hero(new Hero);
int index(heroes.size());
}
}
+void Interpreter::ReadFont(Font &f, const PropertyList &props) {
+ for (PropertyList::ConstIterator i(props.Begin()), end(props.End()); i != end; ++i) {
+ if (i->first == "sprite") {
+ f.SetSprite(GetSprite(*i->second));
+ } else if (i->first == "columnoffset") {
+ f.SetColOffset(GetNumber(*i->second));
+ } else if (i->first == "rowoffset") {
+ f.SetRowOffset(GetNumber(*i->second));
+ } else {
+ throw Error("unknown Font property: " + i->first);
+ }
+ }
+}
+
+void Interpreter::ReadFrame(Frame &f, const PropertyList &props) {
+ for (PropertyList::ConstIterator i(props.Begin()), end(props.End()); i != end; ++i) {
+ if (i->first == "image") {
+ f.SetSurface(GetImage(*i->second));
+ } else if (i->first == "border") {
+ f.SetBorderSize(GetVector(*i->second));
+ } else if (i->first == "repeat") {
+ f.SetRepeatSize(GetVector(*i->second));
+ } else if (i->first == "offset") {
+ f.SetOffset(GetVector(*i->second));
+ } else {
+ throw Error("unknown Frame 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") {
namespace graphics {
class Animation;
+ class Font;
+ class Frame;
class SimpleAnimation;
class Sprite;
}
public:
graphics::Animation *GetAnimation(const std::string &name);
bool GetBoolean(const std::string &name) const;
+ graphics::Font *GetFont(const std::string &name);
+ graphics::Frame *GetFrame(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;
public:
const std::vector<bool> &Booleans() const { return booleans; }
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<battle::Hero *> &Heroes() const { return heroes; }
const std::vector<SDL_Surface *> &Images() const { return images; }
const std::vector<battle::Monster *> &Monsters() const { return monsters; }
graphics::Animation *GetAnimation(const Value &);
bool GetBoolean(const Value &);
+ graphics::Font *GetFont(const Value &);
+ graphics::Frame *GetFrame(const Value &);
SDL_Surface *GetImage(const Value &);
int GetNumber(const Value &);
battle::PartyLayout *GetPartyLayout(const Value &);
void ReadComplexAnimation(graphics::ComplexAnimation &, const PropertyList &);
void ReadComplexAnimationFrame(graphics::ComplexAnimation::FrameProp &, const PropertyList &);
+ void ReadFont(graphics::Font &, const PropertyList &);
+ void ReadFrame(graphics::Frame &, const PropertyList &);
void ReadHero(battle::Hero &, const PropertyList &);
void ReadMonster(battle::Monster &, const PropertyList &);
void ReadPartyLayout(battle::PartyLayout &, const PropertyList &);
enum Type {
BOOLEAN,
COMPLEX_ANIMATION,
+ FONT,
+ FRAME,
HERO,
IMAGE,
MONSTER,
std::vector<bool> booleans;
std::vector<graphics::ComplexAnimation *> complexAnimations;
+ std::vector<graphics::Font *> fonts;
+ std::vector<graphics::Frame *> frames;
std::vector<battle::Hero *> heroes;
std::vector<SDL_Surface *> images;
std::vector<battle::Monster *> monsters;
battleRes.attackIcons = intp.GetSprite("attackIcons");
battleRes.attackChoiceIcons = intp.GetSprite("attackChoiceIcons");
battleRes.moveIcons = intp.GetSprite("moveIcons");
-
- SDL_Surface *titleFrameImg(IMG_Load("test-data/title-frame.png"));
- Frame titleFrame(titleFrameImg, 16, 16);
- battleRes.titleFrame = &titleFrame;
-
- SDL_Surface *largeFontImg(IMG_Load("test-data/large-font.png"));
- Sprite largeFontSprite(largeFontImg, 16, 32);
- Font largeFont(&largeFontSprite, 0, -2);
- battleRes.titleFont = &largeFont;
-
+ battleRes.titleFrame = intp.GetFrame("titleFrame");
+ battleRes.titleFont = intp.GetFont("largeFont");
battleRes.numberAnimationPrototype = intp.GetAnimation("numberAnimationPrototype");
battleRes.bigNumberSprite = intp.GetSprite("bigNumbers");
battleRes.greenNumberSprite = intp.GetSprite("bigGreenNumbers");
battleRes.ikariLabelCol = 0;
battleRes.ikariLabelRow = 4;
- SDL_Surface *numbersImg(IMG_Load("test-data/numbers.png"));
- Sprite numbersSprite(numbersImg, 16, 16);
- Font heroTagFont(&numbersSprite, 0, -3);
- battleRes.heroTagFont = &heroTagFont;
- SDL_Surface *tagFramesImg(IMG_Load("test-data/tag-frames.png"));
- Frame heroTagFrame(tagFramesImg, 16, 16, 1, 1, 0, 33);
- battleRes.heroTagFrame = &heroTagFrame;
- Frame activeHeroTagFrame(tagFramesImg, 16, 16);
- battleRes.activeHeroTagFrame = &activeHeroTagFrame;
- SDL_Surface *smallTagFrameImg(IMG_Load("test-data/small-tag-frame.png"));
- Frame smallTagFrame(smallTagFrameImg, 8, 16);
- battleRes.smallHeroTagFrame = &smallTagFrame;
- Frame lastSmallTagFrame(smallTagFrameImg, 8, 16, 1, 1, 0, 33);
- battleRes.lastSmallHeroTagFrame = &lastSmallTagFrame;
+ battleRes.heroTagFont = intp.GetFont("heroTagFont");
+ battleRes.heroTagFrame = intp.GetFrame("heroTagFrame");
+ battleRes.activeHeroTagFrame = intp.GetFrame("activeHeroTagFrame");
+ battleRes.smallHeroTagFrame = intp.GetFrame("smallHeroTagFrame");
+ battleRes.lastSmallHeroTagFrame = intp.GetFrame("lastSmallHeroTagFrame");
battleRes.heroesBgColor = SDL_MapRGB(screen.Screen()->format, 0x18, 0x28, 0x31);
SDL_Surface *gauges(IMG_Load("test-data/gauges.png"));
size: <32,32>
}
+export Frame titleFrame {
+ image: "test-data/title-frame.png",
+ border: <16,16>
+}
+
+export Font largeFont {
+ sprite: Sprite {
+ image: "test-data/large-font.png",
+ size: <16,32>
+ },
+ rowoffset: -2
+}
+
export ComplexAnimation numberAnimationPrototype {
frametime: frameTime,
repeat: false,
image: "test-data/hero-tag-sprites.png",
size: <32,16>
}
+export Font heroTagFont {
+ sprite: Sprite {
+ image: "test-data/numbers.png",
+ size: <16,16>
+ },
+ rowoffset: -3
+}
+
+export Frame activeHeroTagFrame {
+ image: "test-data/tag-frames.png",
+ border: <16,16>
+}
+export Frame heroTagFrame {
+ image: "test-data/tag-frames.png",
+ border: <16,16>,
+ offset: < 0,33>
+}
+
+export Frame smallHeroTagFrame {
+ image: "test-data/small-tag-frame.png",
+ border: <8,16>
+}
+export Frame lastSmallHeroTagFrame {
+ image: "test-data/small-tag-frame.png",
+ border: <8,16>,
+ offset: <0,33>
+}
\ No newline at end of file