diff options
| author | 2022-05-18 22:56:53 +0200 | |
|---|---|---|
| committer | 2022-05-18 22:57:27 +0200 | |
| commit | 4950fee9569525f59624651ba2a267e4e4324220 (patch) | |
| tree | ddd4ca6bb580997dd1d7c73176738ff91f457f2a /src/libparser/node/switchcasenode.cpp | |
| parent | 57acb8a12a2d9b66145a0a8382e4536a4170c1b0 (diff) | |
| download | OneRoll-4950fee9569525f59624651ba2a267e4e4324220.tar.gz OneRoll-4950fee9569525f59624651ba2a267e4e4324220.zip | |
Manage scalar result in front of Switch/Case
Fix #144
Diffstat (limited to 'src/libparser/node/switchcasenode.cpp')
| -rw-r--r-- | src/libparser/node/switchcasenode.cpp | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/src/libparser/node/switchcasenode.cpp b/src/libparser/node/switchcasenode.cpp index 880fa4d..c48d81f 100644 --- a/src/libparser/node/switchcasenode.cpp +++ b/src/libparser/node/switchcasenode.cpp @@ -22,6 +22,7 @@ #include "stringresult.h" #include <QDebug> #include <diceparser/parsingtoolbox.h> +#include <memory> SwitchCaseNode::SwitchCaseNode() : m_stringResult(new StringResult) { @@ -56,7 +57,6 @@ void SwitchCaseNode::run(ExecutionNode* previous) auto diceResult= dynamic_cast<DiceResult*>(previousResult); - QSet<QString> alreadyValidDice; QStringList finalResultList; if(diceResult) { @@ -93,6 +93,41 @@ void SwitchCaseNode::run(ExecutionNode* previous) finalResultList << resultList; } } + else + { + auto scalar= previousResult->getResult(Dice::RESULT_TYPE::SCALAR).toReal(); + for(auto const& info : qAsConst(m_branchList)) + { + if(m_stopAtFirst && !finalResultList.isEmpty()) + break; + + if(info->validatorList) + { + auto die= std::make_unique<Die>(); + die->insertRollValue(scalar); + if(info->validatorList->hasValid(die.get(), true)) + { + auto lastNode= ParsingToolBox::getLeafNode(info->node); + if(lastNode && lastNode->getResult()) + { + finalResultList << lastNode->getResult()->getStringResult(); + } + } + } + else if(finalResultList.isEmpty()) + { + info->node->run(m_previousNode); + auto lastNode= ParsingToolBox::getLeafNode(info->node); + if(lastNode && lastNode->getResult()) + { + finalResultList << lastNode->getResult()->getStringResult(); + } + else + finalResultList << QString(); + } + } + } + for(auto const& str : qAsConst(finalResultList)) m_stringResult->addText(str); |