/** This is called from user_config when reading the config file
*/
void UnlockManager::load()
{
    const std::string filename=file_manager->getChallengeFile("challenges.xml");
    XMLNode* root = file_manager->createXMLTree(filename);
    if(!root || root->getName() != "challenges")
    {
        std::cerr << "Challenge file '" << filename << "' will be created." 
                  << std::endl;
        
        createSlotsIfNeeded();
        save();
        
        if (root) delete root;
        return;
    }
    
    std::vector<XMLNode*> xml_game_slots;
    root->getNodes("gameslot", xml_game_slots);
    for (unsigned int n=0; n<xml_game_slots.size(); n++)
    {
        std::string player_id;
        if (!xml_game_slots[n]->get("playerID", &player_id))
        {
            fprintf(stderr, "[UnlockManager] WARNING: Found game slot without a player ID attached. Discarding it\n");
            continue;
        }
        
        GameSlot* slot = new GameSlot(player_id);
        
        std::string kart_id;
        xml_game_slots[n]->get("kart", &kart_id);
        slot->setKartIdent(kart_id);
        
        m_game_slots[player_id] = slot;
        
        bool first_time = true;
        xml_game_slots[n]->get("firstTime", &first_time);
        slot->setFirstTime(first_time);
        
        for(AllChallengesType::iterator i = m_all_challenges.begin(); 
            i!=m_all_challenges.end();  i++)
        {
            ChallengeData* curr = i->second;
            Challenge* state = new Challenge(curr);
            
            slot->m_challenges_state[curr->getId()] = state;
            state->load(xml_game_slots[n]);
        }
        slot->computeActive();
    }
    
    bool something_changed = createSlotsIfNeeded();
    if (something_changed) save();
    
    delete root;
}   // load
Exemplo n.º 2
0
 // ------------------------------------------------------------------------
 void setFirstTime(bool b) { m_game_slot->setFirstTime(b); }