本文整理汇总了C++中XMLElement::IntAttribute方法的典型用法代码示例。如果您正苦于以下问题:C++ XMLElement::IntAttribute方法的具体用法?C++ XMLElement::IntAttribute怎么用?C++ XMLElement::IntAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XMLElement
的用法示例。
在下文中一共展示了XMLElement::IntAttribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Initialize
int CTransportConfig::Initialize(const char* confname)
{
if (m_transports.size() <= 0)
{
XMLDocument doc;
if (doc.LoadFile(confname) != XML_NO_ERROR)
{
throw CMudException("load xml transports config file failed");
}
XMLHandle docHandle(&doc);
XMLHandle current_handle = docHandle.FirstChildElement("config").FirstChildElement("transports").FirstChild();
XMLElement* elem = current_handle.ToElement();
while (elem)
{
int id = elem->IntAttribute("id");
m_transports[id].id = id;
m_transports[id].name = elem->Attribute("name");
m_transports[id].x = elem->IntAttribute("x");
m_transports[id].y = elem->IntAttribute("y");
m_transports[id].enabled = elem->BoolAttribute("enabled");
STDOUT_DEBUG("id=%d, name=%s, x=%d, y=%d, enabled=%d",
id, m_transports[id].name.c_str(), m_transports[id].x, m_transports[id].y, m_transports[id].enabled);
elem = current_handle.NextSibling().ToElement();
}
}
return 0;
}
示例2: loadImage
ensoft::tmx::Image loadImage(XMLElement *element)
{
XMLElement *ximage = element->FirstChildElement("image");
std::string format = getAttributeString(ximage, "format");
std::string source = getAttributeString(ximage, "source");
std::string trans = getAttributeString(ximage, "trans");
int width = ximage->IntAttribute("width");
int height = ximage->IntAttribute("height");
return ensoft::tmx::Image{format, source, trans, width, height};
}
示例3: init
void VisualComponent::init(XMLElement *xmlData)
{
XMLElement *visibleElt = xmlData->FirstChildElement("Visible");
// if no visibility if specified, default to true
if (visibleElt == nullptr)
visible = true;
else
{
visible = visibleElt->BoolAttribute("value");
}
XMLElement *textureElt = xmlData->FirstChildElement("Texture");
// if no texture is specified, set it to null
if (textureElt == nullptr)
texture = nullptr;
else
{
string texID = textureElt->Attribute("id");
texture = TextureManager::get()->getTexture(texID);
}
XMLElement *dimElt = xmlData->FirstChildElement("Dimensions");
// if both are null, we have no dimension data
if (dimElt == nullptr && textureElt == nullptr)
throw BAD_DIMENSION_ERR;
// if no dimensions are specified, take them from the texture
else if (dimElt == nullptr)
{
width = texture->width;
height = texture->height;
}
else
{
width = dimElt->DoubleAttribute("w");
height = dimElt->DoubleAttribute("h");
}
XMLElement *colorElt = xmlData->FirstChildElement("Color");
// if no color is specified, default to white
if (colorElt == nullptr)
colorData = bm::Color(255, 255, 255, 255);
else
{
int r = colorElt->IntAttribute("r");
int g = colorElt->IntAttribute("g");
int b = colorElt->IntAttribute("b");
int a = colorElt->IntAttribute("a");
colorData = bm::Color(r, g, b, a);
}
}
示例4: init
void VisualComponent::init(XMLElement *componentElement)
{
XMLElement* textureElement;
const char* textureFileLocation;
const char* fontFileLocation;
std::ostringstream LabelString;
ComponentID = componentElement->IntAttribute("ComponentType");
viewType = (ViewType)componentElement->IntAttribute("GameViewId");
XMLElement* colorElement = componentElement->FirstChildElement("Color");
//actorColor = new sf::Color(colorElement->IntAttribute("r"),colorElement->IntAttribute("g"),colorElement->IntAttribute("b"),colorElement->IntAttribute("a"));
XMLElement* shapeElement = colorElement->NextSiblingElement("Structure");
shapeID = shapeElement->IntAttribute("ShapeID");
switch(shapeElement->IntAttribute("ShapeID"))
{
case 1://"Rectangle":
actorShape = new ActorShape::Rectangle();
((ActorShape::Rectangle*)actorShape)->setSize(shapeElement->FloatAttribute("Height"), shapeElement->FloatAttribute("Width"));
((ActorShape::Rectangle*)actorShape)->actorShape.setFillColor((const sf::Color &)actorColor);//(const sf::Color &)actorColor
break;
case 2://"Circle":
actorShape = new ActorShape::Circle();
((ActorShape::Circle*)actorShape)->setSize(shapeElement->FloatAttribute("Radious"));
((ActorShape::Circle*)actorShape)->actorShape.setFillColor((const sf::Color &)actorColor);
break;
case 3://"GRID MAP":
actorShape = new ActorShape::GridMap();
((ActorShape::GridMap*)actorShape)->setBlockSize(shapeElement->IntAttribute("BlockHeight"),shapeElement->IntAttribute("BlockWidth"));
break;
case 5://TextArea
textureElement = shapeElement->NextSiblingElement("Texture");
textureFileLocation = textureElement->Attribute("TextureFileName");
actorShape = new ActorShape::GridMap();
((ActorShape::GridMap*)actorShape)->LoadTexture(textureFileLocation);
((ActorShape::GridMap*)actorShape)->setBlockSize(shapeElement->IntAttribute("BlockHeight"),shapeElement->IntAttribute("BlockWidth"));
fontFileLocation = textureElement->Attribute("FontFileName");
((ActorShape::GridMap*)actorShape)->LoadFont(fontFileLocation);
//LabelString << textureElement->Attribute("Text");// put float into string buffer
//((ActorShape::GridMap*)actorShape)->SetTextInBox(LabelString, 0, 0);
break;
default:
actorShape = new ActorShape::Circle();
((ActorShape::Circle*)actorShape)->setSize(10);
((ActorShape::Circle*)actorShape)->actorShape.setFillColor((const sf::Color &)actorColor);
break;
}
isVisible = true;
}
示例5: getLevel
Level* DataManager::getLevel(string name)
{
int gridSize = 8;
XMLDocument doc;
doc.LoadFile("data/levels.xml");
XMLElement* element = doc.FirstChildElement("package")->FirstChildElement("levels")->FirstChildElement("level");
int width = element->IntAttribute("width");
int height = element->IntAttribute("height");
//string name = element->Attribute("name");
Level* level = new Level();
level->width = width;
level->height = height;
level->name = name;
stringstream ss;
ss << hex << element->GetText();
int i = 0;
int j = 0;
int value;
while (ss >> value) {
int x = i * gridSize;
int y = j * gridSize;
int type = getBits(value, 0, 5);
switch (type) {
case 0x01: level->objects.push_back(new Object(x, y, Object::Type::BRICK)); break;
case 0x02: level->objects.push_back(new Object(x, y, Object::Type::KEY)); break;
case 0x03: level->objects.push_back(new Object(x, y, Object::Type::CACTUS)); break;
case 0x04: level->objects.push_back(new Object(x, y, Object::Type::TRAVELATOR_LEFT)); break;
case 0x05: level->blagger = new Blagger(x, y); break;
case 0x06: level->objects.push_back(new Object(x, y, Object::Type::CROSS)); break;
case 0x07: level->objects.push_back(new Object(x, y, Object::Type::METAL_FLOOR)); break;
case 0x08: level->objects.push_back(new Object(x, y, Object::Type::SINKING_FLOOR)); break;
case 0x09: level->objects.push_back(new Object(x, y, Object::Type::TRAVELATOR_RIGHT)); break;
case 0x0A: level->objects.push_back(new Object(x, y, Object::Type::WALL_TOP)); break;
case 0x0B: level->objects.push_back(new Object(x, y, Object::Type::WALL_CENTER)); break;
case 0x0C: level->objects.push_back(new Object(x, y, Object::Type::WALL_BOTTOM)); break;
}
i++;
if (i >= width) {
i = 0;
j++;
}
}
return level;
}
示例6: load
bool GraphDataStorageXML::load(const char* fullpath, GraphData& data, StageBaseData* baseData) {
try {
XMLDocument doc;
XMLDocument *myDocument = &doc;
if (! FileUtils::getInstance()->isFileExist(fullpath)) return false;
auto Data = FileUtils::getInstance()->getDataFromFile(fullpath);
if (myDocument->Parse((const char*)Data.getBytes(), Data.getSize())) return false;
//if (myDocument->LoadFile(fullpath)) return false;
static GraphData s_defGraphData = {
10/*row*/,
10/*column*/,
5/*vertex_num*/,
64/*box_heights*/,
64/*box_widths*/,
0/*diff_row_off_x*/,
32/*offsert_x*/,
32/*offsert_y*/
};
data = s_defGraphData;
for (XMLElement* property = myDocument->FirstChildElement("property"); property; property = property->NextSiblingElement("property")) {
data.cols = property->IntAttribute("cols");
data.rows = property->IntAttribute("rows");
if (baseData) {
baseData->m_bonusNeedStar = 12;
baseData->m_lbNeedScore = property->IntAttribute("score") * 5;
}
}
for (XMLElement* property = myDocument->FirstChildElement("map"); property; property = property->NextSiblingElement()) {
for (auto attribute = property->FirstAttribute(); attribute; attribute = attribute->Next()) {
const char* name = attribute->Name();
int row = 0, col = 0;
sscanf(name, "a%d_%d", &row, &col);
data.map[row][col] = GraphAttrib::make(NodeCategory::make(static_cast<enNodeColor>(attribute->IntValue()), CHESS_CATEGORY_NORM, 0));
}
}
} catch (std::string& e) {
cocos2d::log("%s\n", e.c_str());
return false;
}
return true;
}
示例7: configXml
int OliWeb::configXml()
{
string msg = "Opening ";
msg += OLIWEB_CONFIG;
writeLog(msg);
//writeLog("Parsing XML (tinyxml2)");
//config.Parse(OLIWEB_CONFIG);
//config.Parse("utf8test.xml");
config.LoadFile(OLIWEB_CONFIG);
//writeLog("Errorcode = " + toString(config.ErrorID()));
// Pick apart the XML for config options...
XMLElement *root = config.RootElement();
if ( root == NULL )
{
writeLog("Error parsing file - no root element found.");
return -1;
}
// Configuration Options
XMLElement *parserElement = root->FirstChildElement("ConfigurationSettings");
if (parserElement != NULL)
{
writeLog("Reading configuration parameters",false);
XMLElement *configElement = parserElement->FirstChildElement();
while (configElement != NULL)
{
string settingName = configElement->Name();
string value = configElement->Attribute("value");
writeLog(settingName + " = " + value,false);
if ( settingName == "PortNumber")
portNumber = configElement->IntAttribute("value");
else if ( settingName == "RootFileDirectory")
rootFileDirectory = value;
else if ( settingName == "ScriptDirectory")
scriptDirectory = value;
else if ( settingName == "DefaultFileName")
defaultFileName = value;
else if ( settingName == "FileNotFoundPage")
fileNotFoundPage = value;
else if ( settingName == "LogFile")
logFileName = value;
else if ( settingName == "PhpEngine")
phpEngine = value;
else if ( settingName == "PhpFlags")
phpFlags = value;
else if ( settingName == "UtilDirectory")
utilDirectory = value;
else writeLog("Setting not recognized!!");
configElement = configElement->NextSiblingElement();
}
}
return 0; // Success
}
示例8: ParseMesh
XMLElement* CManagerModel::ParseMesh(XMLElement *XMLMesh,CModel* Model)
{
// Parse a SINGLE Mesh
// Parse XMLSources AND Triangles.
CMesh Mesh;
XMLElement *XMLSource = XMLMesh->FirstChildElement("source");
XMLElement *Tri = XMLMesh->FirstChildElement("triangles");
XMLElement *Input = Tri->FirstChildElement("input");
//Mesh.mTriangleCount = Tri->IntAttribute("count");
while (Input != NULL)
{
CSource Source;
if (strcmp(Input->Attribute("semantic"),"VERTEX") == 0)
{
Source.mID = XMLMesh->FirstChildElement("vertices")->FirstChildElement("input")->Attribute("source");
}
else
{
Source.mID = Input->Attribute("source");
}
Source.mType = (char*) Input->Attribute("semantic");
Source.mOffset = Input->IntAttribute("offset");
Source.mID = Source.mID.erase(0, 1); // Remove the pound symbol.
// This is actually <p>, aka an index list.
Mesh.mIndex = gusVector_SplitString((char*)Tri->FirstChildElement("p")->GetText(),' ');
ParseSource(SourceByID(XMLMesh,(char*)Source.mID.c_str()),&Mesh,&Source);
Input = Input->NextSiblingElement("input");
}
// [Matrix setup]
// Let's hope we've added everything needed in these loops.
Model->AddMesh(Mesh);
return XMLMesh->NextSiblingElement("mesh");
}
示例9: space
Volume3d<float, float>::Attribute CGBFile<float, float>::load(const std::string& filename)
{
tinyxml2::XMLDocument xml;
xml.LoadFile(filename.c_str());
XMLElement* root = xml.FirstChildElement("root");
Volume3d<float, float>::Attribute attr;
{
XMLElement* res = root->FirstChildElement(resStr.c_str());
attr.resx = res->IntAttribute("x");
attr.resy = res->IntAttribute("y");
attr.resz = res->IntAttribute("z");
}
XMLElement* res = root->FirstChildElement("origin");
Vector3d<float> origin = XMLHelper::parse(*res);
XMLElement* lengthElem = root->FirstChildElement("length");
Vector3d<float> length = XMLHelper::parse(*lengthElem);
Space3d<float> space(origin, length);
attr.space = space;
XMLElement* volumeElem = root->FirstChildElement("volume");
XMLElement* imageElem = volumeElem->FirstChildElement("image");
imageFileNames.clear();
while (imageElem != nullptr) {
imageFileNames.push_back(imageElem->Attribute("path"));
imageElem = imageElem->NextSiblingElement("image");
}
return attr;
}
示例10: read
void FileList::read() {
XMLDocument doc;
const string filepath = dir + "filelist";
doc.LoadFile(filepath.c_str());
XMLElement* filelist = doc.FirstChildElement();
try { validateXML(filelist, filepath); }
catch (NoFile) { return; }
for (XMLElement* i = filelist->FirstChildElement(); i != NULL;
i = (XMLElement*) i->NextSibling()) {
const string from = i->Attribute("from");
const string to = i->Attribute("to");
const Args::Action action =
static_cast<Args::Action>(i->IntAttribute("action"));
records.push_back(Record(from, to, action));
}
}
示例11: Init
bool InventoryComponent::Init(XMLElement* node)
{
if (node->QueryBoolAttribute("drop", &m_canDrop) != tinyxml2::XMLError::XML_SUCCESS)
return false;
if (node->QueryIntAttribute("maxsize", &m_maxSize) != tinyxml2::XMLError::XML_SUCCESS)
return false;
XMLElement* pItems = node->FirstChildElement("Items");
XMLElement* pItem = pItems->FirstChildElement("Item");
while (pItem)
{
if (!AddItem(pItem->Attribute("name"), pItem->IntAttribute("quantity")))
return false;
pItem = pItem->NextSiblingElement("Item");
}
return true;
}
示例12: if
void
GameObject::LoadProperties( XMLElement & e )
{
XMLElement * prop = e.FirstChildElement("Property");
while ( prop ){
g_Log << "Property id is: " << prop->Attribute("id") << "\n";
if ( !prop->Attribute("id") ) throw AttributeMissingException("Property - No id attribute");
if ( !prop->Attribute("type") ) throw AttributeMissingException("Property - No type attribute");
if ( !prop->Attribute("value") ) throw AttributeMissingException("Property - No value attribute");
string type = prop->Attribute("type");
if ( type == "bool" ) AddProperty( prop->Attribute("id"), prop->BoolAttribute("value"));
else if ( type == "int" ) AddProperty( prop->Attribute("id"), prop->IntAttribute("value"));
else if ( type == "float" ) AddProperty( prop->Attribute("id"), prop->FloatAttribute("value"));
else if ( type == "string" ) AddProperty( prop->Attribute("id"), prop->Attribute("value"));
else throw InvalidAttributeException("Invalid attribute type defined!");
prop = prop->NextSiblingElement("Property");
}
}
示例13: load
std::string SystemSettings::load(const K::File& file) {
XMLDocument doc;
doc.LoadFile( file.getAbsolutePath().c_str() );
XMLElement* nRoot = doc.FirstChildElement("KSynth");
if (nRoot == nullptr) {return "";}
// list of all encountered problems;
std::string problems;
XMLElement* nSettings = nRoot->FirstChildElement("Settings");
if (!nSettings) {return "missing node for 'Settings'\n";}
// sound-sink
XMLElement* nSink = nSettings->FirstChildElement("SoundSink");
if (nSink) {
std::string name = nSink->Attribute("name");
SoundSinkHardware* ss = SoundSinks::get().getHardwareSinkByName(name);
if (ss) {
setSoundSink(ss);
} else {
problems += "could not find a SoundSink named '"+name+"'\n";
}
} else {
problems += "no 'SoundSink' given\n";
}
// refresh interval
XMLElement* nGui = nSettings->FirstChildElement("GUI");
if (nGui) {
XMLElement* nGuiRefresh = nGui->FirstChildElement("Refresh");
if (nGuiRefresh) {
setGuiRefreshInterval(nGuiRefresh->IntAttribute("ms"));
}
}
return problems;
}
示例14: gsv_parse
GSV* gsv_parse(char* xmlString)
{
#ifdef GSV_DEBUG
printf("gsv_parse(%p)\n",xmlString);
printf("XML = %s\n",xmlString);
#endif
XMLDocument doc;
doc.Parse(xmlString);
GSV* gsvHandle = (GSV*) malloc(sizeof(GSV));
if(gsvHandle == NULL)
return NULL;
*gsvHandle = GSVDefault;
XMLElement* panoramaElement = doc.FirstChildElement("panorama");
XMLElement* dataPropertiesElement = panoramaElement->FirstChildElement("data_properties");
int error = dataPropertiesElement->QueryIntAttribute("image_width",&gsvHandle->dataProperties.imageWidth);
GSV_WARNING("image_width",error);
error = dataPropertiesElement->QueryIntAttribute("image_height",&gsvHandle->dataProperties.imageHeight);
GSV_WARNING("image_height",error);
error = dataPropertiesElement->QueryIntAttribute("tile_width",&gsvHandle->dataProperties.tileWidth);
GSV_WARNING("tile_width",error);
error = dataPropertiesElement->QueryIntAttribute("tile_height",&gsvHandle->dataProperties.tileHeight);
GSV_WARNING("tile_height",error);
char year[5];
memset(year,'\0',sizeof(year)*sizeof(char));
char month[3];
memset(month,'\0',sizeof(month)*sizeof(char));
const char* imageDate = dataPropertiesElement->Attribute("image_date");
memcpy(year,imageDate,4*sizeof(char));
memcpy(month,&imageDate[5],2*sizeof(char));
struct tm imageDateTm = { 0, 0, 0, 1, atoi(month)-1, atoi(year)-1900, 0, 0, -1 };
gsvHandle->dataProperties.imageDate = mktime(&imageDateTm);
memcpy(gsvHandle->dataProperties.panoramaId,dataPropertiesElement->Attribute("pano_id"),GSV_PANORAMA_ID_LENGTH);
error = dataPropertiesElement->QueryIntAttribute("num_zoom_levels",&gsvHandle->dataProperties.numZoomLevels);
GSV_WARNING("num_zoom_levels",error);
error = dataPropertiesElement->QueryDoubleAttribute("lat",&gsvHandle->dataProperties.latitude);
GSV_WARNING("lat",error);
error = dataPropertiesElement->QueryDoubleAttribute("lng",&gsvHandle->dataProperties.longitude);
GSV_WARNING("lng",error);
error = dataPropertiesElement->QueryDoubleAttribute("original_lat",&gsvHandle->dataProperties.longitude);
GSV_WARNING("original_lat",error);
error = dataPropertiesElement->QueryDoubleAttribute("original_lng",&gsvHandle->dataProperties.longitude);
GSV_WARNING("original_lng",error);
gsv_copy_string(dataPropertiesElement->FirstChildElement("copyright")->GetText(),&gsvHandle->dataProperties.copyright);
gsv_copy_string(dataPropertiesElement->FirstChildElement("text")->GetText(),&gsvHandle->dataProperties.text);
gsv_copy_string(dataPropertiesElement->FirstChildElement("street_range")->GetText(),&gsvHandle->dataProperties.streetRange);
gsv_copy_string(dataPropertiesElement->FirstChildElement("region")->GetText(),&gsvHandle->dataProperties.region);
gsv_copy_string(dataPropertiesElement->FirstChildElement("country")->GetText(),&gsvHandle->dataProperties.country);
XMLElement* projectionPropertiesElement = panoramaElement->FirstChildElement("projection_properties");
gsv_copy_string(projectionPropertiesElement->Attribute("projection_type"),&gsvHandle->projectionProperties.projectionType);
gsvHandle->projectionProperties.panoramaYaw = projectionPropertiesElement->DoubleAttribute("pano_yaw_deg");
gsvHandle->projectionProperties.tiltYaw = projectionPropertiesElement->DoubleAttribute("tilt_yaw_deg");
gsvHandle->projectionProperties.tiltYaw = projectionPropertiesElement->DoubleAttribute("tilt_pitch_deg");
XMLElement* annotationProperties = panoramaElement->FirstChildElement("annotation_properties");
XMLElement* linkElement = annotationProperties->FirstChildElement("link");
while(linkElement != NULL)
{
gsvHandle->annotationProperties.links = (gsvLink*) realloc(gsvHandle->annotationProperties.links,(gsvHandle->annotationProperties.numLinks+1)*sizeof(gsvLink));
gsvLink* link = &gsvHandle->annotationProperties.links[gsvHandle->annotationProperties.numLinks];
error = linkElement->QueryDoubleAttribute("yaw_deg",&link->yaw);
GSV_WARNING("yaw_deg",error);
memcpy(link->panoramaId,linkElement->Attribute("pano_id"),GSV_PANORAMA_ID_LENGTH);
const char* road_argb = linkElement->Attribute("road_argb");
*((unsigned int*)&link->roadColour) = (unsigned int)strtoul(&road_argb[2],NULL,16);
link->scene = linkElement->IntAttribute("scene");
XMLElement* linkTextElement = linkElement->FirstChildElement("link_text");
gsv_copy_string(linkTextElement->GetText(),&link->text);
gsvHandle->annotationProperties.numLinks++;
XMLNode* siblingNode = linkElement->NextSibling();
if(siblingNode == NULL)
break;
linkElement = siblingNode->ToElement();
}
return gsvHandle;
}
示例15: logger
std::unique_ptr<ensoft::tmx::Map> ensoft::tmx::TmxLoader::loadMap(std::string filename)
{
Logger logger("TMX Loader");
logger.log("Loading " + filename);
XMLDocument doc;
XMLError error = doc.LoadFile(filename.c_str());
std::unique_ptr<ensoft::tmx::Map> map;
if (error != XMLError::XML_NO_ERROR)
{
logger.error("Error code: " + std::to_string(error));
}
else
{
// start parsing the TMX map
XMLElement *xmap = doc.FirstChildElement("map");
map = std::make_unique<ensoft::tmx::Map>(loadProperties(xmap));
map->version = xmap->Attribute("version");
map->orientation = xmap->Attribute("orientation");
map->width = xmap->IntAttribute("width");
map->height = xmap->IntAttribute("height");
map->tilewidth = xmap->IntAttribute("tilewidth");
map->tileheight = xmap->IntAttribute("tileheight");
map->renderorder = xmap->Attribute("renderorder");
map->properties = loadProperties(xmap);
// load all the tilesets
XMLElement *xtileset = xmap->FirstChildElement("tileset");
while (xtileset)
{
auto tileSet = std::make_unique<ensoft::tmx::TileSet>(loadProperties(xtileset));
tileSet->firstgid = xtileset->IntAttribute("firstgid");
tileSet->source = getAttributeString(xtileset, "source");
tileSet->name = getAttributeString(xtileset, "name");
tileSet->tilewidth = xtileset->IntAttribute("tilewidth");
tileSet->tileheight = xtileset->IntAttribute("tileheight");
tileSet->spacing = xtileset->IntAttribute("spacing");
tileSet->margin = xtileset->IntAttribute("margin");
// get the tiles for this tileset
XMLElement *xtile = xtileset->FirstChildElement("tile");
while (xtile)
{
auto tile = make_unique<ensoft::tmx::Tile>(loadProperties(xtile));
tile->id = xtile->IntAttribute("id");
tile->terrain = getAttributeString(xtile, "terrain");
tile->probability = xtile->FloatAttribute("probability");
tile->image = loadImage(xtile);
// keep track of all tiles and their global IDs
int tileGid = tileSet->firstgid + tile->id;
map->allTiles[tileGid] = tile.get();
std::cout << "[TMX Loader] Added: " << tile->image.source << " GID: " << tileGid << " Tileset: " << tileSet->name << std::endl;
tileSet->tiles.push_back(std::move(tile));
xtile = xtile->NextSiblingElement("tile");
}
map->tilesets.push_back(std::move(tileSet));
// try to find another tileset
xtileset = xtileset->NextSiblingElement("tileset");
}
XMLElement *xlayer = xmap->FirstChildElement("layer");
while (xlayer)
{
auto layer = std::make_shared<ensoft::tmx::Layer>(loadProperties(xlayer));
layer->name = xlayer->Attribute("name");
layer->x = xlayer->IntAttribute("x");
layer->y = xlayer->IntAttribute("y");
layer->width = xlayer->IntAttribute("width");
layer->height = xlayer->IntAttribute("height");
layer->opacity = xlayer->FloatAttribute("opacity");
layer->visible = xlayer->BoolAttribute("visible");
// load the data element
XMLElement *xdata = xlayer->FirstChildElement("data");
if (xdata)
{
string data = trim_copy(xdata->GetText());
loadData(*layer, map.get(), data);
}
map->layers.push_back(layer);
xlayer = xlayer->NextSiblingElement("layer");
}
XMLElement *ximagelayer = xmap->FirstChildElement("imagelayer");
while (ximagelayer)
{
auto imageLayer = std::make_unique<ensoft::tmx::ImageLayer>(loadProperties(ximagelayer));
imageLayer->name = ximagelayer->Attribute("name");
imageLayer->x = ximagelayer->IntAttribute("x");
imageLayer->y = ximagelayer->IntAttribute("y");
imageLayer->width = ximagelayer->IntAttribute("width");
imageLayer->height = ximagelayer->IntAttribute("height");
imageLayer->opacity = ximagelayer->FloatAttribute("opacity");
imageLayer->visible = ximagelayer->BoolAttribute("visible");
//.........这里部分代码省略.........