Exemplo n.º 1
0
    void GD_EXTENSION_API DeleteAnElement(const std::string &refname, RuntimeScene &scene)
    {
        TiXmlNode *nodeToRemove = RefManager::Get(&scene)->GetRef(refname);

        if(nodeToRemove)
        {
            RefManager::Get(&scene)->DeleteChildRefs(refname);
            if(nodeToRemove->Parent())
            {
                nodeToRemove->Parent()->RemoveChild(nodeToRemove);
            }
            RefManager::Get(&scene)->SetRef(refname, 0);
        }
    }
Exemplo n.º 2
0
std::string
XMLReader::getCurrentNodePath() const noexcept
{
	std::vector<std::string> components;

	TiXmlNode* node = this->_currentNode;
	while (node != _document.get())
	{
		components.push_back(node->Value());
		node = node->Parent();
	}

	std::string path;
	std::size_t size = components.size();
	if (size > 0)
	{
		for (int i = size - 1; i >= 0; i--)
		{
			path.append(components[i]);
			if (i > 0)
			{
				path.append("/");
			}
		}
	}

	return path;
}
Exemplo n.º 3
0
    void processNodeChildren(TiXmlNode* node, Model::geometryData* dData,
			     Model::physicsData* pData)
    {

      TiXmlNode* child = NULL;
      for (child = node->FirstChild(); child; child = child->NextSibling())
	{
	  if(child->Type() == 1)
	    {
	      std::string typeName = "";
	      typeName = child->Parent()->Value();
	      if (typeName == "library_geometries")
		{
		  extractVertices(child, dData);
		}
	      else if (typeName == "library_physics_materials")
		{
		  extractPhysicsMaterials(child);
		}
	      else if (typeName == "library_physics_models")
		{
		  extractPhysics(child, pData);
		}
	    }
	  processNodeChildren(child, dData, pData);
	}
    }
Exemplo n.º 4
0
  int tixmldocument_delete(lua_State *L) {
    TiXmlDocument *xmldoc;
    TiXmlDocument_ud* xmldoc_userdata = (TiXmlDocument_ud *) luaL_checkudata(L, 1, "TiXmlDocument");
    xmldoc = xmldoc_userdata->xmldoc;
    const char *path = luaL_checkstring(L, 2); // path

    lua_pop(L, 2);

    char *attr_name;
    TiXmlNode *node = find_node(path, xmldoc->RootElement(), &attr_name);

    if (node) {
      if (attr_name) {
	if (node->Type() == TiXmlNode::ELEMENT) {
	  TiXmlElement *elt_node = dynamic_cast<TiXmlElement *>(node);
	  if (elt_node->Attribute(attr_name)) {
	    elt_node->RemoveAttribute(attr_name);
	    delete attr_name;
	    lua_pushboolean(L, 1);
	    return 1;
	  }
	}
	luaL_error(L, "invalid attribute: %s", attr_name);
	delete attr_name;
	return 0;
      } else {
	node->Parent()->RemoveChild(node);
	lua_pushboolean(L, 1);
	return 1;
      }
    } else {
      return luaL_error(L, "path not found: %s", path);
    }
  }
    void GD_EXTENSION_API InsertElementIntoAnother(const std::string &refNameOfElementToAdd, const std::string &refNameOfParentElement, const std::string &refNameOfNextElement, RuntimeScene &scene)
    {
        TiXmlNode *parentEle = RefManager::GetInstance(&scene)->GetRef(refNameOfParentElement);
        TiXmlNode *nextEle = RefManager::GetInstance(&scene)->GetRef(refNameOfNextElement);
        TiXmlNode *toBeAddedEle = RefManager::GetInstance(&scene)->GetRef(refNameOfElementToAdd);

        if(!nextEle || nextEle->Parent() != parentEle)
        {
            parentEle->LinkEndChild(toBeAddedEle);
        }
        else
        {
            TiXmlNode *insertedEle = 0;
            insertedEle = parentEle->InsertBeforeChild(nextEle, *toBeAddedEle);
            RefManager::GetInstance(&scene)->SetRef(refNameOfElementToAdd, insertedEle);
        }
    }
Exemplo n.º 6
0
    void GD_EXTENSION_API InsertElementIntoAnother(const gd::String &refNameOfElementToAdd, const gd::String &refNameOfParentElement, const gd::String &refNameOfNextElement, RuntimeScene &scene)
    {
        TiXmlNode *parentEle = RefManager::Get(&scene)->GetRef(refNameOfParentElement);
        TiXmlNode *nextEle = RefManager::Get(&scene)->GetRef(refNameOfNextElement);
        TiXmlNode *toBeAddedEle = RefManager::Get(&scene)->GetRef(refNameOfElementToAdd);

        if ( parentEle == NULL || toBeAddedEle == NULL )
            return; //These element cannot be invalid
        else
        {
            if(!nextEle || nextEle->Parent() != parentEle)
            {
                parentEle->LinkEndChild(toBeAddedEle);
            }
            else
            {
                TiXmlNode *insertedEle = 0;
                insertedEle = parentEle->InsertBeforeChild(nextEle, *toBeAddedEle);
                RefManager::Get(&scene)->SetRef(refNameOfElementToAdd, insertedEle);
            }

        }
    }
Exemplo n.º 7
0
bool CPlayListASX::LoadData(istream& stream)
{
  CLog::Log(LOGNOTICE, "Parsing ASX");

  if(stream.peek() == '[')
  {
    return LoadAsxIniInfo(stream);
  }
  else
  {
    CXBMCTinyXML xmlDoc;
    stream >> xmlDoc;

    if (xmlDoc.Error())
    {
      CLog::Log(LOGERROR, "Unable to parse ASX info Error: %s", xmlDoc.ErrorDesc());
      return false;
    }

    TiXmlElement *pRootElement = xmlDoc.RootElement();

    // lowercase every element
    TiXmlNode *pNode = pRootElement;
    TiXmlNode *pChild = NULL;
    CStdString value;
    value = pNode->Value();
    value.ToLower();
    pNode->SetValue(value);
    while(pNode)
    {
      pChild = pNode->IterateChildren(pChild);
      if(pChild)
      {
        if (pChild->Type() == TiXmlNode::TINYXML_ELEMENT)
        {
          value = pChild->Value();
          value.ToLower();
          pChild->SetValue(value);

          TiXmlAttribute* pAttr = pChild->ToElement()->FirstAttribute();
          while(pAttr)
          {
            value = pAttr->Name();
            value.ToLower();
            pAttr->SetName(value);
            pAttr = pAttr->Next();
          }
        }

        pNode = pChild;
        pChild = NULL;
        continue;
      }

      pChild = pNode;
      pNode = pNode->Parent();
    }
    CStdString roottitle = "";
    TiXmlElement *pElement = pRootElement->FirstChildElement();
    while (pElement)
    {
      value = pElement->Value();
      if (value == "title")
      {
        roottitle = pElement->GetText();
      }
      else if (value == "entry")
      {
        CStdString title(roottitle);

        TiXmlElement *pRef = pElement->FirstChildElement("ref");
        TiXmlElement *pTitle = pElement->FirstChildElement("title");

        if(pTitle)
          title = pTitle->GetText();

        while (pRef)
        { // multiple references may apear for one entry
          // duration may exist on this level too
          value = pRef->Attribute("href");
          if (value != "")
          {
            if(title.IsEmpty())
              title = value;

            CLog::Log(LOGINFO, "Adding element %s, %s", title.c_str(), value.c_str());
            CFileItemPtr newItem(new CFileItem(title));
            newItem->SetPath(value);
            Add(newItem);
          }
          pRef = pRef->NextSiblingElement("ref");
        }
      }
      else if (value == "entryref")
      {
        value = pElement->Attribute("href");
        if (value != "")
        { // found an entryref, let's try loading that url
          auto_ptr<CPlayList> playlist(CPlayListFactory::Create(value));
          if (NULL != playlist.get())
            if (playlist->Load(value))
              Add(*playlist);
        }
      }
      pElement = pElement->NextSiblingElement();
    }
  }

  return true;
}
Exemplo n.º 8
0
void KrEncoder::CalcAllInfo( TiXmlNode* node, 
							 AllInfo* i,
							 SDL_Surface* surface )
{
	TiXmlElement* ele = node->ToElement();
	if ( !ele )
	{
		GLASSERT( 0 );
		return;
	}	

	// Walk up the tree, get information as we go.
	TiXmlNode* parent = ele->Parent();
	while( parent )
	{
		TiXmlElement* parentEle = parent->ToElement();
		if ( parentEle )
		{
			if ( parentEle->Value() == "Definition" )
			{
//				i->format = FORMAT_DEF;
//
//				if ( parentEle->Attribute( "filename" ) )
//					i->filename = *parentEle->Attribute( "filename" );

				// We need go no higher.
				break;
			}
			else if ( parentEle->Value() == "Sprite" )
			{
				i->type = TYPE_SPRITE;

				if ( parentEle->Attribute( "name" ) )
					i->name = *parentEle->Attribute( "name" );
			}
			else if ( parentEle->Value() == "Action" )
			{
				if ( parentEle->Attribute( "name" ) )
					i->action = *parentEle->Attribute( "name" );
			}
			else if ( parentEle->Value() ==  "File" )
			{
//				if ( parentEle->Attribute( "filename" ) )
//					i->filename = *parentEle->Attribute( "filename" );
			}
			else if ( parentEle->Value() ==  "Direct" )
			{
				//i->format = FORMAT_DIRECT;
				// Go no higher.
				break;
			}
		}
		parent = parent->Parent();
	}

	// Now interpret the element itself:
	if ( ele->Value() == "Image" )
	{
		// Could be sprite or tile.
		i->useEntireImage = true;
	}
	else if ( ele->Value() == "ColorKey" )
	{
		// Could be sprite on tile.
		//i->useEntireImage = false;
	}
	else if ( ele->Value() == "Frame" )
	{
		i->type = TYPE_SPRITE;
	}
	else if ( ele->Value() == "Font" )
	{
		i->type = TYPE_FONT;
	}
	else if ( ele->Value() == "Tile" )
	{
		i->type = TYPE_TILE;
	}
	
	// And its attributes. They don't have different meanings in different
	// tags, so they can all be read in together.

	// ColorKey and Image attributes:
	if ( ele->Attribute( "tile" ) )
	{
		GLASSERT( i->type == TYPE_NONE );
		i->name = *ele->Attribute( "tile" );
		i->type = TYPE_TILE;
	}
	if ( ele->Attribute( "sprite" ) )
	{
		GLASSERT( i->type == TYPE_NONE );
		i->name = *ele->Attribute( "sprite" );
		i->type = TYPE_SPRITE;
	}
	if ( ele->Attribute( "color" ) )
	{
		gedString c = *ele->Attribute( "color" );
		i->keyColor.FromString( c.c_str() );
		i->keyColor.c.alpha = KrRGBA::KR_OPAQUE;	// alpha not used
	}
	if ( ele->Attribute( "frameCount" ) )
	{
		ele->Attribute( "frameCount", &i->frameCount );
	}
	if ( ele->Attribute( "action" ) )
	{
		i->action = *ele->Attribute( "action" );
	}
	if ( ele->Attribute( "sprite" ) )
	{
		i->name = *ele->Attribute( "sprite" );
	}

	// Used by tile and font:
	if ( ele->Attribute( "name" ) )
	{
		i->name = *ele->Attribute( "name" );
	}

	// Font attributes:
	if ( i->type == TYPE_FONT )
	{
		if ( ele->Attribute( "start" ) )
		{
			ele->Attribute( "start", &i->fontStart );
		}
		if ( ele->Attribute( "space" ) )
		{
			ele->Attribute( "space", &i->space );
		}
		if ( ele->Attribute( "type" ) )
		{
			if ( *ele->Attribute( "type" ) == "sfont" )
				i->subType = SUBTYPE_SFONT;
		}
	}

	// Generic attributes:
	if ( ele->Attribute( "x" ) )
	{
		ele->Attribute( "x", &i->x );
	}
	if ( ele->Attribute( "y" ) )
	{
		ele->Attribute( "y", &i->y );
	}
	if ( ele->Attribute( "size" ) )
	{
		GLASSERT( i->type == TYPE_TILE );
		ele->Attribute( "size", &i->width );
		i->height = i->width;					// size is height and width for tiles.
	}
	if ( ele->Attribute( "width" ) )
	{
		ele->Attribute( "width", &i->width );
	}
	if ( ele->Attribute( "height" ) )
	{
		ele->Attribute( "height", &i->height );
	}
	if ( ele->Attribute( "hotspotx" ) )
	{
		//i->hasHotspot = true;
		ele->Attribute( "hotspotx", &i->hotx);
	}
	if ( ele->Attribute( "hotspoty" ) )
	{
		//i->hasHotspot = true;
		ele->Attribute( "hotspoty", &i->hoty );
	}
	if ( ele->Attribute( "deltax" ) )
	{
		//i->hasDelta = true;
		ele->Attribute( "deltax", &i->deltax );
	}
	if ( ele->Attribute( "deltay" ) )
	{
		//i->hasDelta = true;
		ele->Attribute( "deltay", &i->deltay );
	}
	if ( ele->Attribute( "isotile" ) )
	{
		i->isoTargetWidth = 0;
		ele->Attribute( "isotile", &i->isoTargetWidth );
	}
	if ( ele->Attribute( "length" ) )
	{
		ele->Attribute( "length", &i->fontLength );
	}
	if ( ele->Attribute( "rotation" ) )
	{
		gedString r = *ele->Attribute( "rotation" );
		GlString::RemoveWhiteSpace( &r );

		GlDynArray< gedString > strArray;
		GlString::Split( &strArray, r, ",", false );

		for( int k=0; k<(int)strArray.Count(); ++k )
		{
			if ( strArray[k].length() > 1 && strArray[k].at( 0 ) == 'd' )
			{
				int division = strArray[k].at( 1 ) - '0'; //maks
				if ( division > 0 )
				{
					int increment = 360 / division;
					if ( increment > 0 )
					{
						for( int theta = 0; theta < 360; theta += increment )
						{
							i->rotation.PushBack( theta );
						}
					}
				}
			}
			else
			{
				int theta = atoi( strArray[k].c_str() );
				i->rotation.PushBack( theta );
			}
		}
		i->rotation.Sort();
	}

	if ( i->useEntireImage )
	{
		i->x = 0;
		i->y = 0;
		i->width = surface->w;
		i->height = surface->h;
	}
}