Exemple #1
0
// Virtual IComponent methods
bool CCmpRenderable::Init(CObjectIdHash oid, tinyxml2::XMLNode &node)
{
  // Get XML info
  try
  {
    tinyxml2::XMLElement * element = NULL;
    if(!node.FirstChildElement("float"))
    {
      CLog::Get()->Write(LOG_ERROR, "No child element to this node");
      return false;
    }
    for(element = node.FirstChildElement(); element != NULL; element = element->NextSiblingElement())
    {
      std::string name = element->Name();
      if(name == "path")
      {
        std::string nameAttrib = element->Attribute("name");
        if(nameAttrib == "model")
          this->createModel(element->FirstChild()->ToText()->Value());
      }//end if - name == path
    }//end for loop through nodes
  }//end try block
  catch(std::exception e)
  {
    CLog::Get()->Write( LOG_ERROR, "Unable to parse XML for CCmpRenderable Init! %s", e.what());
    return false;
  }
  return true;
}
Exemple #2
0
bool 
  CCmpUserInput::Init(CObjectIdHash oid, tinyxml2::XMLNode &node)
{
  //register keys->broadcast messages, based on XML file
  //Globals::GetInputManager()->playerInputHandler->registerCallback(
  //Globals::GetObjectManager()->BroadcastMessage
  CLog::Get()->Write(LOG_GENERAL,"TODO! Write a configurable keyboard thing in CCmpUserInput");

    // Get XML info
  try
  {
    tinyxml2::XMLElement * element = NULL;
    for(element = node.FirstChildElement(); element; element = element->NextSiblingElement()) 
    {
      std::string name = element->Name();
      if(name == "key")
      {
        //map the characters we'll load up from our XML to in-game constants
        IInputHandler * inputHandler = Globals::GetInputManager()->mInputHandlers[INPUT_PLAYER_KEY];

        SInput_t * key = new SKeyboardKey_t(element->Attribute("name"));
        int state = 0;
        if(element->Attribute("state") != NULL)
          state = atoi(element->Attribute("state"));
        
        CLog::Get()->Write(LOG_GENERAL,"working on input for %s", key->getIdentifier());
        
        CLog::Get()->Write(LOG_ERROR,"TODO! Writing the init for certain common actions");

        //TODO: write more generalized code to allow for customization.
        // currently, you define key mappings here in objects - ideally
        // you'd define them in one config to a generalized "Intent" (i.e. "hero action 1")
        // which is then mapped to the object, but I just want to get this working for now






        //THIS is where we register some script handle with our input handling
        //TODO:
        //create a scriptComponent
        //  -> scriptManager will get script filename from XML, return a handle/register a message/give a callback

      } //end if - name == key

    } //end for
  } // end try block
  catch(std::exception e)
  {
    CLog::Get()->Write( LOG_ERROR, "Unable to parse XML for CCmpEntity Init! %s", e.what());
    return false;
  }//end catch
  return true;
}
	/**
	*	@brief This is the default constructor for the XMLLoader. This sets up the root
	*	node and initalises the tinyxml2::XMLElement to start on the first save slot 
	*/
	XMLLoader(){
		string path = "Assets/save_data";
		string ext = ".sav";
		ext = ".xml";
		string result = path + ext;

		//xmlDoc.LoadFile(result.c_str());

		//Why does this load the old save_data all the time
		if(xmlDoc.LoadFile(result.c_str()) == tinyxml2::XML_ERROR_FILE_NOT_FOUND)
			GenerateSaveFile();
		
		tinyxml2::XMLNode *pRoot = xmlDoc.FirstChild();
		//cout << string_to_int(s) << endl;
		
		saveGame = pRoot->FirstChildElement("SaveGame");
		if (saveGame == nullptr) throw tinyxml2::XML_ERROR_FILE_READ_ERROR;

		
		loadSaveSlots();
		/*
		tinyxml2::XMLElement * slot = saveGame->FirstChildElement("SaveSlot1");
		if (slot == nullptr) throw tinyxml2::XML_ERROR_FILE_READ_ERROR;

		tinyxml2::XMLElement * level = slot->FirstChildElement("Levels");
		if (level == nullptr) throw tinyxml2::XML_ERROR_FILE_READ_ERROR;

		tinyxml2::XMLElement * level_bool = level->FirstChildElement("LVL3");
		if (level_bool == nullptr) throw tinyxml2::XML_ERROR_FILE_READ_ERROR;
		string l_data = level_bool->GetText();
		cout << string_to_int(l_data) << endl;
		*/
		/*
		loadSaveSlots();
		*/
		/*
		const string image_ext = texture->Attribute("EXT");
		const string file_name = image_name + '.' + image_ext;*/
	}