aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorRenaud G <renaud@rolisteam.org>2019-07-19 02:01:06 +0200
committerRenaud G <renaud@rolisteam.org>2019-07-19 02:01:06 +0200
commit63edd55e030475bd4abe1f39967cacf6e5adf892 (patch)
tree3857f7e75b5dc60c0b9b6e26504584a893468ce2
parent504d91db102a840e461b8b2ba442c0f76d581742 (diff)
downloadOneRoll-63edd55e030475bd4abe1f39967cacf6e5adf892.tar.gz
OneRoll-63edd55e030475bd4abe1f39967cacf6e5adf892.zip
fix if behaviour and output
-rw-r--r--diceparser.cpp21
-rw-r--r--die.cpp5
-rw-r--r--die.h1
-rw-r--r--node/ifnode.cpp42
-rw-r--r--result/diceresult.cpp3
5 files changed, 42 insertions, 30 deletions
diff --git a/diceparser.cpp b/diceparser.cpp
index 75247ba..4ec44ef 100644
--- a/diceparser.cpp
+++ b/diceparser.cpp
@@ -48,7 +48,6 @@
#include "node/sortresult.h"
#include "node/splitnode.h"
#include "node/startingnode.h"
-#include "node/stringnode.h"
#include "node/uniquenode.h"
#include "node/valueslistnode.h"
#include "node/variablenode.h"
@@ -232,6 +231,11 @@ bool DiceParser::readExpression(QString& str, ExecutionNode*& node)
}
}
}
+ else if(readOptionFromNull(str, operandNode))
+ {
+ node= operandNode;
+ return true;
+ }
else if(readOperatorFromNull(str, operandNode))
{
node= operandNode;
@@ -265,11 +269,6 @@ bool DiceParser::readExpression(QString& str, ExecutionNode*& node)
node= operandNode;
return true;
}
- else if(readOptionFromNull(str, operandNode))
- {
- node= operandNode;
- return true;
- }
else if(readValuesList(str, operandNode))
{
node= operandNode;
@@ -385,6 +384,7 @@ void DiceParser::start()
QList<qreal> DiceParser::getLastIntegerResults()
{
QList<qreal> resultValues;
+ QStringList alreadyVisitedNode;
for(auto node : m_startNodes)
{
ExecutionNode* next= getLeafNode(node);
@@ -394,7 +394,11 @@ QList<qreal> DiceParser::getLastIntegerResults()
{
if(result->hasResultOfType(Result::SCALAR))
{
- resultValues << result->getResult(Result::SCALAR).toReal();
+ if(!alreadyVisitedNode.contains(result->getId()))
+ {
+ resultValues << result->getResult(Result::SCALAR).toReal();
+ alreadyVisitedNode << result->getId();
+ }
scalarDone= true;
}
result= result->getPrevious();
@@ -420,7 +424,8 @@ QStringList DiceParser::getStringResult()
}
result= result->getPrevious();
}
- stringListResult << str;
+ if(!str.isEmpty())
+ stringListResult << str;
}
return stringListResult;
}
diff --git a/die.cpp b/die.cpp
index 3d372c8..2d2ff91 100644
--- a/die.cpp
+++ b/die.cpp
@@ -174,7 +174,10 @@ void Die::displayed()
{
m_displayStatus= true;
}
-
+void Die::setDisplayed(bool b)
+{
+ m_displayStatus= b;
+}
void Die::setHighlighted(bool a)
{
m_highlighted= a;
diff --git a/die.h b/die.h
index 9f50120..f544808 100644
--- a/die.h
+++ b/die.h
@@ -142,6 +142,7 @@ public:
Die::ArithmeticOperator getOp() const;
void setOp(const Die::ArithmeticOperator& op);
+ void setDisplayed(bool b);
private:
qint64 m_value= 0;
diff --git a/node/ifnode.cpp b/node/ifnode.cpp
index fbcd9b9..5470e15 100644
--- a/node/ifnode.cpp
+++ b/node/ifnode.cpp
@@ -133,30 +133,30 @@ void IfNode::run(ExecutionNode* previous)
}
}
}
- }
-
- if(m_conditionType == OnScalar)
- {
- Die* dice= new Die();
- dice->setValue(value);
- dice->insertRollValue(value);
- dice->setMaxValue(value);
- if(m_validator->hasValid(dice, true, true))
- {
- nextNode= m_true;
- }
- else
- {
- nextNode= m_false;
- }
- if(nullptr != nextNode)
+ if(m_conditionType == OnScalar)
{
- if(nullptr == m_nextNode)
+ Die dice;
+ auto val= static_cast<qint64>(value);
+ dice.setValue(val);
+ dice.insertRollValue(val);
+ dice.setMaxValue(val);
+ if(m_validator->hasValid(&dice, true, true))
{
- m_nextNode= nextNode;
+ nextNode= m_true;
+ }
+ else
+ {
+ nextNode= m_false;
+ }
+ if(nullptr != nextNode)
+ {
+ if(nullptr == m_nextNode)
+ {
+ m_nextNode= nextNode;
+ }
+ nextNode->run(previousLoop);
+ previousLoop= getLeafNode(nextNode);
}
- nextNode->run(previousLoop);
- previousLoop= getLeafNode(nextNode);
}
}
}
diff --git a/result/diceresult.cpp b/result/diceresult.cpp
index 76e473b..e66fc4f 100644
--- a/result/diceresult.cpp
+++ b/result/diceresult.cpp
@@ -178,13 +178,16 @@ Result* DiceResult::getCopy() const
auto copy= new DiceResult();
copy->setHomogeneous(m_homogeneous);
copy->setOperator(m_operator);
+ copy->m_id= m_id;
QList<Die*> list;
for(auto die : m_diceValues)
{
auto newdie= new Die(*die);
+ newdie->setDisplayed(false);
die->displayed();
list.append(newdie);
}
copy->setResultList(list);
+ copy->setPrevious(getPrevious());
return copy;
}