void ResourceManager::loadAnimations(const std::string &filename) { XMLFile file; int size; bool loaded = false; char *data = loadFile(filename, size); if (data && file.parse(data)) { // add all the animations file.setElement("animation"); do { file.setSubElement("body"); int id = file.readInt("animation", "id"); std::string name = file.readString("animation", "name"); int frames = file.readInt("animation", "frames"); int width = file.readInt("animation", "width"); int height = file.readInt("animation", "height"); // get list of animations for each body part std::list<BeingAnimation*> animList; do { std::string img = file.readString("body", "file"); int part = file.readInt("body", "part"); std::stringstream texName; texName << part << name; // check if animation is in content update if (getDataPath(img).find(".zip") == std::string::npos) { img = getDataPath(img); loaded = graphicsEngine->loadTextureSet(texName.str(), img, width, height); } else { int imgBufSize = 0; char *buffer = loadFile(img, imgBufSize); loaded = graphicsEngine->loadTextureSet(texName.str(), buffer, imgBufSize, width, height); free(buffer); } // load in all the frames of animation if (loaded) { BeingAnimation *anim = new BeingAnimation(id, part); for (int i = 1; i <= frames; ++i) { std::stringstream str; str << texName.str() << i; anim->addTexture(graphicsEngine->getTexture(str.str())); } animList.push_back(anim); } } while (file.nextSubElement("body")); mAnimations.insert(std::pair<std::string, std::list<BeingAnimation*> >(name, animList)); file.clear("body"); } while (file.nextElement("animation")); } }
void ResourceManager::loadBodyParts(const std::string &filename) { XMLFile file; int size; char *data = loadFile(filename, size); if (data && file.parse(data)) { // set size file.setElement("size"); mBodyWidth = file.readInt("size", "width"); mBodyHeight = file.readInt("size", "height"); // set defaults file.setElement("default"); mDefaultBody = file.readInt("default", "body"); mDefaultFemale = file.readInt("default", "female"); mDefaultHair = file.readInt("default", "hair"); mDefaultChest = file.readInt("default", "chest"); mDefaultLegs = file.readInt("default", "legs"); mDefaultFeet = file.readInt("default", "feet"); // add all the body parts file.setElement("body"); do { file.setSubElement("image"); int id = file.readInt("body", "id"); std::string icon = file.readString("body", "icon"); int part = file.readInt("body", "part"); std::string colour = file.readString("body", "colour"); Texture *iconTex = NULL; if (icon != "") { if (getDataPath(icon).find(".zip") == std::string::npos) { iconTex = graphicsEngine->loadTexture(getDataPath(icon)); } else { int iconBufSize = 0; char *buffer = loadFile(icon, iconBufSize); iconTex = graphicsEngine->loadTexture(icon, buffer, iconBufSize); free(buffer); } if (iconTex == NULL) { logger->logError("Unable to load icon: " + icon); } } BodyPart *body = new BodyPart(id, part, iconTex); do { int dir = -1; // check if img is in a content update std::string img = file.readString("image", "file"); std::string dirstr = file.readString("image", "dir"); if (dirstr == "SE") dir = DIRECTION_SOUTHEAST; else if (dirstr == "SW") dir = DIRECTION_SOUTHWEST; else if (dirstr == "NE") dir = DIRECTION_NORTHEAST; else if (dirstr == "NW") dir = DIRECTION_NORTHWEST; std::string path = getDataPath(img); size_t found = path.find(".zip"); if (found == std::string::npos) { body->addTexture(dir, path); } else { int imgBufSize = 0; char *buffer = loadFile(img, imgBufSize); body->addTexture(dir, img, buffer, imgBufSize); free(buffer); } } while (file.nextSubElement("image")); mBodyParts.push_back(body); file.clear("image"); } while (file.nextElement("body")); } }