30 #include "ext/tinyxml/fife_tinyxml.h"
31 #include "vfs/fife_boost_filesystem.h"
33 #include "vfs/raw/rawdata.h"
34 #include "video/imagemanager.h"
35 #include "video/image.h"
36 #include "video/animation.h"
37 #include "util/base/exception.h"
38 #include "util/log/logger.h"
39 #include "util/resource/resource.h"
40 #include "util/resource/resourcemanager.h"
42 #include "animationloader.h"
45 static Logger _log(LM_NATIVE_LOADERS);
47 AnimationLoader::AnimationLoader(VFS* vfs, ImageManager* imageManager)
48 : m_vfs(vfs), m_imageManager(imageManager) {
52 bool AnimationLoader::isLoadable(
const std::string& filename) {
53 bfs::path animPath(filename);
55 std::string animationFilename = animPath.string();
58 RawData* data = m_vfs->open(animationFilename);
61 if (data->getDataLength() != 0) {
64 doc.
Parse(data->readString(data->getDataLength()).c_str());
83 AnimationPtr AnimationLoader::load(
const std::string& filename) {
84 bfs::path animPath(filename);
86 std::string animationFilename = animPath.string();
90 AnimationPtr animation;
93 RawData* data = m_vfs->open(animationFilename);
96 if (data->getDataLength() != 0) {
97 doc.
Parse(data->readString(data->getDataLength()).c_str());
109 catch (NotFound& e) {
110 FL_ERR(_log, e.what());
124 animation.reset(
new Animation());
127 root->QueryValueAttribute(
"delay", &animDelay);
132 root->QueryValueAttribute(
"x_offset", &animXoffset);
133 root->QueryValueAttribute(
"y_offset", &animYoffset);
134 root->QueryValueAttribute(
"action", &action);
138 animation->setActionFrame(action);
140 const std::string* sourceId = frameElement->
Attribute(std::string(
"source"));
143 bfs::path framePath(filename);
148 framePath = bfs::path(*sourceId);
152 if(!m_imageManager->exists(framePath.string())) {
153 imagePtr = m_imageManager->create(framePath.string());
156 imagePtr = m_imageManager->getPtr(framePath.string());
160 int frameXoffset = 0;
161 int frameYoffset = 0;
163 int success = root->QueryValueAttribute(
"x_offset", &frameXoffset);
165 if (success == TIXML_SUCCESS) {
166 imagePtr->setXShift(frameXoffset);
169 imagePtr->setXShift(animXoffset);
172 success = root->QueryValueAttribute(
"y_offset", &frameYoffset);
174 if (success == TIXML_SUCCESS) {
175 imagePtr->setYShift(frameYoffset);
178 imagePtr->setYShift(animYoffset);
182 success = root->QueryValueAttribute(
"delay", &frameDelay);
184 if (success == TIXML_SUCCESS) {
185 animation->addFrame(imagePtr, frameDelay);
188 animation->addFrame(imagePtr, animDelay);
virtual const char * Parse(const char *p, TiXmlParsingData *data=0, TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
bool HasParentPath(const bfs::path &path)
bfs::path GetParentPath(const bfs::path &path)
const TiXmlElement * NextSiblingElement() const
const char * Attribute(const char *name) const
const TiXmlElement * RootElement() const
const TiXmlElement * FirstChildElement() const
Convenience function to get through elements.