diff options
| author | 2017-03-10 01:15:30 +0100 | |
|---|---|---|
| committer | 2017-03-10 01:15:30 +0100 | |
| commit | 026ca5cb4829cd4c4ad6b945e27479303e96fe82 (patch) | |
| tree | 6b9f4972ca71d9cfcd2ae26789103e501aa4e3c4 | |
| parent | 993a636818d237feaca1870a65b72ab1d4ead31d (diff) | |
| parent | 6fdd7dad0a24cff8bd20907425a7b9f91e33fdd8 (diff) | |
| download | OneRoll-026ca5cb4829cd4c4ad6b945e27479303e96fe82.tar.gz OneRoll-026ca5cb4829cd4c4ad6b945e27479303e96fe82.zip | |
Merge branch 'master' of github.com:Rolisteam/DiceParser
| -rw-r--r-- | node/ifnode.cpp | 40 | ||||
| -rw-r--r-- | node/ifnode.h | 2 | ||||
| -rw-r--r-- | parsingtoolbox.cpp | 24 | ||||
| -rw-r--r-- | parsingtoolbox.h | 2 |
4 files changed, 44 insertions, 24 deletions
diff --git a/node/ifnode.cpp b/node/ifnode.cpp index 27b588f..91ad199 100644 --- a/node/ifnode.cpp +++ b/node/ifnode.cpp @@ -81,7 +81,7 @@ void IfNode::run(ExecutionNode *previous) } } } - else + else if((m_conditionType == OneOfThem)||(m_conditionType == AllOfThem)) { bool trueForAll=true; bool falseForAll=true; @@ -133,28 +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 { - Die* dice = new Die(); - dice->setValue(value); - dice->setMaxValue(value); - if(m_validator->hasValid(dice,true,true)) - { - nextNode=m_true; - } - else - { - nextNode=m_false; - } - if(NULL!=nextNode) + nextNode=m_false; + } + if(NULL!=nextNode) + { + if(NULL==m_nextNode) { - if(NULL==m_nextNode) - { - m_nextNode = nextNode; - } - nextNode->run(previousLoop); - previousLoop = getLeafNode(nextNode); + m_nextNode = nextNode; } + nextNode->run(previousLoop); + previousLoop = getLeafNode(nextNode); } } } diff --git a/node/ifnode.h b/node/ifnode.h index da8bb0b..7376101 100644 --- a/node/ifnode.h +++ b/node/ifnode.h @@ -34,7 +34,7 @@ public: /** * @brief The ConditionType enum */ - enum ConditionType {OnEach,OneOfThem,AllOfThem}; + enum ConditionType {OnEach,OneOfThem,AllOfThem,OnScalar}; /** * @brief IfNode */ diff --git a/parsingtoolbox.cpp b/parsingtoolbox.cpp index 3d2d2c3..e04dcbe 100644 --- a/parsingtoolbox.cpp +++ b/parsingtoolbox.cpp @@ -213,6 +213,11 @@ IfNode::ConditionType ParsingToolBox::readConditionType(QString& str) str=str.remove(0,1); type = IfNode::AllOfThem; } + else if(str.startsWith(':')) + { + str=str.remove(0,1); + type = IfNode::OnScalar; + } return type; } @@ -311,7 +316,8 @@ bool ParsingToolBox::readNumber(QString& str, qint64& myNumber) if(number.isEmpty()) { - return readVariable(str,myNumber); + QString reason; + return readVariable(str,myNumber,reason); } bool ok; @@ -376,7 +382,7 @@ bool ParsingToolBox::readString(QString &str, QString& strResult) return false; } -bool ParsingToolBox::readVariable(QString &str, qint64 &myNumber) +bool ParsingToolBox::readVariable(QString &str, qint64 &myNumber, QString& reasonFail) { if(str.isEmpty()) return false; @@ -390,6 +396,7 @@ bool ParsingToolBox::readVariable(QString &str, qint64 &myNumber) if(NULL!=m_variableHash) { + qDebug() << m_variableHash->keys(); if(m_variableHash->contains(key)) { QString value = m_variableHash->value(key); @@ -401,10 +408,21 @@ bool ParsingToolBox::readVariable(QString &str, qint64 &myNumber) str=str.remove(0,post+1); return true; } + else + { + reasonFail = QStringLiteral("Variable value is %1, not a number").arg(value); + } } + else + { + reasonFail = QStringLiteral("Variable not found"); + } + } + else + { + reasonFail = QStringLiteral("No Variables are defined"); } - return false; diff --git a/parsingtoolbox.h b/parsingtoolbox.h index 75c01c2..6bfffd0 100644 --- a/parsingtoolbox.h +++ b/parsingtoolbox.h @@ -110,7 +110,7 @@ public: * @param myNumber * @return */ - static bool readVariable(QString& str,qint64& myNumber); + static bool readVariable(QString& str,qint64& myNumber, QString& reasonFail); /** * @brief readOpenParentheses * @param str |