aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--HelpMe.md16
-rw-r--r--booleancondition.cpp37
-rw-r--r--booleancondition.h2
-rw-r--r--diceparser.cpp241
-rw-r--r--diceparser.h73
-rw-r--r--diceparser.pri67
-rw-r--r--node/dicerollernode.cpp32
-rw-r--r--node/dicerollernode.h22
-rw-r--r--node/executionnode.h2
-rw-r--r--node/helpnode.cpp2
-rw-r--r--node/node.pri52
-rw-r--r--node/sortresult.cpp3
-rw-r--r--parsingtoolbox.cpp39
-rw-r--r--parsingtoolbox.h20
-rw-r--r--range.cpp7
-rw-r--r--range.h1
-rw-r--r--validator.h1
17 files changed, 528 insertions, 89 deletions
diff --git a/HelpMe.md b/HelpMe.md
index efb42b7..b3c1a4d 100644
--- a/HelpMe.md
+++ b/HelpMe.md
@@ -45,13 +45,25 @@ Thanks of several operations and option, you can tune a bit you rolling command.
> kX
-The option sorts the resulting die list and select the X best dice.
+The option sorts the resulting die list and select the X higher dice.
### Keep And Explose
> KX
-Dice explose if their value are at the die maximum, the option sorts the resulting die list, the it selects the X best dice.
+Dice explose if their value are at the die maximum, the option sorts the resulting die list, the it selects the X higher dice.
+
+### Keep Lower dice
+
+> klX
+
+The option sorts the resulting die list and select the X lowest dice.
+
+### Keep Lower dice
+
+> klX
+
+Dice explose if their value are at the die maximum, the option sorts the resulting die list, the it selects the X lowest dice.
### Sorting
diff --git a/booleancondition.cpp b/booleancondition.cpp
index 49e055a..267d7e9 100644
--- a/booleancondition.cpp
+++ b/booleancondition.cpp
@@ -77,5 +77,40 @@ void BooleanCondition::setValue(qint64 v)
}
QString BooleanCondition::toString()
{
- return QString("BooleanCondition_op_%1_value_%2").arg(m_operator).arg(m_value);
+ QString str="";
+ switch (m_operator)
+ {
+ case Equal:
+ str.append("=");
+ break;
+ case GreaterThan:
+ str.append(">");
+ break;
+ case LesserThan:
+ str.append("<");
+ break;
+ case GreaterOrEqual:
+ str.append(">=");
+ break;
+ case LesserOrEqual:
+ str.append("<=");
+ break;
+ }
+ return QString("[%1%2]").arg(str).arg(m_value);
+}
+quint8 BooleanCondition::getValidRangeSize(quint64 faces) const
+{
+ switch (m_operator)
+ {
+ case Equal:
+ return 1;
+ case GreaterThan:
+ return faces-m_value;
+ case LesserThan:
+ return m_value-1;
+ case GreaterOrEqual:
+ return faces-(m_value-1);
+ case LesserOrEqual:
+ return m_value;
+ }
}
diff --git a/booleancondition.h b/booleancondition.h
index ea5eefd..02fadf9 100644
--- a/booleancondition.h
+++ b/booleancondition.h
@@ -37,6 +37,8 @@ public:
void setValue(qint64);
QString toString();
+ virtual quint8 getValidRangeSize(quint64 faces) const;
+
private:
LogicOperator m_operator;
qint64 m_value;
diff --git a/diceparser.cpp b/diceparser.cpp
index 23e40cd..91e4af0 100644
--- a/diceparser.cpp
+++ b/diceparser.cpp
@@ -100,6 +100,7 @@ QString DiceParser::convertAlias(QString str)
bool DiceParser::parseLine(QString str)
{
+ m_errorMap.clear();
m_command = str;
m_start = new StartingNode();
ExecutionNode* newNode = NULL;
@@ -108,7 +109,7 @@ bool DiceParser::parseLine(QString str)
str = convertAlias(str);
bool keepParsing = readExpression(str,newNode);
- while(keepParsing)
+ if(keepParsing)
{
m_current->setNextNode(newNode);
m_current = getLatestNode(m_current);
@@ -119,10 +120,16 @@ bool DiceParser::parseLine(QString str)
m_current = getLatestNode(m_current);
}
- return true;
+ }
+ if(m_errorMap.isEmpty())
+ {
+ return true;
+ }
+ else
+ {
+ return false;
}
- return false;
}
@@ -232,24 +239,24 @@ QString DiceParser::displayResult()
QString str;
QTextStream stream(&str);
- Result* myResult=next->getResult();
+ Result* result=next->getResult();
- QString totalValue("you get %1 ;");
+ QString totalValue("you got %1 ;");
QString dieValue("D%1 : {%2} ");
bool scalarDone=false;
- while(NULL!=myResult)
+ while(NULL!=result)
{
++resulCount;
- if((myResult->hasResultOfType(Result::SCALAR))&&(!scalarDone))
+ if((result->hasResultOfType(Result::SCALAR))&&(!scalarDone))
{
- stream << totalValue.arg(myResult->getResult(Result::SCALAR).toReal()) << endl; //.arg(m_command)
+ stream << totalValue.arg(result->getResult(Result::SCALAR).toReal()) << endl; //.arg(m_command)
scalarDone=true;
}
- else if(myResult->hasResultOfType(Result::DICE_LIST))
+ else if(result->hasResultOfType(Result::DICE_LIST))
{
- DiceResult* myDiceResult = dynamic_cast<DiceResult*>(myResult);
+ DiceResult* myDiceResult = dynamic_cast<DiceResult*>(result);
if(NULL!=myDiceResult)
{
@@ -286,12 +293,12 @@ QString DiceParser::displayResult()
}
}
- else if(myResult->hasResultOfType(Result::STRING))
+ else if(result->hasResultOfType(Result::STRING))
{
- stream << myResult->getResult(Result::STRING).toString();
+ stream << result->getResult(Result::STRING).toString();
}
- myResult = myResult->getPrevious();
+ result = result->getPrevious();
}
QTextStream out(stdout);
@@ -303,8 +310,164 @@ QString DiceParser::displayResult()
// qDebug() << "result count:" << resulCount;
}
+qreal DiceParser::getLastIntegerResult()
+{
+ ExecutionNode* next = getLeafNode();
+ Result* result=next->getResult();
+ qreal resultValue;
+ bool scalarDone = false;
+ while((result!=NULL)&&(!scalarDone))
+ {
+ if(result->hasResultOfType(Result::SCALAR))
+ {
+ resultValue = result->getResult(Result::SCALAR).toReal();
+ scalarDone=true;
+ }
+ result=result->getPrevious();
+ }
+ return resultValue;
+}
+QString DiceParser::getStringResult()
+{
+ ExecutionNode* next = getLeafNode();
+ QString str;
+
+ Result* result=next->getResult();
+ bool found = false;
+ while((NULL!=result) && (!found) )
+ {
+ if(result->hasResultOfType(Result::STRING))
+ {
+ str = result->getResult(Result::STRING).toString();
+ found = true;
+ }
+
+ result = result->getPrevious();
+ }
+ return str;
+}
+QString DiceParser::getLastDiceResult()
+{
+ ExecutionNode* next = getLeafNode();
+ QString str;
+ QTextStream stream(&str);
+ Result* result=next->getResult();
+ QString dieValue("D%1 : {%2} ");
+ while(NULL!=result)
+ {
+ if(result->hasResultOfType(Result::DICE_LIST))
+ {
+
+ DiceResult* myDiceResult = dynamic_cast<DiceResult*>(result);
+ if(NULL!=myDiceResult)
+ {
+
+ QString resulStr;
+ quint64 face=0;
+ foreach(Die* die, myDiceResult->getResultList())
+ {
+ if(!die->hasBeenDisplayed())
+ {
+ resulStr+=QString("%1").arg(die->getValue());
+ die->displayed();
+ face = die->getFaces();
+
+
+ if(die->hasChildrenValue())
+ {
+ resulStr+=" [";
+ foreach(qint64 i, die->getListValue())
+ {
+
+ resulStr+=QString("%1,").arg(i);
+ }
+ resulStr.remove(resulStr.size()-1,1);
+ resulStr+="]";
+ }
+ resulStr+=", ";
+ }
+ }
+ resulStr.remove(resulStr.size()-2,2);
+
+ if(!resulStr.isEmpty())
+ {
+ stream << dieValue.arg(face).arg(resulStr);
+ }
+ }
+ }
+
+ result = result->getPrevious();
+ }
+
+ return str.simplified();
+}
+QString DiceParser::getDiceCommand()
+{
+ return m_command;
+}
+
+bool DiceParser::hasIntegerResultNotInFirst()
+{
+ return hasResultOfType(Result::SCALAR,true);
+}
+bool DiceParser::hasDiceResult()
+{
+ return hasResultOfType(Result::DICE_LIST);
+}
+bool DiceParser::hasStringResult()
+{
+ return hasResultOfType(Result::STRING);
+}
+bool DiceParser::hasResultOfType(Result::RESULT_TYPE type, bool notthelast)
+{
+ ExecutionNode* next = getLeafNode();
+ Result* result=next->getResult();
+ bool scalarDone = false;
+ while((result!=NULL)&&(!scalarDone))
+ {
+ if(result->hasResultOfType(type) && ((!notthelast)||(notthelast && (NULL!=result->getPrevious()))))
+ {
+ scalarDone=true;
+ }
+ result=result->getPrevious();
+ }
+ return scalarDone;
+}
+qreal DiceParser::getSumOfDiceResult()
+{
+ ExecutionNode* next = getLeafNode();
+ qreal resultValue=0;
+ Result* result=next->getResult();
+ bool found = false;
+ while((NULL!=result)&&(!found))
+ {
+ if(result->hasResultOfType(Result::DICE_LIST))
+ {
+ DiceResult* myDiceResult = dynamic_cast<DiceResult*>(result);
+ if(NULL!=myDiceResult)
+ {
+ foreach(Die* die, myDiceResult->getResultList())
+ {
+ resultValue+=die->getValue();
+ }
+ found = true;
+ }
+ }
+ result = result->getPrevious();
+ }
+ return resultValue;
+}
+ExecutionNode* DiceParser::getLeafNode()
+{
+ ExecutionNode* next = m_start;
+ while(NULL != next->getNextNode() )
+ {
+ next = next->getNextNode();
+ }
+ return next;
+}
bool DiceParser::readDice(QString& str,ExecutionNode* & node)
{
@@ -496,11 +659,19 @@ DiceRollerNode* DiceParser::addRollDiceNode(qint64 faces,ExecutionNode* previous
previous->setNextNode(mydiceRoller);
return mydiceRoller;
}
-
+ExploseDiceNode* DiceParser::addExploseDiceNode(qint64 value,ExecutionNode* previous)
+{
+ ExploseDiceNode* exploseDiceNode= new ExploseDiceNode();
+ BooleanCondition* condition = new BooleanCondition();
+ condition->setValue(value);
+ condition->setOperator(BooleanCondition::Equal);
+ m_parsingToolbox->isValidValidator(previous,condition);
+ exploseDiceNode->setValidator(condition);
+ previous->setNextNode(exploseDiceNode);
+ return exploseDiceNode;
+}
bool DiceParser::readOption(QString& str,ExecutionNode* previous, bool hasDice)
{
-
-
if(str.isEmpty())
{
return false;
@@ -509,8 +680,6 @@ bool DiceParser::readOption(QString& str,ExecutionNode* previous, bool hasDice)
ExecutionNode* node = NULL;
bool isFine=false;
-
-
for(int i = 0; ((i<m_OptionOp->keys().size())&&(!isFine));++i )
{
QString tmp =m_OptionOp->keys().at(i);
@@ -525,15 +694,14 @@ bool DiceParser::readOption(QString& str,ExecutionNode* previous, bool hasDice)
case Keep:
{
int myNumber=0;
+ bool ascending = m_parsingToolbox->readAscending(str);
if(m_parsingToolbox->readNumber(str,myNumber))
{
if(!hasDice)
{
previous = addRollDiceNode(10,previous);
}
-
-
- node = m_parsingToolbox->addSort(previous,false);
+ node = m_parsingToolbox->addSort(previous,ascending);
KeepDiceExecNode* nodeK = new KeepDiceExecNode();
nodeK->setDiceKeepNumber(myNumber);
@@ -548,15 +716,18 @@ bool DiceParser::readOption(QString& str,ExecutionNode* previous, bool hasDice)
case KeepAndExplose:
{
int myNumber=0;
+ bool ascending = m_parsingToolbox->readAscending(str);
if(m_parsingToolbox->readNumber(str,myNumber))
{
if(!hasDice)
{
previous = addRollDiceNode(10,previous);
}
+ DiceRollerNode* nodeTmp = dynamic_cast<DiceRollerNode*>(previous);
+ previous = addExploseDiceNode(nodeTmp->getFaces(),previous);
- node = m_parsingToolbox->addSort(previous,false);
+ node = m_parsingToolbox->addSort(previous,ascending);
KeepDiceExecNode* nodeK = new KeepDiceExecNode();
nodeK->setDiceKeepNumber(myNumber);
@@ -568,10 +739,10 @@ bool DiceParser::readOption(QString& str,ExecutionNode* previous, bool hasDice)
}
}
break;
- break;
case Sort:
{
- node = m_parsingToolbox->addSort(previous,false);
+ bool ascending = m_parsingToolbox->readAscending(str);
+ node = m_parsingToolbox->addSort(previous,ascending);
isFine = true;
}
@@ -581,6 +752,9 @@ bool DiceParser::readOption(QString& str,ExecutionNode* previous, bool hasDice)
Validator* validator = m_parsingToolbox->readValidator(str);
if(NULL!=validator)
{
+ /// @todo display warning here.
+ bool b = m_parsingToolbox->isValidValidator(previous,validator);
+
CountExecuteNode* countNode = new CountExecuteNode();
countNode->setValidator(validator);
@@ -596,6 +770,8 @@ bool DiceParser::readOption(QString& str,ExecutionNode* previous, bool hasDice)
Validator* validator = m_parsingToolbox->readValidator(str);
if(NULL!=validator)
{
+ /// @todo display warning here.
+ bool b = m_parsingToolbox->isValidValidator(previous,validator);
RerollDiceNode* rerollNode = new RerollDiceNode();
if(m_OptionOp->value(tmp)==RerollAndAdd)
{
@@ -616,11 +792,16 @@ bool DiceParser::readOption(QString& str,ExecutionNode* previous, bool hasDice)
Validator* validator = m_parsingToolbox->readValidator(str);
if(NULL!=validator)
{
+ if(!m_parsingToolbox->isValidValidator(previous,validator))
+ {
+ m_errorMap.insert(ExecutionNode::ENDLESS_LOOP_ERROR,QObject::tr("This condition %1 introduces an endless loop. Please, change it").arg(validator->toString()));
+ }
ExploseDiceNode* explosedNode = new ExploseDiceNode();
explosedNode->setValidator(validator);
previous->setNextNode(explosedNode);
node = explosedNode;
isFine = true;
+
}
}
@@ -635,6 +816,18 @@ QList<ExecutionNode::ERROR_CODE> DiceParser::getErrorList()
{
return m_start->getErrorList();
}
+QString DiceParser::humanReadableError()
+{
+ QMapIterator<ExecutionNode::ERROR_CODE,QString> i(m_errorMap);
+ QString str="";
+ while (i.hasNext())
+ {
+ i.next();
+ str.append(i.value());
+ str.append("\n");
+ }
+ return str;
+}
bool DiceParser::readOperand(QString& str,ExecutionNode* & node)
{
diff --git a/diceparser.h b/diceparser.h
index 65a8b03..e4ea0e3 100644
--- a/diceparser.h
+++ b/diceparser.h
@@ -33,6 +33,7 @@
#include "booleancondition.h"
#include "parsingtoolbox.h"
+class ExploseDiceNode;
/**
* @mainpage DiceParser
*
@@ -109,6 +110,51 @@ public:
* @brief displayDotTree
*/
void displayDotTree();
+ /**
+ * @brief getLastIntegerResult
+ * @return
+ */
+ qreal getLastIntegerResult();
+ /**
+ * @brief getSumOfDiceResult
+ * @return
+ */
+ qreal getSumOfDiceResult();
+ /**
+ * @brief getLastDiceResult
+ * @return
+ */
+ QString getLastDiceResult();
+ /**
+ * @brief hasIntegerResultNotInFirst
+ * @return
+ */
+ bool hasIntegerResultNotInFirst();
+ /**
+ * @brief hasDiceResult
+ * @return
+ */
+ bool hasDiceResult();
+ /**
+ * @brief getDiceCommand
+ * @return
+ */
+ QString getDiceCommand();
+ /**
+ * @brief hasStringResult
+ * @return
+ */
+ bool hasStringResult();
+ /**
+ * @brief getStringResult
+ * @return
+ */
+ QString getStringResult();
+ /**
+ * @brief humanReadableError
+ * @return
+ */
+ QString humanReadableError();
private:
/**
@@ -157,7 +203,13 @@ private:
* @return
*/
DiceRollerNode* addRollDiceNode(qint64 faces,ExecutionNode*);
-
+ /**
+ * @brief addExploseDiceNode
+ * @param faces
+ * @param previous
+ * @return
+ */
+ ExploseDiceNode* addExploseDiceNode(qint64 faces,ExecutionNode* previous);
/**
* @brief readOperand
* @param node
@@ -176,12 +228,25 @@ private:
* @return
*/
QList<ExecutionNode::ERROR_CODE> getErrorList();
-
+ /**
+ * @brief readInstructionOperator
+ * @param c
+ * @return
+ */
bool readInstructionOperator(QChar c);
-
+ /**
+ * @brief readNode
+ * @param str
+ * @param node
+ * @return
+ */
bool readNode(QString& str,ExecutionNode* & node);
+ ExecutionNode* getLeafNode();
+ bool hasResultOfType(Result::RESULT_TYPE,bool notthelast = false);
+
+
private:
QMap<QString,DiceOperator>* m_mapDiceOp;
QMap<QString,OptionOperator>* m_OptionOp;
@@ -189,6 +254,8 @@ private:
QMap<QString,QString>* m_aliasMap;
QStringList* m_commandList;
+ QMap<ExecutionNode::ERROR_CODE,QString> m_errorMap;
+
ExecutionNode* m_start;
ExecutionNode* m_current;
diff --git a/diceparser.pri b/diceparser.pri
index e69de29..b9af1d7 100644
--- a/diceparser.pri
+++ b/diceparser.pri
@@ -0,0 +1,67 @@
+
+INCLUDEPATH += $$PWD/result
+INCLUDEPATH += $$PWD/node
+INCLUDEPATH += $$PWD
+
+SOURCES += $$PWD/diceparser.cpp \
+ $$PWD/result/diceresult.cpp \
+ $$PWD/range.cpp \
+ $$PWD/booleancondition.cpp \
+ $$PWD/validator.cpp \
+ $$PWD/die.cpp \
+ $$PWD/result/result.cpp \
+ $$PWD/result/scalarresult.cpp \
+ $$PWD/parsingtoolbox.cpp \
+ $$PWD/result/stringresult.cpp
+
+
+HEADERS += \
+ $$PWD/diceparser.h \
+ $$PWD/result/diceresult.h \
+ $$PWD/range.h \
+ $$PWD/booleancondition.h \
+ $$PWD/validator.h \
+ $$PWD/die.h \
+ $$PWD/result/result.h \
+ $$PWD/result/scalarresult.h \
+ $$PWD/result/parsingtoolbox.h \
+ $$PWD/result/stringresult.h
+
+
+HEADERS += \
+ $$PWD/node/dicerollernode.h \
+ $$PWD/node/executionnode.h \
+ $$PWD/node/rerolldicenode.h \
+ $$PWD/node/startingnode.h \
+ $$PWD/node/scalaroperatornode.h \
+ $$PWD/node/numbernode.h \
+ $$PWD/node/sortresult.h \
+ $$PWD/node/keepdiceexecnode.h \
+ $$PWD/node/countexecutenode.h \
+ $$PWD/node/explosedicenode.h \
+ $$PWD/node/parenthesesnode.h \
+ $$PWD/node/helpnode.h \
+ $$PWD/node/jumpbackwardnode.h \
+ $$PWD/node/listaliasnode.h \
+ $$PWD/node/listsetrollnode.h
+
+SOURCES += \
+ $$PWD/node/dicerollernode.cpp \
+ $$PWD/node/executionnode.cpp \
+ $$PWD/node/startingnode.cpp \
+ $$PWD/node/rerolldicenode.cpp \
+ $$PWD/node/scalaroperatornode.cpp \
+ $$PWD/node/numbernode.cpp \
+ $$PWD/node/sortresult.cpp \
+ $$PWD/node/keepdiceexecnode.cpp \
+ $$PWD/node/countexecutenode.cpp \
+ $$PWD/node/explosedicenode.cpp \
+ $$PWD/node/parenthesesnode.cpp \
+ $$PWD/node/helpnode.cpp \
+ $$PWD/node/jumpbackwardnode.cpp \
+ $$PWD/node/listaliasnode.cpp \
+ $$PWD/node/listsetrollnode.cpp
+
+
+OTHER_FILES += \
+ $$PWD/HelpMe.md
diff --git a/node/dicerollernode.cpp b/node/dicerollernode.cpp
index 8eecf0d..1fd1a2f 100644
--- a/node/dicerollernode.cpp
+++ b/node/dicerollernode.cpp
@@ -8,24 +8,24 @@
#include <QTime>
-DiceRoller::DiceRoller(QMutex* mutex,DiceResult* diceResult,int faces,int count)
- : m_mutex(mutex),m_sharedDiceResult(diceResult),m_faces(faces),m_diceCount(count)
-{
+//DiceRoller::DiceRoller(QMutex* mutex,DiceResult* diceResult,int faces,int count)
+// : m_mutex(mutex),m_sharedDiceResult(diceResult),m_faces(faces),m_diceCount(count)
+//{
-}
+//}
-void DiceRoller::run()
-{
- for(quint64 i=0; i < m_diceCount ; ++i)
- {
- Die* die = new Die();
- die->setFaces(m_faces);
- die->roll();
- m_mutex->lock();
- m_sharedDiceResult->insertResult(die);
- m_mutex->unlock();
- }
-}
+//void DiceRoller::run()
+//{
+// for(quint64 i=0; i < m_diceCount ; ++i)
+// {
+// Die* die = new Die();
+// die->setFaces(m_faces);
+// die->roll();
+// m_mutex->lock();
+// m_sharedDiceResult->insertResult(die);
+// m_mutex->unlock();
+// }
+//}
diff --git a/node/dicerollernode.h b/node/dicerollernode.h
index 472a5d8..d50fe95 100644
--- a/node/dicerollernode.h
+++ b/node/dicerollernode.h
@@ -7,17 +7,17 @@
#include "executionnode.h"
#include "result/diceresult.h"
-class DiceRoller : public QRunnable
-{
-public:
- DiceRoller(QMutex* mutex,DiceResult* diceResult,int faces,int count);
- virtual void run ();
-private:
- QMutex* m_mutex;
- DiceResult* m_sharedDiceResult;
- int m_faces;
- quint64 m_diceCount;
-};
+//class DiceRoller : public QRunnable
+//{
+//public:
+// DiceRoller(QMutex* mutex,DiceResult* diceResult,int faces,int count);
+// virtual void run ();
+//private:
+// QMutex* m_mutex;
+// DiceResult* m_sharedDiceResult;
+// int m_faces;
+// quint64 m_diceCount;
+//};
/**
* @brief The DiceRollerNode class
diff --git a/node/executionnode.h b/node/executionnode.h
index e0fc563..cf1514f 100644
--- a/node/executionnode.h
+++ b/node/executionnode.h
@@ -9,7 +9,7 @@
class ExecutionNode
{
public:
- enum ERROR_CODE {NO_ERROR,DIE_RESULT_EXPECTED,BAD_SYNTAXE};
+ enum ERROR_CODE {NO_ERROR,DIE_RESULT_EXPECTED,BAD_SYNTAXE,ENDLESS_LOOP_ERROR};
/**
* @brief ExecutionNode
*/
diff --git a/node/helpnode.cpp b/node/helpnode.cpp
index 82f44f8..f31fac1 100644
--- a/node/helpnode.cpp
+++ b/node/helpnode.cpp
@@ -30,7 +30,7 @@ void HelpNode::run(ExecutionNode* previous)
}
QString HelpNode::toString()const
{
- return QObject::tr("Rolisteam Dice Parser: Full documentation at: https://github.com/obiwankennedy/DiceParser/blob/master/HelpMe.md\n");
+ return QObject::tr("Rolisteam Dice Parser: Full documentation at: <a href=\"https://github.com/obiwankennedy/DiceParser/blob/master/HelpMe.md\">https://github.com/obiwankennedy/DiceParser/blob/master/HelpMe.md</a> \n");
}
qint64 HelpNode::getPriority() const
diff --git a/node/node.pri b/node/node.pri
index 7424c0b..d7f5c7c 100644
--- a/node/node.pri
+++ b/node/node.pri
@@ -1,33 +1,33 @@
HEADERS += \
- node/dicerollernode.h \
- node/executionnode.h \
- node/rerolldicenode.h \
- node/startingnode.h \
- node/scalaroperatornode.h \
- node/numbernode.h \
- node/sortresult.h \
- node/keepdiceexecnode.h \
- node/countexecutenode.h \
- node/explosedicenode.h \
- node/parenthesesnode.h \
- node/helpnode.h \
+ $$PWD/dicerollernode.h \
+ $$PWD/executionnode.h \
+ $$PWD/rerolldicenode.h \
+ $$PWD/startingnode.h \
+ $$PWD/scalaroperatornode.h \
+ $$PWD/numbernode.h \
+ $$PWD/sortresult.h \
+ $$PWD/keepdiceexecnode.h \
+ $$PWD/countexecutenode.h \
+ $$PWD/explosedicenode.h \
+ $$PWD/parenthesesnode.h \
+ $$PWD/helpnode.h \
$$PWD/jumpbackwardnode.h \
- node/listsetrollnode.h \
+ $$PWD/listsetrollnode.h
$$PWD/listaliasnode.h
SOURCES += \
- node/dicerollernode.cpp \
- node/executionnode.cpp \
- node/startingnode.cpp \
- node/rerolldicenode.cpp \
- node/scalaroperatornode.cpp \
- node/numbernode.cpp \
- node/sortresult.cpp \
- node/keepdiceexecnode.cpp \
- node/countexecutenode.cpp \
- node/explosedicenode.cpp \
- node/parenthesesnode.cpp \
- node/helpnode.cpp \
+ $$PWD/dicerollernode.cpp \
+ $$PWD/executionnode.cpp \
+ $$PWD/startingnode.cpp \
+ $$PWD/rerolldicenode.cpp \
+ $$PWD/scalaroperatornode.cpp \
+ $$PWD/numbernode.cpp \
+ $$PWD/sortresult.cpp \
+ $$PWD/keepdiceexecnode.cpp \
+ $$PWD/countexecutenode.cpp \
+ $$PWD/explosedicenode.cpp \
+ $$PWD/parenthesesnode.cpp \
+ $$PWD/helpnode.cpp \
$$PWD/jumpbackwardnode.cpp \
- node/listsetrollnode.cpp \
+ $$PWD/listsetrollnode.cpp
$$PWD/listaliasnode.cpp
diff --git a/node/sortresult.cpp b/node/sortresult.cpp
index 5d7f142..46e6eb8 100644
--- a/node/sortresult.cpp
+++ b/node/sortresult.cpp
@@ -72,9 +72,6 @@ void SortResultNode::run(ExecutionNode* node)
}
}
-
-
-
m_diceResult->setResultList(diceList2);
if(NULL!=m_nextNode)
{
diff --git a/parsingtoolbox.cpp b/parsingtoolbox.cpp
index 0d749cc..e03690e 100644
--- a/parsingtoolbox.cpp
+++ b/parsingtoolbox.cpp
@@ -186,3 +186,42 @@ bool ParsingToolBox::readList(QString& str,QStringList& list)
}
return false;
}
+bool ParsingToolBox::readAscending(QString& str)
+{
+ if(str.isEmpty())
+ {
+ return false;
+ }
+ else if(str.at(0)=='l')
+ {
+ str=str.remove(0,1);
+ return true;
+ }
+ return false;
+
+
+}
+bool ParsingToolBox::isValidValidator(ExecutionNode* previous, Validator* val)
+{
+ DiceRollerNode* node = getDiceRollerNode(previous);
+ if(NULL!=node)
+ {
+ return (val->getValidRangeSize(node->getFaces())<node->getFaces());
+ }
+ else
+ {
+ return true;
+ }
+}
+DiceRollerNode* ParsingToolBox::getDiceRollerNode(ExecutionNode* previous)
+{
+ while(NULL!=previous)
+ {
+ DiceRollerNode* node = dynamic_cast<DiceRollerNode*>(previous);
+ if(NULL!=node)
+ {
+ return node;
+ }
+ previous = previous->getPreviousNode();
+ }
+}
diff --git a/parsingtoolbox.h b/parsingtoolbox.h
index 4c5ce8d..43dca4e 100644
--- a/parsingtoolbox.h
+++ b/parsingtoolbox.h
@@ -25,6 +25,7 @@
#include <QMap>
#include "node/executionnode.h"
+#include "node/dicerollernode.h"
#include "booleancondition.h"
#include "range.h"
@@ -42,6 +43,12 @@ public:
* @return
*/
ExecutionNode* addSort(ExecutionNode* e,bool b);
+ /**
+ * @brief readAscending
+ * @param str
+ * @return
+ */
+ bool readAscending(QString& str);
/**
* @brief readLogicOperator
* @param str
@@ -86,6 +93,19 @@ public:
* @return
*/
bool readList(QString& str,QStringList& list);
+ /**
+ * @brief isValidValidator
+ * @param previous
+ * @param val
+ * @return
+ */
+ bool isValidValidator(ExecutionNode* previous, Validator* val);
+ /**
+ * @brief getDiceRollerNode
+ * @param previous
+ * @return
+ */
+ DiceRollerNode* getDiceRollerNode(ExecutionNode* previous);
private:
QMap<QString,BooleanCondition::LogicOperator>* m_logicOp;
diff --git a/range.cpp b/range.cpp
index 31667e2..1f47c50 100644
--- a/range.cpp
+++ b/range.cpp
@@ -54,5 +54,10 @@ qint64 Range::hasValid(Die* m,bool recursive) const
}
QString Range::toString()
{
- return QString("Range_%1_%2").arg(m_start).arg(m_end);
+ return QString("[%1-%2]").arg(m_start).arg(m_end);
+}
+quint8 Range::getValidRangeSize(quint64 faces) const
+{
+ Q_UNUSED(faces);
+ return m_end-m_start;
}
diff --git a/range.h b/range.h
index 4f9cbed..629d0c3 100644
--- a/range.h
+++ b/range.h
@@ -34,6 +34,7 @@ public:
virtual qint64 hasValid(Die* b,bool recursive) const;
virtual QString toString();
+ virtual quint8 getValidRangeSize(quint64 faces) const;
private:
qint64 m_start;
diff --git a/validator.h b/validator.h
index 78f3e9c..c9bb78e 100644
--- a/validator.h
+++ b/validator.h
@@ -33,6 +33,7 @@ public:
virtual qint64 hasValid(Die* b,bool recursive) const = 0 ;
virtual QString toString()=0;
+ virtual quint8 getValidRangeSize(quint64 faces) const = 0 ;
};
#endif // VALIDATOR_H