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 Level::LoadProject(const std::string &filename) { Debug::Log("Loading Level..."); // load the project data from an xml file instance->tilesets.clear(); TiXmlDocument xml(Assets::GetContentPath() + filename); bool isLoaded = xml.LoadFile(); if (isLoaded) { TiXmlElement* eProject = xml.FirstChildElement("Project"); if (eProject) { // Load Tileset data (for tiles on a grid) TiXmlElement* eTilesets = eProject->FirstChildElement("Tilesets"); if (eTilesets) { TiXmlElement* eTileset = eTilesets->FirstChildElement("Tileset"); while (eTileset) { instance->tilesets.push_back(Tileset(XMLReadString(eTileset, "name"), XMLReadString(eTileset, "image"), XMLReadInt(eTileset, "tileWidth"), XMLReadInt(eTileset, "tileHeight"))); eTileset = eTilesets->NextSiblingElement("Tileset"); } } // Load FringeTileset data (for abitrarily sized 'n placed tiles) TiXmlElement* eFringeTilesets = eProject->FirstChildElement("FringeTilesets"); if (eFringeTilesets) { TiXmlElement* eFringeTileset = eFringeTilesets->FirstChildElement("FringeTileset"); while (eFringeTileset) { FringeTileset fringeTileset = FringeTileset(XMLReadString(eFringeTileset, "name")); TiXmlElement* eFringeTile = eFringeTileset->FirstChildElement("FringeTile"); while (eFringeTile) { if (eFringeTile->Attribute("id") && eFringeTile->Attribute("image")) { int tileID = XMLReadInt(eFringeTile, "id"); std::string image = XMLReadString(eFringeTile, "image"); int width = -1; int height = -1; if (eFringeTile->Attribute("width") && eFringeTile->Attribute("height")) { width = XMLReadInt(eFringeTile, "width"); height = XMLReadInt(eFringeTile, "height"); } FilterType filter = FILTER_LINEAR; bool repeatX = XMLReadBool(eFringeTile, "repeatX"); bool repeatY = XMLReadBool(eFringeTile, "repeatY"); if (image != "") { fringeTileset.SetFringeTileData(tileID, new FringeTileData(image, width, height, filter, repeatX, repeatY)); } } eFringeTile = eFringeTile->NextSiblingElement("FringeTile"); } instance->fringeTilesets.push_back(fringeTileset); eFringeTileset = eFringeTileset->NextSiblingElement("FringeTileset"); } } } } Debug::Log("...done"); }