//
// Created by IgorBat on 21.04.2018.
//

#include "abstractfactory.h"
#include "skills/spell.h"

#include <iostream>
#include <algorithm>
#include <cassert>
#include <string>

#include <QFile>
#include <QString>
#include <QTextStream>

Spell::Spell(QString parameters) {
    QStringList params = parameters.split("\n");
    assert(params.size() >= 1);
    spell_name_ = param[0];
    QString spell_folder = ":/assets/skills/" + spell_name_ + "/";

    loadSpellDescr(spell_folder);
    loadSpellIcon(spell_folder);
    loadSpellTraits(spell_folder);
}

void Spell::loadSpellDescr(QString spell_folder) {
    QFile file(spell_folder + "descr.txt");
    file.open(QIODevice::ReadOnly);
    QTextStream in(&file);
    in.setCodec("UTF-8");
    spell_descr_ = in.readAll();
}

void Spell::loadSpellIcon(QString spell_folder) {
    spell_icon_.load(spell_folder + "icon.png");
}

void Spell::loadSpellTraits(QString spell_folder) {
    /*
     * you can do it by yourself, i need to sleep
     */

}

QString Spell::getSpellName() const {
    return spell_name_;
}

QString Spell::getSpellDescr() const {
    return spell_descr_;
}

QImage Spell::getSpellIcon() const {
    return spell_icon_;
}

int Spell::getDistance(){
    return distance_;
}
void setDistance(int value){
    distance_ = value;
}

bool getForCell(){
    return forCell_;
}
void setForCell(bool value){
    forCell_ = value;
}
bool Spell::canCastToCell(Cell* destination, Cell* from){
    if(from -> lenOfActualPath(destination) == 1) return true;
    return false;
}
