spell.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. //
  2. // Created by IgorBat on 21.04.2018.
  3. //
  4. #include "abstractfactory.h"
  5. #include "spells/spell.h"
  6. #include <iostream>
  7. #include <algorithm>
  8. #include <cassert>
  9. #include <string>
  10. #include <QFile>
  11. #include <QString>
  12. #include <QTextStream>
  13. #include <spellsmanager.h>
  14. Spell::Spell(QString parameters) : QObject(nullptr) {
  15. QStringList params = parameters.split("\n");
  16. assert(params.size() >= 1);
  17. spell_name_ = params[0];
  18. QString spell_folder = ":/assets/skills/" + spell_name_ + "/";
  19. loadSpellDescr(spell_folder);
  20. loadSpellIcon(spell_folder);
  21. loadSpellTraits(spell_folder);
  22. }
  23. void Spell::loadSpellDescr(QString spell_folder) {
  24. QFile file(spell_folder + "descr.txt");
  25. file.open(QIODevice::ReadOnly);
  26. QTextStream in(&file);
  27. in.setCodec("UTF-8");
  28. spell_descr_ = in.readAll();
  29. }
  30. void Spell::loadSpellIcon(QString spell_folder) {
  31. spell_icon_.load(spell_folder + "icon.png");
  32. }
  33. void Spell::loadSpellTraits(QString spell_folder) {
  34. QFile file(spell_folder + "traits.txt");
  35. file.open(QIODevice::ReadOnly);
  36. QTextStream in(&file);
  37. in.setCodec("UTF-8");
  38. QString traits_containts = in.readAll();
  39. QStringList params = traits_containts.split("\n");
  40. assert(params.size() >= 1);
  41. size_t countEffects = params[0].toInt();
  42. for (size_t i = 1; i <= countEffects; ++i){
  43. auto list = params[i].split('|');
  44. auto object_ptr =SpellManager::getInstance().createEffect(list[0]);
  45. effects_.push_back(object_ptr);
  46. }
  47. }
  48. QString Spell::getSpellName() const {
  49. return spell_name_;
  50. }
  51. QString Spell::getSpellDescr() const {
  52. return spell_descr_;
  53. }
  54. QImage Spell::getSpellIcon() const {
  55. return spell_icon_;
  56. }
  57. int Spell::getDistance(){
  58. return distance_;
  59. }
  60. void Spell::setDistance(int value){
  61. distance_ = value;
  62. }
  63. bool Spell::getForCell(){
  64. return forCell_;
  65. }
  66. void Spell::setForCell(bool value){
  67. forCell_ = value;
  68. }
  69. bool Spell::isNeirbor(Cell* destination, Cell* from){
  70. return from -> getleft() == destination ||
  71. from -> getleftDown() == destination ||
  72. from -> getleftUp() == destination ||
  73. from -> getright() == destination ||
  74. from -> getrightDown() == destination ||
  75. from -> getrightUp() == destination;
  76. }