diff options
| author | 2018-10-12 00:25:06 +0200 | |
|---|---|---|
| committer | 2021-05-12 02:04:44 +0200 | |
| commit | 4fd5a0988bef5c6c5d4ca96967d7d3a176f4c410 (patch) | |
| tree | bd14e056adca27df8392367a4731157a2c8e68b1 /node/keepdiceexecnode.cpp | |
| parent | 97235bf4e5e8a3502172e434c698562afd87d6b3 (diff) | |
| download | OneRoll-4fd5a0988bef5c6c5d4ca96967d7d3a176f4c410.tar.gz OneRoll-4fd5a0988bef5c6c5d4ca96967d7d3a176f4c410.zip | |
Add ExecutionNode for keep parameters.
Diffstat (limited to 'node/keepdiceexecnode.cpp')
| -rw-r--r-- | node/keepdiceexecnode.cpp | 58 |
1 files changed, 38 insertions, 20 deletions
diff --git a/node/keepdiceexecnode.cpp b/node/keepdiceexecnode.cpp index 9f33f74..3966c3f 100644 --- a/node/keepdiceexecnode.cpp +++ b/node/keepdiceexecnode.cpp @@ -21,6 +21,7 @@ #include <QList> #include "keepdiceexecnode.h" +#include "parsingtoolbox.h" KeepDiceExecNode::KeepDiceExecNode() : m_diceResult(new DiceResult()) { @@ -30,22 +31,34 @@ KeepDiceExecNode::~KeepDiceExecNode() {} void KeepDiceExecNode::run(ExecutionNode* previous) { m_previousNode= previous; - if(nullptr == previous) + if(nullptr == previous || nullptr == m_numberOfDiceNode) { return; } - DiceResult* previousDiceResult= dynamic_cast<DiceResult*>(previous->getResult()); + m_numberOfDiceNode->run(previous); + auto lastnode = ParsingToolBox::getLatestNode(m_numberOfDiceNode); + if(nullptr == lastnode) + return; + auto result = lastnode->getResult(); + if(nullptr == result) + return; + if(!result->hasResultOfType(Result::SCALAR)) + return; + + auto numberOfDice = result->getResult(Result::SCALAR).toInt(); + + DiceResult* previousDiceResult = dynamic_cast<DiceResult*>(previous->getResult()); m_result->setPrevious(previousDiceResult); if(nullptr != previousDiceResult) { QList<Die*> diceList= previousDiceResult->getResultList(); - if(m_numberOfDice < 0) + if(numberOfDice < 0) { - m_numberOfDice= diceList.size() + m_numberOfDice; + numberOfDice= diceList.size() + numberOfDice; } - QList<Die*> diceList3= diceList.mid(0, static_cast<int>(m_numberOfDice)); + QList<Die*> diceList3= diceList.mid(0, static_cast<int>(numberOfDice)); QList<Die*> diceList2; for(Die* die : diceList3) @@ -56,15 +69,15 @@ void KeepDiceExecNode::run(ExecutionNode* previous) die->displayed(); } - if(m_numberOfDice > static_cast<qint64>(diceList.size())) + if(numberOfDice > static_cast<quint64>(diceList.size())) { m_errors.insert(Dice::ERROR_CODE::TOO_MANY_DICE, QObject::tr(" You ask to keep %1 dice but the result only has %2") - .arg(m_numberOfDice) + .arg(numberOfDice) .arg(diceList.size())); } - for(auto& tmp : diceList.mid(static_cast<int>(m_numberOfDice), -1)) + for(auto& tmp : diceList.mid(static_cast<int>(numberOfDice), -1)) { tmp->setHighlighted(false); } @@ -76,20 +89,22 @@ void KeepDiceExecNode::run(ExecutionNode* previous) } } } -void KeepDiceExecNode::setDiceKeepNumber(qint64 n) + +void KeepDiceExecNode::setDiceKeepNumber(ExecutionNode* n) { - m_numberOfDice= n; + m_numberOfDiceNode = n; } QString KeepDiceExecNode::toString(bool wl) const { - if(wl) - { - return QString("%1 [label=\"KeepDiceExecNode %2\"]").arg(m_id).arg(m_numberOfDice); - } - else - { - return m_id; - } + if(wl) + { + auto param = m_numberOfDiceNode->toString(wl); + return QString("%1 [label=\"KeepDiceExecNode %2\"]").arg(m_id).arg(param); + } + else + { + return m_id; + } } qint64 KeepDiceExecNode::getPriority() const { @@ -103,8 +118,11 @@ qint64 KeepDiceExecNode::getPriority() const ExecutionNode* KeepDiceExecNode::getCopy() const { - KeepDiceExecNode* node= new KeepDiceExecNode(); - node->setDiceKeepNumber(m_numberOfDice); + KeepDiceExecNode* node = new KeepDiceExecNode(); + if(nullptr != m_numberOfDiceNode) + { + node->setDiceKeepNumber(m_numberOfDiceNode->getCopy()); + } if(nullptr != m_nextNode) { node->setNextNode(m_nextNode->getCopy()); |