effect.cpp 1.4 KB

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