aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/libparser/node/ifnode.cpp
diff options
context:
space:
mode:
authorRenaud Guezennec <renaud@rolisteam.org>2024-10-23 15:42:08 +0200
committerRenaud Guezennec <renaud@rolisteam.org>2024-12-29 14:46:30 +0100
commitcb1dcb5ee28994a2cd691ad696a5ba4c3c3802ea (patch)
treec261de4ad8d0f85aec0200bf500e9579437577df /src/libparser/node/ifnode.cpp
parente4dc41cdc3ebb84ef7e42f5cf261e36fe874c901 (diff)
downloadOneRoll-cb1dcb5ee28994a2cd691ad696a5ba4c3c3802ea.tar.gz
OneRoll-cb1dcb5ee28994a2cd691ad696a5ba4c3c3802ea.zip
Add execute node.
Diffstat (limited to 'src/libparser/node/ifnode.cpp')
-rw-r--r--src/libparser/node/ifnode.cpp207
1 files changed, 103 insertions, 104 deletions
diff --git a/src/libparser/node/ifnode.cpp b/src/libparser/node/ifnode.cpp
index 8de3cd5..62821ae 100644
--- a/src/libparser/node/ifnode.cpp
+++ b/src/libparser/node/ifnode.cpp
@@ -39,10 +39,10 @@ void PartialDiceRollNode::run(ExecutionNode* previous)
{
m_result->setPrevious(presult);
}
- if(nullptr != m_nextNode)
+ /*if(nullptr != m_nextNode)
{
m_nextNode->run(this);
- }
+ }*/
}
ExecutionNode* PartialDiceRollNode::getCopy() const
{
@@ -94,141 +94,140 @@ IfNode::~IfNode()
void IfNode::run(ExecutionNode* previous)
{
m_previousNode= previous;
- if(nullptr == previous)
- {
+ if(isValid(!previous, Dice::ERROR_CODE::NO_PREVIOUS_ERROR, tr("No Previous node")))
return;
- }
+
ExecutionNode* previousLoop= previous;
ExecutionNode* nextNode= nullptr;
- bool runNext= (nullptr == m_nextNode) ? false : true;
Result* previousResult= previous->getResult();
+ if(isValid(!previousResult, Dice::ERROR_CODE::NO_VALID_RESULT, tr("No Valid result")))
+ return;
+
m_result= previousResult->getCopy();
- if(nullptr != m_result)
+ if(isValid(!m_result, Dice::ERROR_CODE::NO_VALID_RESULT, tr("No Valid copy of result")))
+ return;
+
+ qreal value= previousResult->getResult(Dice::RESULT_TYPE::SCALAR).toReal();
+ if(isValid(!m_validatorList, Dice::ERROR_CODE::NO_VALIDATOR_LIST, tr("No validator list")))
+ return;
+
+ DiceResult* previousDiceResult= getFirstDiceResult(previousResult);
+ if(nullptr != previousDiceResult)
{
- qreal value= previousResult->getResult(Dice::RESULT_TYPE::SCALAR).toReal();
+ QList<Die*> diceList= previousDiceResult->getResultList();
- if(nullptr != m_validatorList)
+ if(m_conditionType == Dice::OnEach)
{
- DiceResult* previousDiceResult= getFirstDiceResult(previousResult);
- if(nullptr != previousDiceResult)
+ for(Die* dice : diceList)
{
- QList<Die*> diceList= previousDiceResult->getResultList();
-
- if(m_conditionType == Dice::OnEach)
+ auto diceNode= new PartialDiceRollNode();
+ diceNode->insertDie(new Die(*dice));
+ if(m_validatorList->hasValid(dice, true, true))
{
- for(Die* dice : diceList)
- {
- auto diceNode= new PartialDiceRollNode();
- diceNode->insertDie(new Die(*dice));
- if(m_validatorList->hasValid(dice, true, true))
- {
- nextNode= (nullptr == m_true) ? nullptr : m_true->getCopy();
- }
- else
- {
- nextNode= (nullptr == m_false) ? nullptr : m_false->getCopy();
- }
-
- if(nullptr != nextNode)
- {
- if(nullptr == previousLoop->getNextNode())
- {
- previousLoop->setNextNode(nextNode);
- }
- if(nullptr == m_nextNode)
- {
- m_nextNode= nextNode;
- }
- diceNode->setNextNode(nextNode);
- diceNode->run(previousLoop);
- previousLoop= getLeafNode(nextNode);
- }
- }
+ nextNode= (nullptr == m_true) ? nullptr : m_true->getCopy();
}
- else if((m_conditionType == Dice::OneOfThem) || (m_conditionType == Dice::AllOfThem))
+ else
{
- bool trueForAll= true;
- bool falseForAll= true;
-
- bool oneIsTrue= false;
- bool oneIsFalse= false;
-
- for(Die* dice : diceList)
- {
- bool result= m_validatorList->hasValid(dice, true, true);
- trueForAll= trueForAll ? result : false;
- falseForAll= falseForAll ? result : false;
+ nextNode= (nullptr == m_false) ? nullptr : m_false->getCopy();
+ }
- oneIsTrue|= result;
- oneIsFalse= !result ? true : oneIsFalse;
- }
- if(m_conditionType == Dice::OneOfThem)
- {
- if(oneIsTrue)
- {
- nextNode= (nullptr == m_true) ? nullptr : m_true->getCopy();
- }
- else // if(oneIsFalse)
- {
- nextNode= (nullptr == m_false) ? nullptr : m_false->getCopy();
- }
- }
- else if(m_conditionType == Dice::AllOfThem)
+ if(nullptr != nextNode)
+ {
+ if(nullptr == previousLoop->getNextNode())
{
- if(trueForAll)
- {
- nextNode= (nullptr == m_true) ? nullptr : m_true->getCopy();
- }
- else // if(falseForAll)
- {
- nextNode= (nullptr == m_false) ? nullptr : m_false->getCopy();
- }
+ previousLoop->setNextNode(nextNode);
}
-
- if(nullptr != nextNode)
+ if(nullptr == m_nextNode)
{
- if(nullptr == m_nextNode)
- {
- m_nextNode= nextNode;
- }
- nextNode->run(previousLoop);
- previousLoop= getLeafNode(nextNode);
+ m_nextNode= nextNode;
}
+ diceNode->setNextNode(nextNode);
+ diceNode->execute(previousLoop);
+ previousLoop= getLeafNode(nextNode);
+ }
+ else
+ {
+ delete diceNode;
}
}
+ }
+ else if((m_conditionType == Dice::OneOfThem) || (m_conditionType == Dice::AllOfThem))
+ {
+ bool trueForAll= true;
+ bool falseForAll= true;
+
+ bool oneIsTrue= false;
+ bool oneIsFalse= false;
+
+ for(Die* dice : diceList)
+ {
+ bool result= m_validatorList->hasValid(dice, true, true);
+ trueForAll= trueForAll ? result : false;
+ falseForAll= falseForAll ? result : false;
- if(m_conditionType == Dice::OnScalar)
+ oneIsTrue|= result;
+ oneIsFalse= !result ? true : oneIsFalse;
+ }
+ if(m_conditionType == Dice::OneOfThem)
{
- Die dice;
- auto val= static_cast<qint64>(value);
- dice.setValue(val);
- dice.insertRollValue(val);
- dice.setMaxValue(val);
- if(m_validatorList->hasValid(&dice, true, true))
+ if(oneIsTrue)
{
- nextNode= m_true;
+ nextNode= (nullptr == m_true) ? nullptr : m_true->getCopy();
}
- else
+ else // if(oneIsFalse)
{
- nextNode= m_false;
+ nextNode= (nullptr == m_false) ? nullptr : m_false->getCopy();
}
- if(nullptr != nextNode)
+ }
+ else if(m_conditionType == Dice::AllOfThem)
+ {
+ if(trueForAll)
{
- if(nullptr == m_nextNode)
- {
- m_nextNode= nextNode;
- }
- nextNode->run(previousLoop);
- previousLoop= getLeafNode(nextNode);
+ nextNode= (nullptr == m_true) ? nullptr : m_true->getCopy();
}
+ else // if(falseForAll)
+ {
+ nextNode= (nullptr == m_false) ? nullptr : m_false->getCopy();
+ }
+ }
+
+ if(nullptr != nextNode)
+ {
+ if(nullptr == m_nextNode)
+ {
+ m_nextNode= nextNode;
+ }
+ nextNode->execute(previousLoop);
+ previousLoop= getLeafNode(nextNode);
}
}
}
- if((nullptr != m_nextNode) && (runNext))
+ if(m_conditionType == Dice::OnScalar)
{
- m_nextNode->run(previousLoop);
+ Die dice;
+ auto val= static_cast<qint64>(value);
+ dice.setValue(val);
+ dice.insertRollValue(val);
+ dice.setMaxValue(val);
+ if(m_validatorList->hasValid(&dice, true, true))
+ {
+ nextNode= m_true;
+ }
+ else
+ {
+ nextNode= m_false;
+ }
+ if(nullptr != nextNode)
+ {
+ if(nullptr == m_nextNode)
+ {
+ m_nextNode= nextNode;
+ }
+ nextNode->execute(previousLoop);
+ previousLoop= getLeafNode(nextNode);
+ }
}
}