Effect.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. //
  2. // Created by IgorBat on 21.04.2018.
  3. //
  4. #include "abstractfactory.h"
  5. #include "effects/effect.h"
  6. #include <iostream>
  7. #include <algorithm>
  8. #include <cassert>
  9. #include <string>
  10. #include <QFile>
  11. #include <QString>
  12. #include <QTextStream>
  13. Effect::Effect(QString parameters) {
  14. QStringList params = parameters.split("|");
  15. assert(params.size() >= 3);
  16. effect_name_ = params[0];
  17. setCount(params[1].toInt());
  18. setDurability(params[2].toInt());
  19. QString effect_folder = ":/assets/effects/" + effect_name_ + "/";
  20. loadEffectDescr(effect_folder);
  21. loadEffectIcon(effect_folder);
  22. }
  23. void Effect::loadEffectDescr(QString effect_folder) {
  24. QFile file(effect_folder + "descr.txt");
  25. file.open(QIODevice::ReadOnly);
  26. QTextStream in(&file);
  27. in.setCodec("UTF-8");
  28. effect_descr_ = in.readAll();
  29. }
  30. void Effect::loadEffectIcon(QString effect_folder) {
  31. effect_icon_.load(effect_folder + "icon.png");
  32. }
  33. QString Effect::getEffectName() const {
  34. return effect_name_;
  35. }
  36. QString Effect::getEffectDescr() const {
  37. return effect_descr_;
  38. }
  39. QImage Effect::getEffectIcon() const {
  40. return effect_icon_;
  41. }
  42. int Effect::getCount(){
  43. return count_;
  44. }
  45. void Effect::setCount(int value){
  46. count_ = value;
  47. }
  48. int Effect::getDurability(){
  49. return durability_;
  50. };
  51. void Effect::setDurability(int value){
  52. durability_ = value;
  53. }