Ejemplo n.º 1
0
void FilterNode::run(ExecutionNode* previous)
{
    m_previousNode = previous;
    if(NULL==previous)
    {
        return;
    }
    DiceResult* previousDiceResult = static_cast<DiceResult*>(previous->getResult());
    m_result->setPrevious(previousDiceResult);
    if(NULL!=previousDiceResult)
    {
        QList<Die*> diceList=previousDiceResult->getResultList();
        QList<Die*> diceList2;


        for(Die* tmp : diceList)
        {
            if(m_validator->hasValid(tmp,m_eachValue))
            {
                diceList2.append(tmp);
            }
            else
            {
                tmp->setHighlighted(false);
            }
        }

        m_diceResult->setResultList(diceList2);
        if(NULL!=m_nextNode)
        {
            m_nextNode->run(this);
        }
    }
}
Ejemplo n.º 2
0
void IfNode::run(ExecutionNode *previous)
{
    m_previousNode = previous;
    if(NULL==previous)
    {
        return;
    }
    ExecutionNode* previousLoop = previous;
    ExecutionNode* nextNode = NULL;
    bool runNext = (NULL==m_nextNode) ? false : true;
    Result* previousResult = previous->getResult();
    m_result = previousResult;

    if(NULL!=m_result)
    {
        qreal value = previousResult->getResult(Result::SCALAR).toReal();

        if(NULL!=m_validator)
        {
            DiceResult* previousDiceResult = dynamic_cast<DiceResult*>(previousResult);
            if(NULL!=previousDiceResult)
            {
                QList<Die*> diceList=previousDiceResult->getResultList();
                if(m_conditionType == OnEach)
                {
                    for(Die* dice : diceList)
                    {
                        if(m_validator->hasValid(dice,true,true))
                        {
                            nextNode = (NULL==m_true) ? NULL: m_true->getCopy();
                        }
                        else
                        {
                            nextNode = (NULL==m_false) ? NULL: m_false->getCopy();
                        }
                        if(NULL!=nextNode)
                        {
                            if(NULL==previousLoop->getNextNode())
                            {
                                previousLoop->setNextNode(nextNode);
                            }
                            if(NULL==m_nextNode)
                            {
                                m_nextNode = nextNode;
                            }
                            nextNode->run(previousLoop);
                            previousLoop = getLeafNode(nextNode);
                        }
                    }
                }
                else
                {
                    bool trueForAll=true;
                    bool falseForAll=true;

                    bool oneIsTrue=false;
                    bool oneIsFalse=false;

                    for(Die* dice : diceList)
                    {
                        bool result = m_validator->hasValid(dice,true,true);
                        qDebug() << result << m_conditionType;
                        trueForAll = trueForAll ? result : false;
                        falseForAll = falseForAll ? result : false;

                        oneIsTrue = (oneIsTrue==false) ? result : true;
                        oneIsFalse = (oneIsFalse==false) ? result : true;
                    }
                    if(m_conditionType==OneOfThem)
                    {
                        if(oneIsTrue)
                        {
                            nextNode = (NULL==m_true) ? NULL: m_true->getCopy();
                        }
                        else if(oneIsFalse)
                        {
                             nextNode = (NULL==m_false) ? NULL: m_false->getCopy();
                        }
                    }
                    else if(m_conditionType==AllOfThem)
                    {
                        if(trueForAll)
                        {
                            nextNode = (NULL==m_true) ? NULL: m_true->getCopy();
                        }
                        else if(falseForAll)
                        {
                             nextNode = (NULL==m_false) ? NULL: m_false->getCopy();
                        }
                    }


                    if(NULL!=nextNode)
                    {
                        if(NULL==m_nextNode)
                        {
                            m_nextNode = nextNode;
                        }
                        nextNode->run(previousLoop);
                        previousLoop = getLeafNode(nextNode);
                    }
                }
            }
            else
            {
                Die* dice = new Die();
                dice->setValue(value);
                dice->setFaces(value);
                if(m_validator->hasValid(dice,true,true))
                {
                        nextNode=m_true;
                }
                else
                {
                        nextNode=m_false;
                }
                if(NULL!=nextNode)
                {
                    if(NULL==m_nextNode)
                    {
                        m_nextNode = nextNode;
                    }
                    nextNode->run(previousLoop);
                    previousLoop = getLeafNode(nextNode);
                }
            }
        }
    }

    if((NULL!=m_nextNode)&&(runNext))
    {
        m_nextNode->run(previousLoop);
    }
}