void TMXMapImporter::loadTileSetInfo(const TiXmlNode *node) { const TiXmlElement *element = node->ToElement(); TileSetInfo tileSetInfo; // EVERY TILED SET NEEDS A FIRSTGID, NAME, TILEWIDTH, & TILEHEIGHT, // SO WE'LL REQUIRE THESE if (element->Attribute(FIRSTGID_ATT.c_str()) == NULL) return; else tileSetInfo.firstgid = extractIntAtt(element, FIRSTGID_ATT); if (element->Attribute(NAME_ATT.c_str()) == NULL) return; else tileSetInfo.name = extractCharAtt(element, NAME_ATT); if (element->Attribute(TILEWIDTH_ATT.c_str()) == NULL) return; else tileSetInfo.tilewidth = extractIntAtt(element, TILEWIDTH_ATT); if (element->Attribute(TILEHEIGHT_ATT.c_str()) == NULL) return; else tileSetInfo.tileheight = extractIntAtt(element, TILEHEIGHT_ATT); // THESE ARE OPTIONAL ATTRIBUTES, AND SO WE WON'T REQUIRE THEM if (element->Attribute(SPACING_ATT.c_str()) != NULL) tileSetInfo.spacing = extractIntAtt(element, SPACING_ATT); else tileSetInfo.spacing = 0; if (element->Attribute(MARGIN_ATT.c_str()) != NULL) tileSetInfo.margin = extractIntAtt(element, MARGIN_ATT); else tileSetInfo.margin = 0; /* // GET THE TILEOFFSET node = node->FirstChild(); element = node->ToElement(); // LOAD TILEOFFSET if (element->Attribute(X_ATT.c_str()) == NULL) return; else tileSetInfo.tileoffsetX = extractIntAtt(element, X_ATT); if (element->Attribute(Y_ATT.c_str()) == NULL) return; else tileSetInfo.tileoffsetY = extractIntAtt(element, Y_ATT); */ // NOW GET THE IMAGE INFO node = node->FirstChild(); element = node->ToElement(); // ALL THREE ATTRIBUTES ARE REQUIRED if (element->Attribute(SOURCE_ATT.c_str()) == NULL) return; else tileSetInfo.sourceImage = extractCharAtt(element, SOURCE_ATT); if (element->Attribute(WIDTH_ATT.c_str()) == NULL) return; else tileSetInfo.sourceImageWidth = extractIntAtt(element, WIDTH_ATT); if (element->Attribute(HEIGHT_ATT.c_str()) == NULL) return; else tileSetInfo.sourceImageHeight = extractIntAtt(element, HEIGHT_ATT); // TRANSPARENCY MAY NOT BE PROVIDED if (element->Attribute(COLOR_KEY_ATT.c_str()) != NULL) tileSetInfo.transparencyColor = extractCharAtt(element, COLOR_KEY_ATT); tileSetInfos.push_back(tileSetInfo); }
void TMXMapImporter::loadTileSetInfo(const TiXmlNode *node) { const TiXmlElement *element = node->ToElement(); TileSetInfo tileSetInfo; tileSetInfo.firstgid = extractIntAtt(element, FIRSTGID_ATT); tileSetInfo.name = extractCharAtt(element, NAME_ATT); tileSetInfo.tilewidth = extractIntAtt(element, TILEWIDTH_ATT); tileSetInfo.tileheight = extractIntAtt(element, TILEHEIGHT_ATT); // NOW GET THE IMAGE INFO node = node->FirstChild(); element = node->ToElement(); tileSetInfo.sourceImage = extractCharAtt(element, SOURCE_ATT); tileSetInfo.sourceImageWidth = extractIntAtt(element, WIDTH_ATT); tileSetInfo.sourceImageHeight = extractIntAtt(element, HEIGHT_ATT); //~Extract the tile collidable properties for each tile. This is slightly // harcoded, but it is following the methods used by the importer in general //First get the first Tile element const TiXmlNode *propNode = NULL; TileProps props; bool tempPropArray[4]; int counter = 0; tileSetInfo.tilePropertyTable = new vector<TileProps>(); //The imageinfo is a sibling to all of the tile properties children node = node->NextSibling(); while(node != NULL){ //this is within the <properties> child element propNode = node->FirstChild()->FirstChild(); while(propNode != NULL){ element = propNode->ToElement(); tempPropArray[counter] = extractBoolAtt(element,VALUE_ATT); counter++; propNode = propNode->NextSibling(); } props.bottom_collidable = tempPropArray[0]; props.left_collidable = tempPropArray[1]; props.right_collidable = tempPropArray[2]; props.top_collidable = tempPropArray[3]; //finally add the props to the vector tileSetInfo.tilePropertyTable->push_back(props); counter = 0; node = node->NextSibling(); } tileSetInfos[tileSetInfo.name] = tileSetInfo; }
void TMXMapImporter::loadImageLayerInfo(const TiXmlNode *node) { const TiXmlElement *element = node->ToElement(); ImageLayerInfo *imageLayerInfo = new ImageLayerInfo(); if (element->Attribute(NAME_ATT.c_str()) == NULL) return; else imageLayerInfo->name = extractCharAtt(element, NAME_ATT); // WE DON'T ACTUALLY CARE ABOUT THE TMX WIDTH AND HEIGHT FOR THIS // NOW GET THE IMAGE ELEMENT const TiXmlNode *childNode = node->FirstChild(); if (childNode->ToElement()->Attribute(SOURCE_ATT.c_str()) == NULL) return; else imageLayerInfo->imageSource = extractCharAtt(childNode->ToElement(), SOURCE_ATT); // AND NOW GET IMAGE LAYER PROPERTIES childNode = childNode->ToElement()->NextSibling(); if (node != NULL) { string eName = childNode->Value(); if (strcmp(eName.c_str(), PROPERTIES_ELEMENT.c_str()) == 0) { const TiXmlNode *grandchildNode = childNode->FirstChild(); while (grandchildNode != NULL) { const TiXmlElement *grandchildElement = grandchildNode->ToElement(); string att = grandchildElement->Attribute(NAME_ATT.c_str()); if (strcmp(att.c_str(), COLLIDABLE_ATT.c_str()) == 0) { imageLayerInfo->collidable = extractBoolAtt(grandchildNode->ToElement(), VALUE_ATT); } else if (strcmp(att.c_str(), IMAGEHEIGHT_ATT.c_str()) == 0) { imageLayerInfo->imageheight= extractIntAtt(grandchildNode->ToElement(), VALUE_ATT); } else if (strcmp(att.c_str(), IMAGEWIDTH_ATT.c_str()) == 0) { imageLayerInfo->imagewidth = extractIntAtt(grandchildNode->ToElement(), VALUE_ATT); } grandchildNode = grandchildNode->NextSibling(); } } } // OK, NOW LOAD THE LAYER imageLayerInfo->type = LayerType::IMAGE; layerInfos.push_back(imageLayerInfo); }
void TMXMapImporter::loadTileSetInfo(const TiXmlNode *node) { const TiXmlElement *element = node->ToElement(); TileSetInfo tileSetInfo; tileSetInfo.firstgid = extractIntAtt(element, FIRSTGID_ATT); tileSetInfo.name = extractCharAtt(element, NAME_ATT); tileSetInfo.tilewidth = extractIntAtt(element, TILEWIDTH_ATT); tileSetInfo.tileheight = extractIntAtt(element, TILEHEIGHT_ATT); // NOW GET THE IMAGE INFO node = node->FirstChild(); element = node->ToElement(); tileSetInfo.sourceImage = extractCharAtt(element, SOURCE_ATT); tileSetInfo.sourceImageWidth = extractIntAtt(element, WIDTH_ATT); tileSetInfo.sourceImageHeight = extractIntAtt(element, HEIGHT_ATT); tileSetInfos[tileSetInfo.name] = tileSetInfo; }
void TMXMapImporter::loadSparseLayerInfo(const TiXmlNode *node) { const TiXmlElement *element = node->ToElement(); SparseLayerInfo *sparseLayerInfo = new SparseLayerInfo(); sparseLayerInfo->name = extractCharAtt(element, NAME_ATT); // NOW GET THE PROPERTIES const TiXmlNode *propertiesNode = node->FirstChild(); string eName = propertiesNode->Value(); const TiXmlNode *dataNode = propertiesNode; if (strcmp(eName.c_str(), PROPERTIES_ELEMENT.c_str()) == 0) { const TiXmlNode *propNode = propertiesNode->FirstChild(); // IF THE LAYER IS NOT SPECIFIED AS COLLIDABLE OR NOT, // DON'T EVEN LOAD IT const char *propName = propNode->Value(); if (strcmp(propNode->Value(), PROPERTY_ELEMENT.c_str()) != 0) return; // OTHERWISE LOAD THE PROPERTIES, WHICH MUST INCLUDE collidable while (propNode != NULL) { const TiXmlElement *propElement = propNode->ToElement(); string att = propElement->Attribute(NAME_ATT.c_str()); if (strcmp(att.c_str(), COLLIDABLE_ATT.c_str()) == 0) { sparseLayerInfo->collidable = extractBoolAtt(propNode->ToElement(), VALUE_ATT); } propNode = propNode->NextSibling(); } dataNode = propertiesNode->NextSibling(); } // NOW LET'S LOAD THE OBJECTS (Sparse Tiles) while (dataNode != NULL) { const TiXmlElement *objectElement = dataNode->ToElement(); if ( (dataNode->ToElement()->Attribute(GID_ATT.c_str()) != NULL) && (dataNode->ToElement()->Attribute(X_ATT.c_str()) != NULL) && (dataNode->ToElement()->Attribute(Y_ATT.c_str()) != NULL)) { sparseLayerInfo->gidS.push_back(extractIntAtt(objectElement, GID_ATT)); sparseLayerInfo->xS.push_back(extractIntAtt(objectElement, X_ATT)); sparseLayerInfo->yS.push_back(extractIntAtt(objectElement, Y_ATT)); } dataNode = dataNode->NextSibling(); } sparseLayerInfo->tileSetInfo = getTileSetForId(sparseLayerInfo->gidS.front()); sparseLayerInfo->type = LayerType::SPARSE; layerInfos.push_back(sparseLayerInfo); }
void TMXMapImporter::loadTiledLayerInfo(const TiXmlNode *node) { const TiXmlElement *element = node->ToElement(); TiledLayerInfo tiledLayerInfo; tiledLayerInfo.name = extractCharAtt(element, NAME_ATT); tiledLayerInfo.width = extractIntAtt(element, WIDTH_ATT); tiledLayerInfo.height = extractIntAtt(element, HEIGHT_ATT); // NOW GET THE PROPERTIES const TiXmlNode *propertiesNode = node->FirstChild(); string eName = propertiesNode->Value(); const TiXmlNode *dataNode; if (strcmp(eName.c_str(), PROPERTIES_ELEMENT.c_str()) == 0) { const TiXmlNode *propNode = propertiesNode->FirstChild(); while (propNode != NULL) { const TiXmlElement *propElement = propNode->ToElement(); string att = propElement->Attribute(NAME_ATT.c_str()); if (strcmp(att.c_str(), COLLIDABLE_ATT.c_str()) == 0) { tiledLayerInfo.collidable = extractBoolAtt(propNode->ToElement(), VALUE_ATT); } propNode = propNode->NextSibling(); } dataNode = propertiesNode->NextSibling(); } // NOW GET THE TILE DATA if (dataNode == NULL) { dataNode = node->FirstChild(); } const TiXmlNode *tileNode = dataNode->FirstChild(); while (tileNode) { const TiXmlElement *element = tileNode->ToElement(); int gid = extractIntAtt(element, GID_ATT); tiledLayerInfo.gids.push_back(gid); tileNode = tileNode->NextSibling(); } tiledLayerInfo.tileSetInfo = getTileSetForId(tiledLayerInfo.gids[0]); tiledLayerInfos[tiledLayerInfo.name] = tiledLayerInfo; }
void TMXMapImporter::loadTiledLayerInfo(const TiXmlNode *node) { const TiXmlElement *element = node->ToElement(); TiledLayerInfo *tiledLayerInfo = new TiledLayerInfo(); // NAME WIDTH AND HEIGHT ARE ALL REQUIRED if (element->Attribute(NAME_ATT.c_str()) == NULL) return; else tiledLayerInfo->name = extractCharAtt(element, NAME_ATT); if (element->Attribute(WIDTH_ATT.c_str()) == NULL) return; else tiledLayerInfo->width = extractIntAtt(element, WIDTH_ATT); if (element->Attribute(HEIGHT_ATT.c_str()) == NULL) return; else tiledLayerInfo->height = extractIntAtt(element, HEIGHT_ATT); // NOW GET THE PROPERTIES, IF THERE ARE ANY const TiXmlNode *propertiesNode = node->FirstChild(); string eName = propertiesNode->Value(); const TiXmlNode *dataNode = NULL; bool collidableSpecified = false; if (strcmp(eName.c_str(), PROPERTIES_ELEMENT.c_str()) == 0) { const TiXmlNode *propNode = propertiesNode->FirstChild(); while (propNode != NULL) { const TiXmlElement *propElement = propNode->ToElement(); string att = propElement->Attribute(NAME_ATT.c_str()); if (strcmp(att.c_str(), COLLIDABLE_ATT.c_str()) == 0) { tiledLayerInfo->collidable = extractBoolAtt(propNode->ToElement(), VALUE_ATT); collidableSpecified = true; } propNode = propNode->NextSibling(); } dataNode = propertiesNode->NextSibling(); } // BY DEFAULT A LAYER IS NOT COLLIDABLE if (!collidableSpecified) tiledLayerInfo->collidable = false; // NOW GET THE TILE DATA if (dataNode == NULL) { dataNode = node->FirstChild(); } const TiXmlNode *tileNode = dataNode->FirstChild(); while (tileNode) { const TiXmlElement *element = tileNode->ToElement(); // GID IS REQUIRED if (element->Attribute(GID_ATT.c_str()) != NULL) { int gid = extractIntAtt(element, GID_ATT); tiledLayerInfo->gids.push_back(gid); } tileNode = tileNode->NextSibling(); } tiledLayerInfo->tileSetInfo = getTileSetForId(tiledLayerInfo->gids[0]); tiledLayerInfo->type = LayerType::TILED; layerInfos.push_back(tiledLayerInfo); }