From fd5728eb399e10514afd0bb55b73d504d50b7517 Mon Sep 17 00:00:00 2001 From: obiwankennedy Date: Mon, 23 Apr 2018 13:41:46 +0200 Subject: reroll dice with replacement by expression --- node/rerolldicenode.cpp | 12 +++++++++++- result/diceresult.cpp | 5 +++++ result/diceresult.h | 2 ++ result/result.cpp | 5 ++++- result/result.h | 2 ++ 5 files changed, 24 insertions(+), 2 deletions(-) diff --git a/node/rerolldicenode.cpp b/node/rerolldicenode.cpp index f51eb9e..a24ffa9 100644 --- a/node/rerolldicenode.cpp +++ b/node/rerolldicenode.cpp @@ -33,9 +33,11 @@ void RerollDiceNode::run(ExecutionNode* previous) //m_diceResult->setResultList(list); QList& list = m_diceResult->getResultList(); + QList toRemove; - for(Die* die: list) + for(int i = 0; i < list.size() ; ++i) { + auto die = list.at(i); if(m_validator->hasValid(die,false)) { if(m_instruction != nullptr) @@ -47,8 +49,10 @@ void RerollDiceNode::run(ExecutionNode* previous) auto lastResult = dynamic_cast(lastNode->getResult()); if(lastResult != nullptr) { + toRemove.append(die); list.append(lastResult->getResultList()); } + lastResult->clear(); } } else @@ -58,6 +62,12 @@ void RerollDiceNode::run(ExecutionNode* previous) } } + for(auto die: toRemove) + { + list.removeOne(die); + } + + if(nullptr!=m_nextNode) { m_nextNode->run(this); diff --git a/result/diceresult.cpp b/result/diceresult.cpp index b8ed8d5..ce59cb1 100644 --- a/result/diceresult.cpp +++ b/result/diceresult.cpp @@ -143,6 +143,11 @@ Die::ArithmeticOperator DiceResult::getOperator() const return m_operator; } +void DiceResult::clear() +{ + m_diceValues.clear(); +} + void DiceResult::setOperator(const Die::ArithmeticOperator& dieOperator) { m_operator = dieOperator; diff --git a/result/diceresult.h b/result/diceresult.h index 3dac826..8ff041f 100644 --- a/result/diceresult.h +++ b/result/diceresult.h @@ -79,6 +79,8 @@ public: void setOperator(const Die::ArithmeticOperator & dieOperator); bool contains(Die *die, const std::function equal); + void clear(); + virtual Result* getCopy() const; private: qreal getScalarResult(); diff --git a/result/result.cpp b/result/result.cpp index f79e004..8b4667b 100644 --- a/result/result.cpp +++ b/result/result.cpp @@ -45,7 +45,10 @@ bool Result::isStringResult() const { return false; } - +void Result::clear() +{ + +} bool Result::hasResultOfType(RESULT_TYPE type) const { return (m_resultTypes & type); diff --git a/result/result.h b/result/result.h index 5de3572..5fc4408 100644 --- a/result/result.h +++ b/result/result.h @@ -69,6 +69,8 @@ public: */ virtual bool isStringResult() const; + virtual void clear(); + /** * @brief getStringResult * @return -- cgit v1.2.3-70-g09d2