racemanager.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #include "racemanager.h"
  2. #include "race.h"
  3. #include <QFile>
  4. #include <QDebug>
  5. #include <QTextStream>
  6. #include <QDebug>
  7. RaceManager::RaceManager(QObject *parent) : QObject(parent)
  8. {
  9. QFile file(":/assets/units/races.txt");
  10. file.open(QIODevice::ReadOnly);
  11. QTextStream in(&file);
  12. QString race_name = in.readLine();
  13. while(!in.atEnd()) {
  14. if (races_.count(race_name) != 0) {
  15. qWarning() << "Warning! found double occurences of races in raceslist.txt";
  16. continue;
  17. }
  18. if (race_name.length() < 2)
  19. continue;
  20. qDebug() << available_races_;
  21. available_races_.push_back(race_name);
  22. races_[race_name] = new Race(race_name);
  23. race_name = in.readLine();
  24. }
  25. if (race_name.length() >= 2) {
  26. qDebug() << available_races_;
  27. available_races_.push_back(race_name);
  28. races_[race_name] = new Race(race_name);
  29. race_name = in.readLine();
  30. }
  31. }
  32. Race* RaceManager::getRace(QString race_name) {
  33. if (races_.count(race_name) == 0) {
  34. qWarning() << "Error! Not found race with name " << race_name;
  35. return nullptr;
  36. }
  37. return races_[race_name];
  38. }
  39. const std::vector<QString>& RaceManager::getAvailableRacesList() {
  40. return available_races_;
  41. }