From 1c875b651df3afafe1df6b8ae412124d67e526a6 Mon Sep 17 00:00:00 2001 From: Renaud G Date: Thu, 5 Sep 2019 00:40:40 +0200 Subject: Copy die but prevent them to be displayed twice. --- diceparser.cpp | 28 +++++++++++++++------------- die.cpp | 14 +++++++++++++- die.h | 4 ++++ node/variablenode.cpp | 11 ++++++++++- 4 files changed, 42 insertions(+), 15 deletions(-) diff --git a/diceparser.cpp b/diceparser.cpp index ea8f251..702c47f 100644 --- a/diceparser.cpp +++ b/diceparser.cpp @@ -539,6 +539,7 @@ void DiceParser::getDiceResultFromAllInstruction(QList& resu void DiceParser::getLastDiceResult(QList& diceValuesList, bool& homogeneous) { + QStringList alreadySeenDice; for(auto start : m_startNodes) { ExportedDiceResult diceValues; @@ -559,23 +560,24 @@ void DiceParser::getLastDiceResult(QList& diceValuesList, bo ListDiceResult listpair; for(auto& die : diceResult->getResultList()) { - if(!die->hasBeenDisplayed()) + if(die->hasBeenDisplayed() || alreadySeenDice.contains(die->getUuid())) + continue; + + QList valuesResult; + valuesResult.append(die->getValue()); + die->displayed(); + face= die->getFaces(); + if(die->hasChildrenValue()) { - QList valuesResult; - valuesResult.append(die->getValue()); - die->displayed(); - face= die->getFaces(); - if(die->hasChildrenValue()) + for(qint64& i : die->getListValue()) { - for(qint64& i : die->getListValue()) - { - valuesResult.append(i); - } + valuesResult.append(i); } - HighLightDice hlDice(valuesResult, die->isHighlighted(), die->getColor(), - die->hasBeenDisplayed(), 0); - listpair.append(hlDice); } + HighLightDice hlDice(valuesResult, die->isHighlighted(), die->getColor(), + die->hasBeenDisplayed(), 0); + listpair.append(hlDice); + alreadySeenDice << die->getUuid(); } if(!listpair.isEmpty()) { diff --git a/die.cpp b/die.cpp index 531853c..884472d 100644 --- a/die.cpp +++ b/die.cpp @@ -24,10 +24,12 @@ #include #include +#include #include Die::Die() - : m_hasValue(false) + : m_uuid(QUuid::createUuid().toString(QUuid::WithoutBraces)) + , m_hasValue(false) , m_displayStatus(false) , m_highlighted(true) , m_base(1) @@ -43,6 +45,7 @@ Die::Die(const Die& die) m_rollResult= die.m_rollResult; m_selected= die.m_selected; m_hasValue= die.m_hasValue; + m_uuid= die.m_uuid; m_displayStatus= die.m_displayStatus; m_maxValue= die.m_maxValue; m_highlighted= die.m_highlighted; @@ -226,3 +229,12 @@ void Die::setOp(const Die::ArithmeticOperator& op) { m_op= op; } +QString Die::getUuid() const +{ + return m_uuid; +} + +void Die::setUuid(const QString& uuid) +{ + m_uuid= uuid; +} diff --git a/die.h b/die.h index eb43521..52ba7a2 100644 --- a/die.h +++ b/die.h @@ -144,7 +144,11 @@ public: void setOp(const Die::ArithmeticOperator& op); void setDisplayed(bool b); + QString getUuid() const; + void setUuid(const QString& uuid); + private: + QString m_uuid; qint64 m_value= 0; QList m_rollResult; bool m_selected= false; diff --git a/node/variablenode.cpp b/node/variablenode.cpp index e45214d..0f5a0b0 100644 --- a/node/variablenode.cpp +++ b/node/variablenode.cpp @@ -14,7 +14,16 @@ void VariableNode::run(ExecutionNode* previous) auto result= value->getResult(); if(result) { - m_result= result->getCopy(); + auto copy= result->getCopy(); + auto diceResult= dynamic_cast(result); + if(nullptr != diceResult) + { + for(auto& die : diceResult->getResultList()) + { + die->setDisplayed(false); + } + } + m_result= copy; if(nullptr != m_nextNode) { m_nextNode->run(this); -- cgit v1.2.3-70-g09d2