QTfrontend/namegen.cpp
changeset 5238 46ddaf14509d
parent 5115 276410cc1178
child 5252 ded882439548
equal deleted inserted replaced
5237:963d787a25c2 5238:46ddaf14509d
    86     team->Hedgehogs[HedgehogNumber].Name = Dictionary[rand()%(Dictionary.size())];
    86     team->Hedgehogs[HedgehogNumber].Name = Dictionary[rand()%(Dictionary.size())];
    87 }
    87 }
    88 
    88 
    89 void HWNamegen::DictLoad(const QString filename, QStringList &list)
    89 void HWNamegen::DictLoad(const QString filename, QStringList &list)
    90 {
    90 {
    91      list.clear();
    91     list.clear();
    92 
    92 
    93      QFile file(QString("%1/Names/%2.txt").arg(datadir->absolutePath()).arg(filename));
    93     QFile file;
    94      if (file.open(QIODevice::ReadOnly | QIODevice::Text))
    94     file.setFileName(QString("%1/Data/Names/%2.txt").arg(cfgdir->absolutePath()).arg(filename));
    95      {
    95     if (!file.exists()) file.setFileName(QString("%1/Names/%2.txt").arg(datadir->absolutePath()).arg(filename));
    96 
    96     if (file.open(QIODevice::ReadOnly | QIODevice::Text))
    97          QTextStream in(&file);
    97     {
    98          while (!in.atEnd()) {
    98 
    99              QString line = in.readLine();
    99         QTextStream in(&file);
   100              if(line != QString(""))
   100         while (!in.atEnd()) {
   101                  {list.append(line);}
   101             QString line = in.readLine();
   102          }
   102             if(line != QString(""))
   103      }
   103                 {list.append(line);}
   104 
   104         }
   105      if (list.size()==0)
   105     }
       
   106 
       
   107     if (list.size()==0)
   106          list.append(filename);
   108          list.append(filename);
   107 
   109 
   108 }
   110 }
   109 
   111 
   110 
   112 
   111 void HWNamegen::HatCfgLoad(const QString hatname, QStringList &list)
   113 void HWNamegen::HatCfgLoad(const QString hatname, QStringList &list)
   112 {
   114 {
   113      list.clear();
   115     list.clear();
   114 
   116 
   115      QFile file(QString("%1/Names/%2.cfg").arg(datadir->absolutePath()).arg(hatname));
   117     QFile file;
   116      if (file.open(QIODevice::ReadOnly | QIODevice::Text))
   118     file.setFileName(QString("%1/Data/Names/%2.cfg").arg(cfgdir->absolutePath()).arg(hatname));
   117      {
   119     if (!file.exists()) file.setFileName(QString("%1/Names/%2.cfg").arg(datadir->absolutePath()).arg(hatname));
   118 
   120     if (file.open(QIODevice::ReadOnly | QIODevice::Text))
   119          QTextStream in(&file);
   121     {
   120          while (!in.atEnd()) {
   122 
   121              QString line = in.readLine();
   123         QTextStream in(&file);
   122              if(line != QString(""))
   124         while (!in.atEnd()) {
   123                  {list.append(line);}
   125             QString line = in.readLine();
   124          }
   126             if(line != QString(""))
   125      }
   127                 {list.append(line);}
   126 
   128         }
   127      if (list.size()==0)
   129     }
       
   130 
       
   131     if (list.size()==0)
   128          list.append(QString("generic"));
   132          list.append(QString("generic"));
   129 
   133 
   130 }
   134 }
   131 
   135 
   132 
   136 
   133 void HWNamegen::TypesLoad()
   137 void HWNamegen::TypesLoad()
   134 {
   138 {
   135 
   139     QFile file;
   136      QFile file(QString("%1/Names/types.ini").arg(datadir->absolutePath()));
   140     file.setFileName(QString("%1/Data/Names/types.ini").arg(cfgdir->absolutePath()));
   137      if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
   141     if (!file.exists()) file.setFileName(QString("%1/Names/types.ini").arg(datadir->absolutePath()));
   138          {TypesAvliable = FALSE; return;}
   142     if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
   139 
   143         {TypesAvliable = FALSE; return;}
   140      int counter = 0; //counter starts with 0 (teamnames mode)
   144 
   141      TypesTeamnames.append(QStringList());
   145     int counter = 0; //counter starts with 0 (teamnames mode)
   142      TypesHatnames.append(QStringList());
   146     TypesTeamnames.append(QStringList());
   143 
   147     TypesHatnames.append(QStringList());
   144      QTextStream in(&file);
   148 
   145      while (!in.atEnd()) {
   149     QTextStream in(&file);
   146          QString line = in.readLine();
   150     while (!in.atEnd()) {
   147          if (line == QString("#####")){
   151         QString line = in.readLine();
   148              counter++; //toggle mode (teamnames || hats)
   152         if (line == QString("#####")){
   149              if ((counter%2) == 0){
   153             counter++; //toggle mode (teamnames || hats)
   150                  TypesTeamnames.append(QStringList());
   154             if ((counter%2) == 0){
   151                  TypesHatnames.append(QStringList());
   155                 TypesTeamnames.append(QStringList());
   152              }
   156                 TypesHatnames.append(QStringList());
   153          } else if ((line == QString("*****")) || (line == QString("*END*"))){
   157             }
   154              TypesAvliable = TRUE; return; // bye bye
   158         } else if ((line == QString("*****")) || (line == QString("*END*"))){
   155          } else {
   159             TypesAvliable = TRUE; return; // bye bye
   156              if ((counter%2) == 0){ // even => teamnames mode
   160         } else {
   157                  TypesTeamnames[(counter/2)].append(line);
   161             if ((counter%2) == 0){ // even => teamnames mode
   158              } else { // odd => hats mode
   162                 TypesTeamnames[(counter/2)].append(line);
   159                  TypesHatnames[((counter-1)/2)].append(line);
   163             } else { // odd => hats mode
   160              }
   164                 TypesHatnames[((counter-1)/2)].append(line);
   161          }
   165             }
   162 //         Types.append(line);
   166         }
   163      }
   167 //        Types.append(line);
   164          TypesAvliable = TRUE;
   168     }
   165      return;
   169         TypesAvliable = TRUE;
       
   170     return;
   166 }
   171 }
   167 
   172 
   168 
   173 
   169 
   174 
   170 QString HWNamegen::GetRandomGrave()
   175 QString HWNamegen::GetRandomGrave()
   171 {
   176 {
   172     QStringList Graves;
   177     QStringList Graves;
   173 
   178 
   174     //list all available Graves
   179     //list all available Graves
   175     QDir tmpdir;
   180     QDir tmpdir;
       
   181     tmpdir.cd(cfgdir->absolutePath());
       
   182     tmpdir.cd("Data/Graphics/Graves");
       
   183     tmpdir.setFilter(QDir::Files);
       
   184     Graves.append(tmpdir.entryList(QStringList("*.png")).replaceInStrings(QRegExp("^(.*)\\.png"), "\\1"));
       
   185 
   176     tmpdir.cd(datadir->absolutePath());
   186     tmpdir.cd(datadir->absolutePath());
   177     tmpdir.cd("Graphics/Graves");
   187     tmpdir.cd("Graphics/Graves");
   178     tmpdir.setFilter(QDir::Files);
   188     tmpdir.setFilter(QDir::Files);
   179     Graves.append(tmpdir.entryList(QStringList("*.png")).replaceInStrings(QRegExp("^(.*)\\.png"), "\\1"));
   189     QStringList tmpList = tmpdir.entryList(QStringList("*.png")).replaceInStrings(QRegExp("^(.*)\\.png"), "\\1");
       
   190     for (QStringList::Iterator it = tmpList.begin(); it != tmpList.end(); ++it) 
       
   191         if (!Graves.contains(*it,Qt::CaseInsensitive)) Graves.append(*it);
   180 
   192 
   181     if(Graves.size()==0)
   193     if(Graves.size()==0)
   182     {
   194     {
   183         //do some serious error handling
   195         //do some serious error handling
   184         return "Error";
   196         return "Error";