diff options
| author | 2021-07-18 19:01:20 +0200 | |
|---|---|---|
| committer | 2021-12-11 18:31:23 +0100 | |
| commit | 7be8941fc9d5b819860d80c37a7401bee60432cc (patch) | |
| tree | 7324c9174541f88d1a6df8e68c67097d35e50c42 /node/switchcasenode.cpp | |
| parent | 31de5347732e16864cadfe9774c7e9b479b99f93 (diff) | |
| download | OneRoll-7be8941fc9d5b819860d80c37a7401bee60432cc.tar.gz OneRoll-7be8941fc9d5b819860d80c37a7401bee60432cc.zip | |
Fix switch/case operator.
Diffstat (limited to 'node/switchcasenode.cpp')
| -rw-r--r-- | node/switchcasenode.cpp | 52 |
1 files changed, 20 insertions, 32 deletions
diff --git a/node/switchcasenode.cpp b/node/switchcasenode.cpp index 0928dd2..b118243 100644 --- a/node/switchcasenode.cpp +++ b/node/switchcasenode.cpp @@ -54,35 +54,26 @@ void SwitchCaseNode::run(ExecutionNode* previous) return; } - QList<Die*> dieList; - if(previousResult->hasResultOfType(Dice::RESULT_TYPE::DICE_LIST)) - { - auto diceResult= dynamic_cast<DiceResult*>(previousResult); - if(diceResult) - dieList.append(diceResult->getResultList()); - } - else if(previousResult->hasResultOfType(Dice::RESULT_TYPE::SCALAR)) - { - auto resultScalar= previousResult->getResult(Dice::RESULT_TYPE::SCALAR).toReal(); - auto d= new Die(); - d->insertRollValue(resultScalar); - dieList.append(d); - } - - for(auto die : dieList) + QStringList resultList; + for(auto const& info : qAsConst(m_branchList)) { - QStringList resultList; - for(auto const& info : qAsConst(m_branchList)) + if(m_stopAtFirst && !resultList.isEmpty()) + break; + if(info->validatorList) + { + info->validatorList->validResult(previousResult, true, false, [&info, this, &resultList](Die*, qint64) { + info->node->run(m_previousNode); + auto lastNode= ParsingToolBox::getLeafNode(info->node); + if(lastNode && lastNode->getResult()) + { + resultList << lastNode->getResult()->getStringResult(); + } + else + resultList << QString(); + }); + } + else if(resultList.isEmpty()) { - if(info->validatorList) - { - auto res= info->validatorList->hasValid(die, true, true); - if(!res) - continue; - } - else if(!resultList.isEmpty()) - break; - info->node->run(m_previousNode); auto lastNode= ParsingToolBox::getLeafNode(info->node); if(lastNode && lastNode->getResult()) @@ -91,13 +82,10 @@ void SwitchCaseNode::run(ExecutionNode* previous) } else resultList << QString(); - - if(m_stopAtFirst) - break; } - for(auto const& str : qAsConst(resultList)) - m_stringResult->addText(str); } + for(auto const& str : qAsConst(resultList)) + m_stringResult->addText(str); if(m_stringResult->getText().isEmpty()) m_errors.insert(Dice::ERROR_CODE::NO_VALID_RESULT, QStringLiteral("No value fits the Switch/Case operator")); |