diff options
| -rw-r--r-- | diceparser.cpp | 21 | ||||
| -rw-r--r-- | die.cpp | 5 | ||||
| -rw-r--r-- | die.h | 1 | ||||
| -rw-r--r-- | node/ifnode.cpp | 42 | ||||
| -rw-r--r-- | result/diceresult.cpp | 3 |
5 files changed, 42 insertions, 30 deletions
diff --git a/diceparser.cpp b/diceparser.cpp index 75247ba..4ec44ef 100644 --- a/diceparser.cpp +++ b/diceparser.cpp @@ -48,7 +48,6 @@ #include "node/sortresult.h" #include "node/splitnode.h" #include "node/startingnode.h" -#include "node/stringnode.h" #include "node/uniquenode.h" #include "node/valueslistnode.h" #include "node/variablenode.h" @@ -232,6 +231,11 @@ bool DiceParser::readExpression(QString& str, ExecutionNode*& node) } } } + else if(readOptionFromNull(str, operandNode)) + { + node= operandNode; + return true; + } else if(readOperatorFromNull(str, operandNode)) { node= operandNode; @@ -265,11 +269,6 @@ bool DiceParser::readExpression(QString& str, ExecutionNode*& node) node= operandNode; return true; } - else if(readOptionFromNull(str, operandNode)) - { - node= operandNode; - return true; - } else if(readValuesList(str, operandNode)) { node= operandNode; @@ -385,6 +384,7 @@ void DiceParser::start() QList<qreal> DiceParser::getLastIntegerResults() { QList<qreal> resultValues; + QStringList alreadyVisitedNode; for(auto node : m_startNodes) { ExecutionNode* next= getLeafNode(node); @@ -394,7 +394,11 @@ QList<qreal> DiceParser::getLastIntegerResults() { if(result->hasResultOfType(Result::SCALAR)) { - resultValues << result->getResult(Result::SCALAR).toReal(); + if(!alreadyVisitedNode.contains(result->getId())) + { + resultValues << result->getResult(Result::SCALAR).toReal(); + alreadyVisitedNode << result->getId(); + } scalarDone= true; } result= result->getPrevious(); @@ -420,7 +424,8 @@ QStringList DiceParser::getStringResult() } result= result->getPrevious(); } - stringListResult << str; + if(!str.isEmpty()) + stringListResult << str; } return stringListResult; } @@ -174,7 +174,10 @@ void Die::displayed() { m_displayStatus= true; } - +void Die::setDisplayed(bool b) +{ + m_displayStatus= b; +} void Die::setHighlighted(bool a) { m_highlighted= a; @@ -142,6 +142,7 @@ public: Die::ArithmeticOperator getOp() const; void setOp(const Die::ArithmeticOperator& op); + void setDisplayed(bool b); private: qint64 m_value= 0; diff --git a/node/ifnode.cpp b/node/ifnode.cpp index fbcd9b9..5470e15 100644 --- a/node/ifnode.cpp +++ b/node/ifnode.cpp @@ -133,30 +133,30 @@ void IfNode::run(ExecutionNode* previous) } } } - } - - if(m_conditionType == OnScalar) - { - Die* dice= new Die(); - dice->setValue(value); - dice->insertRollValue(value); - dice->setMaxValue(value); - if(m_validator->hasValid(dice, true, true)) - { - nextNode= m_true; - } - else - { - nextNode= m_false; - } - if(nullptr != nextNode) + if(m_conditionType == OnScalar) { - if(nullptr == m_nextNode) + Die dice; + auto val= static_cast<qint64>(value); + dice.setValue(val); + dice.insertRollValue(val); + dice.setMaxValue(val); + if(m_validator->hasValid(&dice, true, true)) { - m_nextNode= nextNode; + nextNode= m_true; + } + else + { + nextNode= m_false; + } + if(nullptr != nextNode) + { + if(nullptr == m_nextNode) + { + m_nextNode= nextNode; + } + nextNode->run(previousLoop); + previousLoop= getLeafNode(nextNode); } - nextNode->run(previousLoop); - previousLoop= getLeafNode(nextNode); } } } diff --git a/result/diceresult.cpp b/result/diceresult.cpp index 76e473b..e66fc4f 100644 --- a/result/diceresult.cpp +++ b/result/diceresult.cpp @@ -178,13 +178,16 @@ Result* DiceResult::getCopy() const auto copy= new DiceResult(); copy->setHomogeneous(m_homogeneous); copy->setOperator(m_operator); + copy->m_id= m_id; QList<Die*> list; for(auto die : m_diceValues) { auto newdie= new Die(*die); + newdie->setDisplayed(false); die->displayed(); list.append(newdie); } copy->setResultList(list); + copy->setPrevious(getPrevious()); return copy; } |