diff options
| -rw-r--r-- | HelpMe.md | 7 | ||||
| -rw-r--r-- | booleancondition.cpp | 1 | ||||
| -rw-r--r-- | diceparser.cpp | 91 | ||||
| -rw-r--r-- | diceparser.h | 15 | ||||
| -rw-r--r-- | diceparser.pri | 2 | ||||
| -rw-r--r-- | node/helpnode.cpp | 20 | ||||
| -rw-r--r-- | node/helpnode.h | 19 | ||||
| -rw-r--r-- | node/keepdiceexecnode.cpp | 4 | ||||
| -rw-r--r-- | node/listaliasnode.cpp | 1 | ||||
| -rw-r--r-- | node/parenthesesnode.cpp | 1 | ||||
| -rw-r--r-- | node/scalaroperatornode.cpp | 2 | ||||
| -rw-r--r-- | node/sortresult.cpp | 7 | ||||
| -rw-r--r-- | node/startingnode.cpp | 21 | ||||
| -rw-r--r-- | node/startingnode.h | 20 | ||||
| -rw-r--r-- | parsingtoolbox.cpp | 2 | ||||
| -rw-r--r-- | result/diceresult.cpp | 1 | ||||
| -rw-r--r-- | result/stringresult.cpp | 10 | ||||
| -rw-r--r-- | result/stringresult.h | 4 |
18 files changed, 191 insertions, 37 deletions
@@ -30,7 +30,6 @@ Roll five ten-faced die. Roll 777 six-faced die. - Thanks of several operations and option, you can tune a bit you rolling command. ## List of operator @@ -109,6 +108,10 @@ Rolling 4 dice with value between -1 to 1. (Fudge/Fate system) Rolling 3 dice with 10 faces starting at 0. +> 3d[-20--9] + +Rolling 3 dice, values ars between -20 and -9. + ## Arithmetic Rolisteam Dice Parser is able to compute primary arithmetic operation such as: +, -, /, * and it also manages those operator priority and it can also manage parenthesis. @@ -159,7 +162,7 @@ Substract 4 to 6 and then roll two dice. Divide by 2 the result of 1 die. -## Roll two (or more) kind of dice at once. +## Roll two (or more) kinds of dice at once. To make it, you have to separate all dice commands by `;` diff --git a/booleancondition.cpp b/booleancondition.cpp index 043e2c8..c09166e 100644 --- a/booleancondition.cpp +++ b/booleancondition.cpp @@ -23,6 +23,7 @@ BooleanCondition::BooleanCondition() + : m_operator(Equal) { } qint64 BooleanCondition::hasValid(Die* b,bool recursive,bool unhighlight) const diff --git a/diceparser.cpp b/diceparser.cpp index 6d043a1..b7097d3 100644 --- a/diceparser.cpp +++ b/diceparser.cpp @@ -42,8 +42,9 @@ #define DEFAULT_FACES_NUMBER 10 DiceParser::DiceParser() - : m_start(NULL) + : m_start(NULL),m_current(NULL) { + m_currentTreeHasSeparator =false; m_parsingToolbox = new ParsingToolBox(); m_mapDiceOp = new QMap<QString,DiceOperator>(); @@ -166,7 +167,8 @@ bool DiceParser::parseLine(QString str) keepParsing =!str.isEmpty(); if(keepParsing) { - keepParsing = readOperator(str,m_current); + // keepParsing = + readOperator(str,m_current); m_current = getLatestNode(m_current); } @@ -176,12 +178,11 @@ bool DiceParser::parseLine(QString str) { return true; } - else + else if(m_errorMap.isEmpty()) { - m_errorMap.insert(ExecutionNode::NOTHING_UNDERSTOOD,QObject::tr("Nothing was understood")); - return false; + m_errorMap.insert(ExecutionNode::NOTHING_UNDERSTOOD,QObject::tr("Nothing was understood")); } - + return false; } bool DiceParser::readExpression(QString& str,ExecutionNode* & node) @@ -390,6 +391,58 @@ QString DiceParser::getStringResult() } return str; } +QStringList DiceParser::getAllStringResult(bool& hasAlias) +{ + ExecutionNode* next = getLeafNode(); + Result* result=next->getResult(); + QStringList stringListResult; + + while(NULL!=result) + { + if(result->hasResultOfType(Result::STRING)) + { + StringResult* stringResult = dynamic_cast<StringResult*>(result); + if(NULL!=stringResult) + { + stringListResult << stringResult->getText(); + hasAlias = stringResult->hasHighLight(); + } + } + result = result->getPrevious(); + } + + return stringListResult; +} +QStringList DiceParser::getAllDiceResult(bool& hasAlias) +{ + ExecutionNode* next = getLeafNode(); + Result* result=next->getResult(); + QList<Die*> dieListResult; + QStringList stringListResult; + + while(NULL!=result) + { + if(result->hasResultOfType(Result::DICE_LIST)) + { + DiceResult* stringResult = dynamic_cast<DiceResult*>(result); + if(NULL!=stringResult) + { + dieListResult << stringResult->getResultList(); + hasAlias = true; + } + } + result = result->getPrevious(); + } + foreach(Die* die, dieListResult) + { + foreach (qint64 value, die->getListValue()) + { + stringListResult << QString::number(value); + } + } + + return stringListResult; +} void DiceParser::getLastDiceResult(ExportedDiceResult& diceValues) { ExecutionNode* next = getLeafNode(); @@ -402,7 +455,6 @@ void DiceParser::getLastDiceResult(ExportedDiceResult& diceValues) DiceResult* diceResult = dynamic_cast<DiceResult*>(result); if(NULL!=diceResult) { - bool hasResult = false; quint64 face=0; ListDiceResult listpair; foreach(Die* die, diceResult->getResultList()) @@ -410,7 +462,6 @@ void DiceParser::getLastDiceResult(ExportedDiceResult& diceValues) if(!die->hasBeenDisplayed()) { QList<quint64> valuesResult; - hasResult=true; valuesResult.append(die->getValue()); die->displayed(); face = die->getFaces(); @@ -519,10 +570,10 @@ bool DiceParser::readDice(QString& str,ExecutionNode* & node) if(readDiceOperator(str,currentOperator)) { - qint64 num; - qint64 end; if(currentOperator==D) { + int num; + int end; if(m_parsingToolbox->readNumber(str,num)) { if(num<1) @@ -687,20 +738,17 @@ bool DiceParser::readOperator(QString& str,ExecutionNode* previous) } else if(readInstructionOperator(str[0])) { - str=str.remove(0,1); - delete node; + str=str.remove(0,1); + delete node; ExecutionNode* nodeExec = NULL; if(readExpression(str,nodeExec)) { - - // nodeExec = getLatestNode(nodeExec); - if(NULL==nodeExec) { return false; } previous->setNextNode(nodeExec); - + m_currentTreeHasSeparator = true; return true; } } @@ -714,6 +762,10 @@ bool DiceParser::readOperator(QString& str,ExecutionNode* previous) } return false; } +bool DiceParser::hasSeparator()const +{ + return m_currentTreeHasSeparator; +} DiceRollerNode* DiceParser::addRollDiceNode(qint64 faces,ExecutionNode* previous) { DiceRollerNode* mydiceRoller= new DiceRollerNode(faces); @@ -819,7 +871,8 @@ bool DiceParser::readOption(QString& str,ExecutionNode* previous, bool hasDice)/ if(NULL!=validator) { /// @todo display warning here. - bool b = m_parsingToolbox->isValidValidator(previous,validator); + //bool b = + m_parsingToolbox->isValidValidator(previous,validator); CountExecuteNode* countNode = new CountExecuteNode(); countNode->setValidator(validator); @@ -842,7 +895,8 @@ bool DiceParser::readOption(QString& str,ExecutionNode* previous, bool hasDice)/ if(NULL!=validator) { /// @todo display warning here. - bool b = m_parsingToolbox->isValidValidator(previous,validator); + //bool b = + m_parsingToolbox->isValidValidator(previous,validator); RerollDiceNode* rerollNode = new RerollDiceNode(); if(m_OptionOp->value(tmp)==RerollAndAdd) { @@ -942,7 +996,6 @@ void DiceParser::writeDownDotTree(QString filepath) QTextStream in(&file); in << str; } - } void DiceParser::setPathToHelp(QString l) { diff --git a/diceparser.h b/diceparser.h index 3eb55f1..6b9056f 100644 --- a/diceparser.h +++ b/diceparser.h @@ -191,6 +191,19 @@ public: * @param l the path. */ void setPathToHelp(QString l); + /** + * @brief getAllStringResult + * @return + */ + QStringList getAllStringResult(bool& hasAlias); + /** + * @brief getAllDiceResult + * @param hasAlias + * @return + */ + QStringList getAllDiceResult(bool& hasAlias); + + bool hasSeparator()const; private: /** @@ -289,6 +302,7 @@ private: QStringList* m_commandList; QMap<ExecutionNode::ERROR_CODE,QString> m_errorMap; + QMap<ExecutionNode::ERROR_CODE,QString> m_warningMap; ExecutionNode* m_start; @@ -296,6 +310,7 @@ private: QString m_command; ParsingToolBox* m_parsingToolbox; QString m_helpPath; + bool m_currentTreeHasSeparator; }; #endif // DICEPARSER_H diff --git a/diceparser.pri b/diceparser.pri index cacca31..22ef326 100644 --- a/diceparser.pri +++ b/diceparser.pri @@ -25,7 +25,7 @@ HEADERS += \ $$PWD/die.h \ $$PWD/result/result.h \ $$PWD/result/scalarresult.h \ - $$PWD/result/parsingtoolbox.h \ + $$PWD/parsingtoolbox.h \ $$PWD/result/stringresult.h \ $$PWD/dicealias.h diff --git a/node/helpnode.cpp b/node/helpnode.cpp index d4a5d4b..6f3916a 100644 --- a/node/helpnode.cpp +++ b/node/helpnode.cpp @@ -1,3 +1,22 @@ +/*************************************************************************** + * Copyright (C) 2015 by Renaud Guezennec * + * http://renaudguezennec.homelinux.org/accueil,3.html * + * * + * rolisteam is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ #include "helpnode.h" HelpNode::HelpNode() @@ -9,6 +28,7 @@ void HelpNode::run(ExecutionNode* previous) { m_previousNode = previous; StringResult* txtResult = dynamic_cast<StringResult*>(m_result); + txtResult->setHighLight(false); if(NULL != previous) { diff --git a/node/helpnode.h b/node/helpnode.h index c492e66..ba59f1f 100644 --- a/node/helpnode.h +++ b/node/helpnode.h @@ -1,3 +1,22 @@ +/*************************************************************************** + * Copyright (C) 2015 by Renaud Guezennec * + * http://renaudguezennec.homelinux.org/accueil,3.html * + * * + * rolisteam is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ #ifndef HELPNODE_H #define HELPNODE_H #include "executionnode.h" diff --git a/node/keepdiceexecnode.cpp b/node/keepdiceexecnode.cpp index 7407d30..2ca54f4 100644 --- a/node/keepdiceexecnode.cpp +++ b/node/keepdiceexecnode.cpp @@ -42,10 +42,8 @@ m_previousNode = previous; if(NULL!=previousDiceResult) { QList<Die*> diceList=previousDiceResult->getResultList(); - QList<Die*> diceList2=m_diceResult->getResultList(); + QList<Die*> diceList2 = diceList.mid(0,m_numberOfDice); - - diceList2 = diceList.mid(0,m_numberOfDice); foreach(Die* tmp,diceList.mid(m_numberOfDice,-1)) { tmp->setHighlighted(false); diff --git a/node/listaliasnode.cpp b/node/listaliasnode.cpp index 7af202c..9ced186 100644 --- a/node/listaliasnode.cpp +++ b/node/listaliasnode.cpp @@ -29,6 +29,7 @@ void ListAliasNode::run(ExecutionNode* previous ) { m_previousNode = previous; StringResult* txtResult = dynamic_cast<StringResult*>(m_result); + txtResult->setHighLight(false); if(NULL != previous) { diff --git a/node/parenthesesnode.cpp b/node/parenthesesnode.cpp index d859632..f54a976 100644 --- a/node/parenthesesnode.cpp +++ b/node/parenthesesnode.cpp @@ -22,6 +22,7 @@ #include "parenthesesnode.h" ParenthesesNode::ParenthesesNode() + : m_internalNode(NULL) { } diff --git a/node/scalaroperatornode.cpp b/node/scalaroperatornode.cpp index 4bd2347..f69cb01 100644 --- a/node/scalaroperatornode.cpp +++ b/node/scalaroperatornode.cpp @@ -26,7 +26,7 @@ ScalarOperatorNode::ScalarOperatorNode() - : m_internalNode(NULL),m_scalarResult(new ScalarResult()) + : m_internalNode(NULL),m_scalarResult(new ScalarResult()),m_operator(PLUS) { m_scalarOperationList.insert('+',PLUS); m_scalarOperationList.insert('-',MINUS); diff --git a/node/sortresult.cpp b/node/sortresult.cpp index ffece63..d149507 100644 --- a/node/sortresult.cpp +++ b/node/sortresult.cpp @@ -54,14 +54,11 @@ void SortResultNode::run(ExecutionNode* node) bool found = false; int start = 0; int end = diceList2.size(); - int distance = 0; Die* tmp2 = NULL; while(!found) { - distance = end-start; + int distance = end-start; j = (start+end)/2; - - if(distance == 0) { j=end; @@ -78,9 +75,7 @@ void SortResultNode::run(ExecutionNode* node) { start=j+1; } - } - } diceList2.insert(j,tmp1); } diff --git a/node/startingnode.cpp b/node/startingnode.cpp index 42fba6f..5f1966e 100644 --- a/node/startingnode.cpp +++ b/node/startingnode.cpp @@ -1,3 +1,22 @@ +/*************************************************************************** + * Copyright (C) 2015 by Renaud Guezennec * + * http://renaudguezennec.homelinux.org/accueil,3.html * + * * + * rolisteam is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ #include "startingnode.h" #include <QDebug> @@ -33,7 +52,5 @@ qint64 StartingNode::getPriority() const { priority = m_nextNode->getPriority(); } - - return priority; } diff --git a/node/startingnode.h b/node/startingnode.h index e9bc5a5..923e84b 100644 --- a/node/startingnode.h +++ b/node/startingnode.h @@ -1,3 +1,22 @@ +/*************************************************************************** + * Copyright (C) 2015 by Renaud Guezennec * + * http://renaudguezennec.homelinux.org/accueil,3.html * + * * + * rolisteam is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ #ifndef STARTINGNODE_H #define STARTINGNODE_H @@ -31,3 +50,4 @@ public: }; #endif // STARTINGNODE_H + diff --git a/parsingtoolbox.cpp b/parsingtoolbox.cpp index 50b166a..00072c9 100644 --- a/parsingtoolbox.cpp +++ b/parsingtoolbox.cpp @@ -265,8 +265,6 @@ bool ParsingToolBox::readList(QString& str,QStringList& list,QList<Range>& range list = liststr.split(","); str=str.remove(0,pos+1); readProbability(list,ranges); - - return true; } } diff --git a/result/diceresult.cpp b/result/diceresult.cpp index 6c46de0..ceb77b8 100644 --- a/result/diceresult.cpp +++ b/result/diceresult.cpp @@ -54,7 +54,6 @@ QVariant DiceResult::getResult(RESULT_TYPE type) break; case DICE_LIST: { - return QVariant(); break; } diff --git a/result/stringresult.cpp b/result/stringresult.cpp index b7dc39d..2dff0ac 100644 --- a/result/stringresult.cpp +++ b/result/stringresult.cpp @@ -2,6 +2,7 @@ StringResult::StringResult() { + m_highlight = true; m_resultTypes = Result::STRING; } void StringResult::setText(QString text) @@ -42,3 +43,12 @@ QString StringResult::toString(bool wl) return m_id; } } +void StringResult::setHighLight(bool b) +{ + m_highlight = b; +} + +bool StringResult::hasHighLight() const +{ + return m_highlight; +} diff --git a/result/stringresult.h b/result/stringresult.h index 4f41431..cdd7de2 100644 --- a/result/stringresult.h +++ b/result/stringresult.h @@ -37,8 +37,12 @@ public: * @return */ virtual QString toString(bool); + + virtual void setHighLight(bool ); + virtual bool hasHighLight() const; private: QString m_value; + bool m_highlight; }; #endif // STRINGRESULT_H |