aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--cli/main.cpp2
-rw-r--r--diceparser.cpp16
-rw-r--r--die.cpp9
-rw-r--r--die.h6
-rw-r--r--node/dicerollernode.cpp5
-rw-r--r--node/dicerollernode.h3
-rw-r--r--parsingtoolbox.cpp43
-rw-r--r--parsingtoolbox.h9
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;
}
}
diff --git a/die.cpp b/die.cpp
index 28be07c..1b4b246 100644
--- a/die.cpp
+++ b/die.cpp
@@ -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;
+}
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<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;
};