aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--diceparser.cpp22
-rw-r--r--die.cpp18
-rw-r--r--node/explosedicenode.cpp2
-rw-r--r--node/helpnode.cpp2
-rw-r--r--node/keepdiceexecnode.cpp2
-rw-r--r--node/listaliasnode.cpp13
-rw-r--r--node/listaliasnode.h7
-rw-r--r--node/listsetrollnode.cpp2
-rw-r--r--node/numbernode.cpp2
-rw-r--r--node/rerolldicenode.cpp2
-rw-r--r--node/scalaroperatornode.cpp21
-rw-r--r--node/sortresult.cpp2
-rw-r--r--node/startingnode.cpp2
13 files changed, 66 insertions, 31 deletions
diff --git a/diceparser.cpp b/diceparser.cpp
index ebe2e0e..1046ade 100644
--- a/diceparser.cpp
+++ b/diceparser.cpp
@@ -70,10 +70,9 @@ DiceParser::DiceParser()
m_nodeActionMap = new QMap<QString,NodeAction>();
m_nodeActionMap->insert("@",JumpBackward);
-
- m_commandList = new QStringList();
- m_commandList->append(QObject::tr("help"));
- m_commandList->append(QObject::tr("la"));
+ m_commandList = new QStringList();
+ m_commandList->append("help");
+ m_commandList->append("la");
}
DiceParser::~DiceParser()
@@ -152,12 +151,12 @@ bool DiceParser::parseLine(QString str)
delete m_start;
m_start = NULL;
}
- m_command = str;
m_start = new StartingNode();
ExecutionNode* newNode = NULL;
m_current = m_start;
str = convertAlias(str);
+ m_command = str;
bool keepParsing = readExpression(str,newNode);
if(keepParsing)
@@ -203,11 +202,8 @@ bool DiceParser::readExpression(QString& str,ExecutionNode* & node)
{
parentheseNode->setNextNode(diceNode);
}
-
return true;
}
-
-
}
}
else if(readOperand(str,operandNode))
@@ -527,9 +523,13 @@ bool DiceParser::readDice(QString& str,ExecutionNode* & node)
{
if(m_parsingToolbox->readNumber(str,num))
{
+ if(num<1)
+ {
+ 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);
- // dice.m_diceOp = myOperator;
- // dice.m_faces = num;
node = drNode;
ExecutionNode* current = drNode;
while(readOption(str,current))
@@ -553,7 +553,7 @@ bool DiceParser::readDice(QString& str,ExecutionNode* & node)
}
else
{
- m_errorMap.insert(ExecutionNode::BAD_SYNTAXE,QObject::tr("List is missing after the L operator. Please, add it (e.g : 1L[sword,spear,gun,arrow]"));
+ m_errorMap.insert(ExecutionNode::BAD_SYNTAXE,QObject::tr("List is missing after the L operator. Please, add it (e.g : 1L[sword,spear,gun,arrow])"));
}
}
diff --git a/die.cpp b/die.cpp
index 4782705..28be07c 100644
--- a/die.cpp
+++ b/die.cpp
@@ -95,15 +95,17 @@ void Die::replaceLastValue(qint64 value)
void Die::roll(bool adding)
{
- quint64 value=(qrand()%m_faces)+1;
-
- if((adding)||(m_rollResult.isEmpty()))
- {
- insertRollValue(value);
- }
- else
+ if(m_faces!=0)
{
- replaceLastValue(value);
+ quint64 value=(qrand()%m_faces)+1;
+ if((adding)||(m_rollResult.isEmpty()))
+ {
+ insertRollValue(value);
+ }
+ else
+ {
+ replaceLastValue(value);
+ }
}
}
diff --git a/node/explosedicenode.cpp b/node/explosedicenode.cpp
index 4eae270..c0ebfe7 100644
--- a/node/explosedicenode.cpp
+++ b/node/explosedicenode.cpp
@@ -46,7 +46,7 @@ void ExploseDiceNode::setValidator(Validator* val)
}
QString ExploseDiceNode::toString() const
{
- return QString("ExploseDiceNode");
+ return QString("ExploseDiceNode [label=\"ExploseDiceNode %1\"]").arg(m_validator->toString());
}
qint64 ExploseDiceNode::getPriority() const
{
diff --git a/node/helpnode.cpp b/node/helpnode.cpp
index ffe5f55..d41464b 100644
--- a/node/helpnode.cpp
+++ b/node/helpnode.cpp
@@ -28,7 +28,7 @@ void HelpNode::run(ExecutionNode* previous)
m_nextNode->run(this);
}
}
-QString HelpNode::toString()const
+QString HelpNode::toString() const
{
return QObject::tr("Rolisteam Dice Parser:\nFull documentation at: https://github.com/obiwankennedy/DiceParser/blob/master/HelpMe.md \n");
}
diff --git a/node/keepdiceexecnode.cpp b/node/keepdiceexecnode.cpp
index 859f733..a225ac4 100644
--- a/node/keepdiceexecnode.cpp
+++ b/node/keepdiceexecnode.cpp
@@ -64,7 +64,7 @@ void KeepDiceExecNode::setDiceKeepNumber(quint64 n)
}
QString KeepDiceExecNode::toString() const
{
- return QString("KeepDiceExecNode");
+ return QString("KeepDiceExecNode [label=\"KeepDiceExecNode %1\"]").arg(m_numberOfDice);
}
qint64 KeepDiceExecNode::getPriority() const
{
diff --git a/node/listaliasnode.cpp b/node/listaliasnode.cpp
index 4fd4ab0..ddb8ac9 100644
--- a/node/listaliasnode.cpp
+++ b/node/listaliasnode.cpp
@@ -34,7 +34,7 @@ void ListAliasNode::run(ExecutionNode* previous )
{
if(previous->getResult() == NULL)
{
- txtResult->setText(toString());
+ txtResult->setText(buildList());
}
else
@@ -49,7 +49,7 @@ void ListAliasNode::run(ExecutionNode* previous )
m_nextNode->run(this);
}
}
-QString ListAliasNode::toString() const
+QString ListAliasNode::buildList() const
{
QString result(QObject::tr("List of Alias:\n"));
foreach(DiceAlias* key, *m_aliasList)
@@ -58,7 +58,16 @@ QString ListAliasNode::toString() const
}
return result;
}
+QString ListAliasNode::toString() const
+{
+ QStringList resultList;
+ foreach(DiceAlias* key, *m_aliasList)
+ {
+ resultList << "{" <<key->getCommand() << key->getValue()<< "}";
+ }
+ return QString("ListAliasNode [label=\"ListAliasNode %1\"]").arg(resultList.join(","));
+}
qint64 ListAliasNode::getPriority() const
{
return 0;
diff --git a/node/listaliasnode.h b/node/listaliasnode.h
index e08d073..e8f8b0f 100644
--- a/node/listaliasnode.h
+++ b/node/listaliasnode.h
@@ -42,7 +42,12 @@ public:
* @brief toString
* @return
*/
- virtual QString toString()const;
+ virtual QString toString() const;
+ /**
+ * @brief buildList
+ * @return
+ */
+ virtual QString buildList() const;
/**
* @brief getPriority
* @return
diff --git a/node/listsetrollnode.cpp b/node/listsetrollnode.cpp
index 6512df5..fdc17a5 100644
--- a/node/listsetrollnode.cpp
+++ b/node/listsetrollnode.cpp
@@ -41,7 +41,7 @@ QStringList ListSetRollNode::getList()
}
QString ListSetRollNode::toString() const
{
- return QString("ListSetRollNode_").arg(m_values.join(','));
+ return QString("ListSetRollNode [label=\"ListSetRoll list:%1\"]").arg(m_values.join(','));
}
qint64 ListSetRollNode::getPriority() const
{
diff --git a/node/numbernode.cpp b/node/numbernode.cpp
index ba063db..c63aadf 100644
--- a/node/numbernode.cpp
+++ b/node/numbernode.cpp
@@ -46,7 +46,7 @@ void NumberNode::setNumber(qint64 a)
}
QString NumberNode::toString() const
{
- return QString("NumberNode_%1").arg(m_number);
+ return QString("NumberNode [label=\"NumberNode %1\"]").arg(m_number);
}
qint64 NumberNode::getPriority() const
{
diff --git a/node/rerolldicenode.cpp b/node/rerolldicenode.cpp
index a7cc8c4..038a3ec 100644
--- a/node/rerolldicenode.cpp
+++ b/node/rerolldicenode.cpp
@@ -48,7 +48,7 @@ void RerollDiceNode::setValidator(Validator* val)
}
QString RerollDiceNode::toString() const
{
- return "RerollDiceNode";
+ return QString("RerollDiceNode [label=\"RerollDiceNode validatior:%1\"").arg(m_validator->toString());
}
void RerollDiceNode::setAddingMode(bool b)
{
diff --git a/node/scalaroperatornode.cpp b/node/scalaroperatornode.cpp
index b7c183f..c5f91f9 100644
--- a/node/scalaroperatornode.cpp
+++ b/node/scalaroperatornode.cpp
@@ -140,7 +140,26 @@ qint64 ScalarOperatorNode::multiple(qint64 a,qint64 b)
}
QString ScalarOperatorNode::toString() const
{
- return "ScalarOperatorNode";
+ QString op="";
+ switch(m_operator)
+ {
+ case PLUS:
+ op="+";
+ break;
+ case MINUS:
+ op="-";
+ break;
+ case MULTIPLICATION:
+ op="*";
+ break;
+ case DIVIDE:
+ op="/";
+ break;
+ default:
+ break;
+
+ }
+ return QString("ScalarOperatorNode [label=\"ScalarOperatorNode %1\"").arg(op);
}
qint64 ScalarOperatorNode::getPriority() const
{
diff --git a/node/sortresult.cpp b/node/sortresult.cpp
index b3e6b49..44a25f0 100644
--- a/node/sortresult.cpp
+++ b/node/sortresult.cpp
@@ -112,7 +112,7 @@ void SortResultNode::setSortAscending(bool asc)
}
QString SortResultNode::toString() const
{
- return "SortResultNode";
+ return QString("SortResultNode [label=\"SortResultNode %1\"").arg(m_ascending ? "Ascending":"Descending");
}
qint64 SortResultNode::getPriority() const
{
diff --git a/node/startingnode.cpp b/node/startingnode.cpp
index 48ac4a4..b15101b 100644
--- a/node/startingnode.cpp
+++ b/node/startingnode.cpp
@@ -15,7 +15,7 @@ void StartingNode::run(ExecutionNode*)
}
QString StartingNode::toString() const
{
- return "StartingNode";
+ return "StartingNode [shape=box]";
}
qint64 StartingNode::getPriority() const
{