#include "Components.h"

Components::Components()
{}

Components::Components(QDomElement e)
{
    parseComponents(e);
}

QString Components::humanReadable() const
{
    return _humanReadable;
}

bool Components::hasVocal() const
{
    return _hasVocal;
}

bool Components::hasSomatic() const
{
    return _hasSomatic;
}

bool Components::hasMaterial() const
{
    return _hasMaterial;
}

QString Components::materialComponent() const
{
    return _materialComponent;
}

bool Components::materialComponentIsExpensive() const
{
    return _materialComponentIsExpensive;
}

bool Components::expensiveMaterialComponentIsConsumed() const
{
    return _expensiveMaterialComponentIsConsumed;
}

void Components::parseComponents(QDomElement e)
{
    _humanReadable = e.attribute("humanreadable");
    _hasVocal = e.firstChildElement("vocal").firstChild().toText().nodeValue() == "true";
    _hasSomatic = e.firstChildElement("somatic").firstChild().toText().nodeValue() == "true";
    _hasMaterial = e.firstChildElement("material").firstChild().toText().nodeValue() == "true";
    if(_hasMaterial)
    {
        QDomElement material = e.firstChildElement("material");
        _materialComponent = material.attribute("name");
        _materialComponentIsExpensive = material.attribute("expensive") == "true";
        _expensiveMaterialComponentIsConsumed = material.attribute("consumed") == "true";
    }
    else
    {
        _materialComponent = "";
        _materialComponentIsExpensive = false;
        _expensiveMaterialComponentIsConsumed = false;
    }
}
