bool TrainerTeam::loadFromFile(const QString &path)
{
    QFile file(path);
    if (!file.open(QFile::ReadOnly))
    {
        return false;
    }
    QDomDocument document;
    QString msg;
    int line,col;
    if(!document.setContent(&file,&msg,&line,&col))
    {
        QMessageBox::information(0,QObject::tr("Load Team"),QObject::tr("Error while loading the team."));
        return false;
    }
    QDomElement team = document.firstChildElement("Team");
    if(team.isNull())
    {
        QMessageBox::information(0,QObject::tr("Load Team"),QObject::tr("Error while loading the team."));
        return false;
    }
    int version = team.attribute("version", "0").toInt();

    if (version > 1) {
        QMessageBox::information(0,QObject::tr("Load Team"),QObject::tr("Error while loading the team, the client is outdated."));
        return false;
    }

    int gen = team.attribute("gen", "4").toInt();
    if (gen < GEN_MIN || gen > GEN_MAX)
        gen = GEN_MAX;
    this->team().setGen(gen);
    defaultTier() = team.attribute("defaultTier");

    QDomElement trainer = team.firstChildElement("Trainer");
    if(trainer.isNull())
    {
        QMessageBox::information(0,QObject::tr("Load Team"),QObject::tr("Error while loading the team."));
        return false;
    }

    setTrainerNick(trainer.text());
    setTrainerInfo(trainer.attribute("infoMsg"));
    setTrainerLose(trainer.attribute("loseMsg"));
    setTrainerWin(trainer.attribute("winMsg"));
    avatar() = trainer.attribute("avatar", 0).toInt();

    QDomElement poke = team.firstChildElement("Pokemon");
    int cpt = 0;
    while(!poke.isNull())
    {
        this->team().poke(cpt).loadFromXml(poke, version);

        cpt++;
        poke = poke.nextSiblingElement("Pokemon");
    }
    return true;
}
Esempio n. 2
0
bool Team::loadFromFile(const QString &path)
{
    m_path = path;

    QFile file(path);
    if (!file.open(QFile::ReadOnly))
    {
        return false;
    }
    QDomDocument document;
    QString msg;
    int line,col;
    if(!document.setContent(&file,&msg,&line,&col))
    {
        QMessageBox::information(0,QObject::tr("Load Team"),QObject::tr("Error while loading the team."));
        return false;
    }
    QDomElement team = document.firstChildElement("Team");
    if(team.isNull())
    {
        QMessageBox::information(0,QObject::tr("Load Team"),QObject::tr("Error while loading the team."));
        return false;
    }
    int version = team.attribute("version", "0").toInt();

    if (version > 1) {
        QMessageBox::information(0,QObject::tr("Load Team"),QObject::tr("Error while loading the team, the client is outdated."));
        return false;
    }

    int gen = team.attribute("gen", QString::number(GenInfo::GenMax())).toInt();
    if (gen < GEN_MIN || gen > GenInfo::GenMax())
        gen = GenInfo::GenMax();
    setGen(Pokemon::gen(team.attribute("gen", QString::number(GenInfo::GenMax())).toInt(),
                        team.attribute("subgen", QString::number(GenInfo::NumberOfSubgens(team.attribute("gen", QString::number(GenInfo::GenMax())).toInt())-1)).toInt()));
    defaultTier() = team.attribute("defaultTier");

    QDomElement poke = team.firstChildElement("Pokemon");
    int cpt = 0;
    while(!poke.isNull())
    {
        this->poke(cpt).loadFromXml(poke, version);

        cpt++;
        poke = poke.nextSiblingElement("Pokemon");
    }
    return true;
}
Esempio n. 3
0
void Team::toXml(QDomDocument &document) const
{
    const_cast<Team*>(this)->sanityCheck();

    QDomElement Team = document.createElement("Team");
    Team.setAttribute("gen", gen().num);
    Team.setAttribute("subgen", gen().subnum);
    Team.setAttribute("defaultTier", defaultTier());
    Team.setAttribute("version", 1);
    document.appendChild(Team);

    for(int i = 0; i < 6; i++)
    {
        QDomElement pokemon = document.createElement("Pokemon");
        Team.appendChild(poke(i).toXml(pokemon));
    }
}
void TrainerTeam::toXml(QDomDocument &document) const
{
    QDomElement Team = document.createElement("Team");
    Team.setAttribute("gen", team().gen());
    Team.setAttribute("defaultTier", defaultTier());
    Team.setAttribute("version", 1);
    document.appendChild(Team);
    QDomElement trainer = document.createElement("Trainer");
    Team.appendChild(trainer);
    QDomText trainerName = document.createTextNode(trainerNick());
    trainer.appendChild(trainerName);
    trainer.setAttribute("winMsg",trainerWin());
    trainer.setAttribute("loseMsg",trainerLose());
    trainer.setAttribute("infoMsg",trainerInfo());
    trainer.setAttribute("avatar", avatar());

    for(int i = 0; i < 6; i++)
    {
        QDomElement pokemon = document.createElement("Pokemon");
        Team.appendChild(team().poke(i).toXml(pokemon));
    }
}