spell.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. Spell::Spell(QString parameters) {
  14. QStringList params = parameters.split("\n");
  15. assert(params.size() >= 1);
  16. spell_name_ = params[0];
  17. QString spell_folder = ":/assets/skills/" + spell_name_ + "/";
  18. loadSpellDescr(spell_folder);
  19. loadSpellIcon(spell_folder);
  20. loadSpellTraits(spell_folder);
  21. }
  22. void Spell::loadSpellDescr(QString spell_folder) {
  23. QFile file(spell_folder + "descr.txt");
  24. file.open(QIODevice::ReadOnly);
  25. QTextStream in(&file);
  26. in.setCodec("UTF-8");
  27. spell_descr_ = in.readAll();
  28. }
  29. void Spell::loadSpellIcon(QString spell_folder) {
  30. spell_icon_.load(spell_folder + "icon.png");
  31. }
  32. void Spell::loadSpellTraits(QString spell_folder) {
  33. QFile file(spell_folder + "traits.txt");
  34. file.open(QIODevice::ReadOnly);
  35. QTextStream in(&file);
  36. in.setCodec("UTF-8");
  37. QString traits_containts = in.readAll();
  38. QStringList params = traits_containts.split("\n");
  39. assert(params.size() >= 1);
  40. size_t countEffects = params[0].toInt();
  41. for (size_t i = 1; i <= countEffects; ++i){
  42. effects_.push_back(new Effect(params[i]));
  43. }
  44. }
  45. QString Spell::getSpellName() const {
  46. return spell_name_;
  47. }
  48. QString Spell::getSpellDescr() const {
  49. return spell_descr_;
  50. }
  51. QImage Spell::getSpellIcon() const {
  52. return spell_icon_;
  53. }
  54. int Spell::getDistance(){
  55. return distance_;
  56. }
  57. void Spell::setDistance(int value){
  58. distance_ = value;
  59. }
  60. bool Spell::getForCell(){
  61. return forCell_;
  62. }
  63. void Spell::setForCell(bool value){
  64. forCell_ = value;
  65. }
  66. bool Spell::isNeirbor(Cell* destination, Cell* from){
  67. return from -> getleft() == destination ||
  68. from -> getleftDown() == destination ||
  69. from -> getleftUp() == destination ||
  70. from -> getright() == destination ||
  71. from -> getrightDown() == destination ||
  72. from -> getrightUp() == destination;
  73. }