From e66b5fac468c30498d85148554d76bbd221df9c5 Mon Sep 17 00:00:00 2001 From: Renaud G Date: Fri, 15 May 2015 14:46:15 +0200 Subject: display number as signed --- cli/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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) -- cgit v1.2.3-70-g09d2 From 5acbf79338f01857f4d646727cd5f819c6de2183 Mon Sep 17 00:00:00 2001 From: Renaud G Date: Fri, 15 May 2015 14:47:28 +0200 Subject: add management for dice between range --- diceparser.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) 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; } } -- cgit v1.2.3-70-g09d2 From 74b931cd4dd5af57ee7e34948a92dad62733d722 Mon Sep 17 00:00:00 2001 From: Renaud G Date: Fri, 15 May 2015 14:48:30 +0200 Subject: add management of base, the minimum value of die --- die.cpp | 9 +++++++-- die.h | 6 ++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/die.cpp b/die.cpp index 28be07c..1b4b246 100644 --- a/die.cpp +++ b/die.cpp @@ -26,7 +26,7 @@ #include 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; +} diff --git a/die.h b/die.h index 6b640b7..2c10894 100644 --- a/die.h +++ b/die.h @@ -119,6 +119,11 @@ public: */ bool isHighlighted(); + /** + * @brief setBase + */ + void setBase(qint64); + private: qint64 m_value; QList m_rollResult; @@ -127,6 +132,7 @@ private: bool m_displayStatus; bool m_highlighted; quint64 m_faces; + qint64 m_base; }; -- cgit v1.2.3-70-g09d2 From 03cae353e4a070391850118b5c7e2b5ce4c8828f Mon Sep 17 00:00:00 2001 From: Renaud G Date: Fri, 15 May 2015 14:48:45 +0200 Subject: add management of base, the minimum value of die --- node/dicerollernode.cpp | 5 +++-- node/dicerollernode.h | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) 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 -- cgit v1.2.3-70-g09d2 From f8a2e958e699ca41730cb785e7284c07eaaa5a82 Mon Sep 17 00:00:00 2001 From: Renaud G Date: Fri, 15 May 2015 14:49:49 +0200 Subject: add method to read dice range (a bit different from validator range) --- parsingtoolbox.cpp | 43 ++++++++++++++++++++++++++++++++++++++++++- parsingtoolbox.h | 9 +++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) 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(igetPreviousNode(); } } +bool ParsingToolBox::readDiceRange(QString& str,int& start, int& end) +{ + bool expectSquareBrasket=false; + + qDebug()<<"readDiceRange"<* m_logicOp; }; -- cgit v1.2.3-70-g09d2