racemanager.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. in.setCodec("UTF-8");
  13. QString race_name = in.readLine();
  14. while(!in.atEnd()) {
  15. if (races_.count(race_name) != 0) {
  16. qWarning() << "Warning! found double occurences of races in raceslist.txt";
  17. continue;
  18. }
  19. if (race_name.length() < 2)
  20. continue;
  21. //qDebug() << available_races_;
  22. available_races_.push_back(race_name);
  23. races_[race_name] = std::make_shared<Race>(race_name);
  24. race_name = in.readLine();
  25. }
  26. if (race_name.length() >= 2) {
  27. //qDebug() << available_races_;
  28. available_races_.push_back(race_name);
  29. races_[race_name] = std::make_shared<Race>(race_name);
  30. race_name = in.readLine();
  31. }
  32. }
  33. std::shared_ptr<Race> RaceManager::getRace(QString race_name) {
  34. if (races_.count(race_name) == 0) {
  35. qWarning() << "Error! Not found race with name " << race_name;
  36. return nullptr;
  37. }
  38. return races_[race_name];
  39. }
  40. const std::vector<QString>& RaceManager::getAvailableRacesList() {
  41. return available_races_;
  42. }