racemanager.cpp 931 B

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