diff options
| author | 2015-05-16 00:05:08 +0200 | |
|---|---|---|
| committer | 2015-05-16 00:05:08 +0200 | |
| commit | bb89b91d9919ad9fed8b9d30ea0df79ceea4d3f7 (patch) | |
| tree | 090223d5ab28601d52c63bb9489835f191cf797a | |
| parent | b79df1fffd6677a584d6ad8ed44004aae0dad7b4 (diff) | |
| parent | f8a2e958e699ca41730cb785e7284c07eaaa5a82 (diff) | |
| download | OneRoll-bb89b91d9919ad9fed8b9d30ea0df79ceea4d3f7.tar.gz OneRoll-bb89b91d9919ad9fed8b9d30ea0df79ceea4d3f7.zip | |
Merge branch 'master' of github.com:obiwankennedy/DiceParser
| -rw-r--r-- | cli/main.cpp | 2 | ||||
| -rw-r--r-- | diceparser.cpp | 16 | ||||
| -rw-r--r-- | die.cpp | 9 | ||||
| -rw-r--r-- | die.h | 6 | ||||
| -rw-r--r-- | node/dicerollernode.cpp | 5 | ||||
| -rw-r--r-- | node/dicerollernode.h | 3 | ||||
| -rw-r--r-- | parsingtoolbox.cpp | 43 | ||||
| -rw-r--r-- | parsingtoolbox.h | 9 |
8 files changed, 84 insertions, 9 deletions
diff --git a/cli/main.cpp b/cli/main.cpp index f005cc3..f6197ce 100644 --- a/cli/main.cpp +++ b/cli/main.cpp @@ -59,7 +59,7 @@ QString diceToText(ExportedDiceResult& dice) for(int i =0; i < tmp.first.size(); ++i) { - quint64 dievalue = tmp.first[i]; + qint64 dievalue = tmp.first[i]; QString prefix("%1"); if(tmp.second) diff --git a/diceparser.cpp b/diceparser.cpp index 1046ade..f6cb59a 100644 --- a/diceparser.cpp +++ b/diceparser.cpp @@ -519,6 +519,7 @@ bool DiceParser::readDice(QString& str,ExecutionNode* & node) if(readDiceOperator(str,currentOperator)) { int num; + int end; if(currentOperator==D) { if(m_parsingToolbox->readNumber(str,num)) @@ -528,7 +529,6 @@ bool DiceParser::readDice(QString& str,ExecutionNode* & node) m_errorMap.insert(ExecutionNode::BAD_SYNTAXE,QObject::tr("Dice with %1 face(s) does not exist. Please, put a value higher than 0").arg(num)); return false; } - qDebug() << num; DiceRollerNode* drNode = new DiceRollerNode(num); node = drNode; ExecutionNode* current = drNode; @@ -536,8 +536,20 @@ bool DiceParser::readDice(QString& str,ExecutionNode* & node) { current = getLatestNode(current); } + return true; + } + else if(m_parsingToolbox->readDiceRange(str,num,end)) + { - + int face = abs(num - end)+1; + qDebug()<< num << end<< face; + DiceRollerNode* drNode = new DiceRollerNode(face,num); + node = drNode; + ExecutionNode* current = drNode; + while(readOption(str,current)) + { + current = getLatestNode(current); + } return true; } } @@ -26,7 +26,7 @@ #include <QDebug> Die::Die() - : m_hasValue(false),m_displayStatus(false),m_highlighted(true) + : m_hasValue(false),m_displayStatus(false),m_highlighted(true),m_base(1) { uint seed = quintptr(this) + QDateTime::currentDateTime().toMSecsSinceEpoch(); qsrand(seed); @@ -42,6 +42,7 @@ Die::Die(const Die& die) m_displayStatus = die.m_displayStatus; m_faces = die.m_faces; m_highlighted = die.m_highlighted; + m_base = die.m_base; } void Die::setValue(qint64 r) @@ -97,7 +98,7 @@ void Die::roll(bool adding) { if(m_faces!=0) { - quint64 value=(qrand()%m_faces)+1; + quint64 value=(qrand()%m_faces)+m_base; if((adding)||(m_rollResult.isEmpty())) { insertRollValue(value); @@ -144,3 +145,7 @@ bool Die::isHighlighted() { return m_highlighted; } +void Die::setBase(qint64 base) +{ + m_base = base; +} @@ -119,6 +119,11 @@ public: */ bool isHighlighted(); + /** + * @brief setBase + */ + void setBase(qint64); + private: qint64 m_value; QList<qint64> m_rollResult; @@ -127,6 +132,7 @@ private: bool m_displayStatus; bool m_highlighted; quint64 m_faces; + qint64 m_base; }; diff --git a/node/dicerollernode.cpp b/node/dicerollernode.cpp index f32a033..06148fc 100644 --- a/node/dicerollernode.cpp +++ b/node/dicerollernode.cpp @@ -32,8 +32,8 @@ ////////////////////////////////////////////////// /// \brief DiceRollerNode::DiceRollerNode ////////////////////////////////////////////////// -DiceRollerNode::DiceRollerNode(quint64 faces) - : m_faces(faces),m_diceResult(new DiceResult()) +DiceRollerNode::DiceRollerNode(quint64 faces,qint64 offset) + : m_faces(faces),m_diceResult(new DiceResult()),m_offset(offset) { m_result=m_diceResult; } @@ -52,6 +52,7 @@ void DiceRollerNode::run(ExecutionNode* previous) { Die* die = new Die(); die->setFaces(m_faces); + die->setBase(m_offset); die->roll(); m_diceResult->insertResult(die); } diff --git a/node/dicerollernode.h b/node/dicerollernode.h index 744a4b5..726676e 100644 --- a/node/dicerollernode.h +++ b/node/dicerollernode.h @@ -25,7 +25,7 @@ class DiceRollerNode : public ExecutionNode { public: - DiceRollerNode(quint64 faces); + DiceRollerNode(quint64 faces, qint64 offset = 1); virtual void run(ExecutionNode*); quint64 getFaces(); @@ -37,6 +37,7 @@ private: quint64 m_diceCount; quint64 m_faces; /// faces DiceResult* m_diceResult; + qint64 m_offset; }; #endif // DICEROLLERNODE_H diff --git a/parsingtoolbox.cpp b/parsingtoolbox.cpp index 3e09bac..0052f07 100644 --- a/parsingtoolbox.cpp +++ b/parsingtoolbox.cpp @@ -141,7 +141,7 @@ bool ParsingToolBox::readNumber(QString& str, int& myNumber) QString number; int i=0; - while(i<str.length() && str[i].isNumber()) + while(i<str.length() && ((str[i].isNumber()) || ( (i==0) && (str[i]=='-')))) { number+=str[i]; ++i; @@ -234,3 +234,44 @@ DiceRollerNode* ParsingToolBox::getDiceRollerNode(ExecutionNode* previous) previous = previous->getPreviousNode(); } } +bool ParsingToolBox::readDiceRange(QString& str,int& start, int& end) +{ + bool expectSquareBrasket=false; + + qDebug()<<"readDiceRange"<<str; + if((str.startsWith("["))) + { + str=str.remove(0,1); + expectSquareBrasket = true; + } +qDebug()<<"readDiceRange"<<str; + if(readNumber(str,start)) + { + qDebug()<<"readDiceRange"<<str; + if(str.startsWith("-")) + { + str=str.remove(0,1); + if(readNumber(str,end)) + { + if(expectSquareBrasket) + { + if(str.startsWith("]")) + { + str=str.remove(0,1); + return true; + } + else + { + return false; + } + } + } + else + { + return false; + } + qDebug()<<"readDiceRange"<<str; + } + } + +} diff --git a/parsingtoolbox.h b/parsingtoolbox.h index 8958550..5d38919 100644 --- a/parsingtoolbox.h +++ b/parsingtoolbox.h @@ -115,6 +115,15 @@ public: */ DiceRollerNode* getDiceRollerNode(ExecutionNode* previous); + /** + * @brief readDiceRange + * @param str + * @param start + * @param end + * @return + */ + bool readDiceRange(QString& str,int& start, int& end); + private: QMap<QString,BooleanCondition::LogicOperator>* m_logicOp; }; |