void ConfigValues::Load(const std::string &filename) { TiXmlDocument doc; doc.LoadFile(Assets::GetContentPath() + filename); TiXmlElement *xmlValues = doc.FirstChildElement("config"); if (xmlValues) { TiXmlElement *xmlValue = xmlValues->FirstChildElement("value"); while (xmlValue) { std::string name = XMLReadString(xmlValue, "name"); if (xmlValue->Attribute("float")) instance->floats[name] = XMLReadFloat(xmlValue, "float"); if (xmlValue->Attribute("string")) instance->strings[name] = XMLReadString(xmlValue, "string"); if (xmlValue->Attribute("int")) instance->ints[name] = XMLReadInt(xmlValue, "int"); if (xmlValue->Attribute("bool")) instance->bools[name] = XMLReadBool(xmlValue, "bool"); if (xmlValue->Attribute("vector2")) instance->vector2s[name] = XMLReadVector2(xmlValue, "vector2"); xmlValue = xmlValue->NextSiblingElement("value"); } } }
void TestScene::LoadTextureSheet(const std::string &filename) { // load the xml file TiXmlDocument xml(filename); bool isLoaded = xml.LoadFile(); if (isLoaded) { TiXmlElement* eTextures = xml.FirstChildElement("Textures"); if (eTextures) { TiXmlElement* eTextureSheet = eTextures->FirstChildElement("TextureSheet"); while (eTextureSheet) { textureSheet.name = XMLReadString(eTextureSheet, "name"); TiXmlElement* eTexture = eTextureSheet->FirstChildElement("Texture"); while (eTexture) { Texture texture; texture.name = eTexture->Attribute("name"); texture.width = XMLReadInt(eTexture, "width"); texture.height = XMLReadInt(eTexture, "height"); texture.registrationPoint.x = XMLReadFloat(eTexture, "registrationPointX"); texture.registrationPoint.y = XMLReadFloat(eTexture, "registrationPointY"); textureSheet.textures.push_back(texture); eTexture = eTexture->NextSiblingElement("Texture"); } eTextureSheet = eTextureSheet->NextSiblingElement("TextureSheet"); } } } else { Debug::Log("Error: could not load textureSheet from: " + filename + " - " + xml.ErrorDesc()); } }
void TestScene::LoadAnimation(const std::string &filename) { // load the xml file TiXmlDocument xml(filename); bool isLoaded = xml.LoadFile(); if (isLoaded) { TiXmlElement* eAnimations = xml.FirstChildElement("Animations"); if (eAnimations) { TiXmlElement* eAnimation = eAnimations->FirstChildElement("Animation"); while (eAnimation) { Animation animation(XMLReadString(eAnimation, "name"), XMLReadInt(eAnimation, "frameCount")); TiXmlElement* ePart = eAnimation->FirstChildElement("Part"); while (ePart) { Part part(ePart->Attribute("name")); TiXmlElement* eFrame = ePart->FirstChildElement("Frame"); while (eFrame) { Frame frame; frame.pos = Vector2(XMLReadFloat(eFrame, "x"), XMLReadFloat(eFrame, "y")); if (eFrame->Attribute("scaleX")) { frame.scale.x = XMLReadFloat(eFrame, "scaleX"); } if (eFrame->Attribute("scaleY")) { frame.scale.y = XMLReadFloat(eFrame, "scaleY"); } if (eFrame->Attribute("alpha") != NULL) { frame.alpha = atof(eFrame->Attribute("alpha")); } part.frames.push_back(frame); eFrame = eFrame->NextSiblingElement("Frame"); } animation.parts.push_back(part); ePart = ePart->NextSiblingElement("Part"); } animations.push_back(animation); eAnimation = eAnimation->NextSiblingElement("Animation"); } } } else { Debug::Log("Error: could not load animations from: " + filename + " - " + xml.ErrorDesc()); } }
void Level::Load(const std::string &filename, Scene* scene) { // load from an xml file, into the scene if (scene != NULL) { instance->scene = scene; } if (instance->scene) { // unload tilemaps... (need to destroy them?) instance->tilemaps.clear(); //clearfringeTileset TiXmlDocument xml(Assets::GetContentPath() + filename); instance->filename = filename; bool isLoaded = xml.LoadFile(); if (isLoaded) { TiXmlElement* eLevel = xml.FirstChildElement("Level"); if (eLevel) { instance->width = XMLReadInt(eLevel, "width"); instance->height = XMLReadInt(eLevel, "height"); TiXmlElement *eTilemap = eLevel->FirstChildElement("Tilemap"); while (eTilemap) { Entity *entity = new Entity(); Tilemap *tilemap = new Tilemap(instance->GetTilesetByName(XMLReadString(eTilemap, "set")), instance->width, instance->height, XMLReadInt(eTilemap, "tileWidth"), XMLReadInt(eTilemap, "tileHeight")); instance->tilemaps.push_back(tilemap); entity->SetGraphic(tilemap); instance->scene->Add(entity); TiXmlElement *eTile = eTilemap->FirstChildElement("Tile"); while (eTile) { tilemap->SetTile(XMLReadInt(eTile, "x"), XMLReadInt(eTile, "y"), XMLReadInt(eTile, "tileID")); eTile = eTile->NextSiblingElement("Tile"); } eTilemap = eTilemap->NextSiblingElement("Tilemap"); } TiXmlElement *eFringeTiles = eLevel->FirstChildElement("FringeTiles"); while (eFringeTiles) { FringeTileset *fringeTileset = instance->GetFringeTilesetByName(XMLReadString(eFringeTiles, "set")); /* Entity *entity = new Entity(); Tilemap *tilemap = new Tilemap(instance->GetTileset(XMLString(eTilemap, "set")), instance->width, instance->height, XMLInt(eTilemap, "tileWidth"), XMLInt(eTilemap, "tileHeight")); instance->tilemaps.push_back(tilemap); entity->SetGraphic(tilemap); instance->scene->Add(entity); */ if (fringeTileset) { TiXmlElement *eFringeTile = eFringeTiles->FirstChildElement("FringeTile"); while (eFringeTile) { int tileID = XMLReadInt(eFringeTile, "id"); int layer = XMLReadInt(eFringeTile, "layer"); Vector2 position = Vector2(XMLReadFloat(eFringeTile, "x"), XMLReadFloat(eFringeTile, "y")); Vector2 scale = Vector2::one; if (eFringeTile->Attribute("scaleX") != NULL && eFringeTile->Attribute("scaleY") != NULL) scale = Vector2(XMLReadFloat(eFringeTile, "scaleX"), XMLReadFloat(eFringeTile, "scaleY")); int rotation = XMLReadFloat(eFringeTile, "rotation"); Color color = Color::white; if (eFringeTile->Attribute("ca")) { color.a = XMLReadFloat(eFringeTile, "ca"); } AddFringeTile(fringeTileset, tileID, layer, position, scale, rotation, color); eFringeTile = eFringeTile->NextSiblingElement("FringeTile"); } } eFringeTiles = eFringeTiles->NextSiblingElement("FringeTiles"); } } } } }