Пример #1
0
void 
CEntityBuilder::BuildEntity( TiXmlElement *pParent, EntityManager &em, Resources *pResources){
  // Create entity (new id)
  Entity *ent = em.createEntity();
  if ( !ent){
    LOG2ERR<<"Could not create entity\n";
    throw "Could not create entity";
  }
  TiXmlElement* pChilds = pParent->FirstChildElement( "tags");
  if ( pChilds ){
    // Add tags
    for(pChilds=pChilds->FirstChildElement( "tag" ); pChilds; pChilds = pChilds->NextSiblingElement() ){
      std::string name;
      if ( TIXML_SUCCESS == pChilds->QueryValueAttribute( "name", &name))
      {
        std::string unique;
        bool        isUnique(false);
        if ( TIXML_SUCCESS == pChilds->QueryValueAttribute( "unique", &unique) ){
          isUnique = ( unique=="true");
        }
        em.tagEntity( ent, name, isUnique);
      }
    }
  }
  
  // Add components
  pChilds = pParent->FirstChildElement( "components");
  if ( pChilds ){
    for( pChilds=pChilds->FirstChildElement( "component" ); pChilds; pChilds = pChilds->NextSiblingElement() ){
      std::string type; 
      if ( TIXML_SUCCESS == pChilds->QueryValueAttribute( "type", &type)){
        //LOG2 <<name<<"\n";
        buildComponents(pChilds, type, ent, pResources);
      }
      else {
        LOG2ERR<<"Attribute [type] not found\n";
      }
    }
  }
}