aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/diceparser.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'diceparser.cpp')
-rw-r--r--diceparser.cpp67
1 files changed, 39 insertions, 28 deletions
diff --git a/diceparser.cpp b/diceparser.cpp
index 5d4a610..f4370f6 100644
--- a/diceparser.cpp
+++ b/diceparser.cpp
@@ -34,6 +34,7 @@
#include "node/rerolldicenode.h"
#include "node/explosedicenode.h"
#include "node/parenthesesnode.h"
+#include "node/helpnode.h"
#define DEFAULT_FACES_NUMBER 10
@@ -64,6 +65,7 @@ DiceParser::DiceParser()
m_commandList = new QList<QString>();
m_commandList->append("help");
+
}
ExecutionNode* DiceParser::getLatestNode(ExecutionNode* node)
@@ -148,6 +150,7 @@ bool DiceParser::readExpression(QString& str,ExecutionNode* & node)
}
else if(readCommand(str,operandNode))
{
+ node = operandNode;
return true;
}
else
@@ -202,48 +205,55 @@ QString DiceParser::displayResult()
while(NULL!=myResult)
{
++resulCount;
- if((myResult->isScalar())&&(!scalarDone))
+ if((myResult->hasResultOfType(Result::SCALAR))&&(!scalarDone))
{
- stream << totalValue.arg(myResult->getScalar()) << endl; //.arg(m_command)
+ stream << totalValue.arg(myResult->getResult(Result::SCALAR).toReal()) << endl; //.arg(m_command)
scalarDone=true;
}
-
- DiceResult* myDiceResult = dynamic_cast<DiceResult*>(myResult);
- if(NULL!=myDiceResult)
+ else if(myResult->hasResultOfType(Result::DICE_LIST))
{
- QString resulStr;
- quint64 face=0;
- foreach(Die* die, myDiceResult->getResultList())
+ DiceResult* myDiceResult = dynamic_cast<DiceResult*>(myResult);
+ if(NULL!=myDiceResult)
{
- if(!die->hasBeenDisplayed())
+
+ QString resulStr;
+ quint64 face=0;
+ foreach(Die* die, myDiceResult->getResultList())
{
- resulStr+=QString("%1").arg(die->getValue());
- die->displayed();
- face = die->getFaces();
+ if(!die->hasBeenDisplayed())
+ {
+ resulStr+=QString("%1").arg(die->getValue());
+ die->displayed();
+ face = die->getFaces();
- if(die->hasChildrenValue())
- {
- resulStr+=" [";
- foreach(qint64 i, die->getListValue())
+ if(die->hasChildrenValue())
{
-
- resulStr+=QString("%1 ").arg(i);
+ resulStr+=" [";
+ foreach(qint64 i, die->getListValue())
+ {
+
+ resulStr+=QString("%1 ").arg(i);
+ }
+ resulStr.remove(resulStr.size()-1,1);
+ resulStr+="]";
}
- resulStr.remove(resulStr.size()-1,1);
- resulStr+="]";
+ resulStr+=", ";
}
- resulStr+=", ";
}
- }
- resulStr.remove(resulStr.size()-2,2);
+ resulStr.remove(resulStr.size()-2,2);
- if(!resulStr.isEmpty())
- {
- stream << dieValue.arg(face).arg(resulStr);
- }
+ if(!resulStr.isEmpty())
+ {
+ stream << dieValue.arg(face).arg(resulStr);
+ }
+ }
+ }
+ else if(myResult->hasResultOfType(Result::STRING))
+ {
+ stream << myResult->getResult(Result::STRING).toString();
}
myResult = myResult->getPrevious();
@@ -306,7 +316,8 @@ bool DiceParser::readCommand(QString& str,ExecutionNode* & node)
{
if(m_commandList->contains(str))
{
- // node = new HelpNode();
+ node = new HelpNode();
+ return true;
}
}