aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/libparser/node/explodedicenode.cpp
diff options
context:
space:
mode:
authorRenaud G <renaud@rolisteam.org>2022-04-29 10:48:09 +0200
committerRenaud G <renaud@rolisteam.org>2022-04-29 10:48:09 +0200
commit07c5f6ec23fcf9237a24e71adcfacabce677f818 (patch)
tree588e8c5f82b9163181fad3581f610e6f1d88cba4 /src/libparser/node/explodedicenode.cpp
parenta9153f1615a842cfb9e9bcda4d9071e202618569 (diff)
downloadOneRoll-07c5f6ec23fcf9237a24e71adcfacabce677f818.tar.gz
OneRoll-07c5f6ec23fcf9237a24e71adcfacabce677f818.zip
Change file organization.
Diffstat (limited to 'src/libparser/node/explodedicenode.cpp')
-rw-r--r--src/libparser/node/explodedicenode.cpp117
1 files changed, 117 insertions, 0 deletions
diff --git a/src/libparser/node/explodedicenode.cpp b/src/libparser/node/explodedicenode.cpp
new file mode 100644
index 0000000..1546883
--- /dev/null
+++ b/src/libparser/node/explodedicenode.cpp
@@ -0,0 +1,117 @@
+#include "explodedicenode.h"
+#include "validatorlist.h"
+
+ExplodeDiceNode::ExplodeDiceNode() : m_diceResult(new DiceResult())
+{
+ m_result= m_diceResult;
+}
+void ExplodeDiceNode::run(ExecutionNode* previous)
+{
+ m_previousNode= previous;
+ if((nullptr != previous) && (nullptr != previous->getResult()))
+ {
+ DiceResult* previous_result= dynamic_cast<DiceResult*>(previous->getResult());
+ m_result->setPrevious(previous_result);
+ if(nullptr != previous_result)
+ {
+ Die* exampleDie;
+ for(auto& die : previous_result->getResultList())
+ {
+ Die* tmpdie= new Die(*die);
+ m_diceResult->insertResult(tmpdie);
+ die->displayed();
+ exampleDie= tmpdie;
+ }
+
+ // QList<Die*> list= m_diceResult->getResultList();
+
+ bool hasExploded= false;
+ std::function<void(Die*, qint64)> f= [&hasExploded, this](Die* die, qint64) {
+ if(Dice::CONDITION_STATE::ALWAYSTRUE
+ == m_validatorList->isValidRangeSize(
+ std::make_pair<qint64, qint64>(die->getBase(), die->getMaxValue())))
+ {
+ m_errors.insert(Dice::ERROR_CODE::ENDLESS_LOOP_ERROR,
+ QObject::tr("Condition (%1) cause an endless loop with this dice: %2")
+ .arg(toString(true))
+ .arg(QStringLiteral("d[%1,%2]")
+ .arg(static_cast<int>(die->getBase()))
+ .arg(static_cast<int>(die->getMaxValue()))));
+ }
+ hasExploded= true;
+ die->roll(true);
+ };
+ do
+ {
+ hasExploded= false;
+ m_validatorList->validResult(m_diceResult, false, false, f);
+ } while(hasExploded);
+
+ /*for(auto& die : list)
+ {
+ if(Dice::CONDITION_STATE::ALWAYSTRUE
+ == m_validatorList->isValidRangeSize(
+ std::make_pair<qint64, qint64>(die->getBase(), die->getMaxValue())))
+ {
+
+ continue;
+ }
+
+ while(m_validatorList->hasValid(die, false))
+ {
+ die->roll(true);
+ }
+ }*/
+
+ if(nullptr != m_nextNode)
+ {
+ m_nextNode->run(this);
+ }
+ }
+ }
+}
+ExplodeDiceNode::~ExplodeDiceNode()
+{
+ if(nullptr != m_validatorList)
+ {
+ delete m_validatorList;
+ }
+}
+void ExplodeDiceNode::setValidatorList(ValidatorList* val)
+{
+ m_validatorList= val;
+}
+QString ExplodeDiceNode::toString(bool withlabel) const
+{
+ if(withlabel)
+ {
+ return QString("%1 [label=\"ExplodeDiceNode %2\"]").arg(m_id, m_validatorList->toString());
+ }
+ else
+ {
+ return m_id;
+ }
+}
+qint64 ExplodeDiceNode::getPriority() const
+{
+ qint64 priority= 0;
+ if(nullptr != m_previousNode)
+ {
+ priority= m_previousNode->getPriority();
+ }
+ return priority;
+}
+
+ExecutionNode* ExplodeDiceNode::getCopy() const
+{
+ ExplodeDiceNode* node= new ExplodeDiceNode();
+ if(nullptr != m_validatorList)
+ {
+ node->setValidatorList(m_validatorList->getCopy());
+ }
+ if(nullptr != m_nextNode)
+ {
+ node->setNextNode(m_nextNode->getCopy());
+ }
+ return node;
+}