diff options
| author | 2018-05-26 20:08:08 +0200 | |
|---|---|---|
| committer | 2018-06-01 13:53:00 +0200 | |
| commit | 0a9202c3ef0d3255ae3d57d0df68f7232396b580 (patch) | |
| tree | 870a7fbaa421da1ada3a6e30ecf17d5dbc69a73a | |
| parent | 00b6a6a04b341d5a6332083425e3524349cef521 (diff) | |
| download | OneRoll-0a9202c3ef0d3255ae3d57d0df68f7232396b580.tar.gz OneRoll-0a9202c3ef0d3255ae3d57d0df68f7232396b580.zip | |
add "R" (Reroll until) operator
| -rw-r--r-- | HelpMe.md | 7 | ||||
| -rw-r--r-- | README.md | 3 | ||||
| -rw-r--r-- | diceparser.cpp | 17 | ||||
| -rw-r--r-- | node/rerolldicenode.cpp | 36 | ||||
| -rw-r--r-- | node/rerolldicenode.h | 13 |
5 files changed, 31 insertions, 45 deletions
@@ -151,6 +151,7 @@ the number of instruction is not limited. * s : Sort * c : Count * r : Reroll +* R : Reroll until * e : Explode * a : Reroll and add * @ : Backward Jump @@ -210,6 +211,12 @@ Count how many dice respect the condition and display the number (See Validator Reroll the die if the previous value fits the validator (See Validator for more details about syntax). +### Reroll until + +> 3D10R[Validator] + +Works like "Reroll", but continue to roll the dice until the condition is false. + ### Explode > 3D10e[Validator] @@ -14,7 +14,7 @@ Instruction =: Expression Expression =: number | number Dice DiceOperation | ScalarOperator Expression | string | variable Expression Dice =: DiceOperator Number(faces) | DiceOperator ListOfValues DiceOperator =: D | L -DiceOperation =: Keep | KeepAndExplode | Sort | Count | Reroll | If | Explode | Jumpbackward | Merge | Filter | Split | Parenthese | Count | Paint | Group +DiceOperation =: Keep | KeepAndExplode | Sort | Count | Reroll | RerollUntil | If | Explode | Jumpbackward | Merge | Filter | Split | Parenthese | Count | Paint | Group ScalarOperator =: [x,-,*,x,/] number =: [0-9]+ | constantValue constantValue =: ${id | label} @@ -31,6 +31,7 @@ String =: [A-z0-9]+ Keep =: k Number KeepAndExplode =: K number Reroll =: r +RerollUntil =: R Explosing =: e RerollOnceAndAdd =: a RerollAndAdd =: A diff --git a/diceparser.cpp b/diceparser.cpp index c37d572..641cf21 100644 --- a/diceparser.cpp +++ b/diceparser.cpp @@ -69,6 +69,7 @@ DiceParser::DiceParser() m_OptionOp->insert(QStringLiteral("c"),Count); m_OptionOp->insert(QStringLiteral("r"),Reroll); m_OptionOp->insert(QStringLiteral("e"),Explode); + m_OptionOp->insert(QStringLiteral("R"),RerollUntil); m_OptionOp->insert(QStringLiteral("a"),RerollAndAdd); m_OptionOp->insert(QStringLiteral("m"),Merge); m_OptionOp->insert(QStringLiteral("i"),ifOperator); @@ -1048,7 +1049,9 @@ bool DiceParser::readOption(QString& str,ExecutionNode* previous)//, } break; case Reroll: + case RerollUntil: case RerollAndAdd: + // Todo: I think that Exploding and Rerolling could share the same code { Validator* validator = m_parsingToolbox->readCompositeValidator(str); if(nullptr!=validator) @@ -1058,16 +1061,10 @@ bool DiceParser::readOption(QString& str,ExecutionNode* previous)//, m_errorMap.insert(ExecutionNode::BAD_SYNTAXE,QObject::tr("Validator is missing after the %1 operator. Please, change it") .arg(operatorName == Reroll ? "r" : "a" )); } - RerollDiceNode* rerollNode = new RerollDiceNode(); - ExecutionNode* nodeParam = nullptr; - if(readParameterNode(str,nodeParam)) - { - rerollNode->setInstruction(nodeParam); - } - if(m_OptionOp->value(key)==RerollAndAdd) - { - rerollNode->setAddingMode(true); - } + + auto reroll = (operatorName==RerollAndAdd || operatorName==Reroll); + auto addingMode = (operatorName==RerollAndAdd); + RerollDiceNode* rerollNode = new RerollDiceNode(reroll, addingMode); rerollNode->setValidator(validator); previous->setNextNode(rerollNode); node = rerollNode; diff --git a/node/rerolldicenode.cpp b/node/rerolldicenode.cpp index a24ffa9..f7df0fa 100644 --- a/node/rerolldicenode.cpp +++ b/node/rerolldicenode.cpp @@ -1,8 +1,11 @@ #include "rerolldicenode.h" #include "parsingtoolbox.h" -RerollDiceNode::RerollDiceNode() - : m_diceResult(new DiceResult()),m_adding(false),m_validator(nullptr) +RerollDiceNode::RerollDiceNode(bool reroll, bool addingMode) + : m_diceResult(new DiceResult()) + , m_validator(nullptr) + , m_reroll(reroll) + , m_adding(addingMode) { m_result=m_diceResult; } @@ -38,26 +41,12 @@ void RerollDiceNode::run(ExecutionNode* previous) for(int i = 0; i < list.size() ; ++i) { auto die = list.at(i); - if(m_validator->hasValid(die,false)) + while(m_validator->hasValid(die,false)) { - if(m_instruction != nullptr) + die->roll(m_adding); + if(m_reroll) { - m_instruction->run(this); - auto lastNode = ParsingToolBox::getLatestNode(m_instruction); - if(lastNode != nullptr) - { - auto lastResult = dynamic_cast<DiceResult*>(lastNode->getResult()); - if(lastResult != nullptr) - { - toRemove.append(die); - list.append(lastResult->getResultList()); - } - lastResult->clear(); - } - } - else - { - die->roll(m_adding); + break; } } } @@ -96,10 +85,6 @@ QString RerollDiceNode::toString(bool wl) const } //return QString("RerollDiceNode [label=\"RerollDiceNode validatior:%1\""); } -void RerollDiceNode::setAddingMode(bool b) -{ - m_adding = b; -} qint64 RerollDiceNode::getPriority() const { qint64 priority=0; @@ -113,9 +98,8 @@ qint64 RerollDiceNode::getPriority() const } ExecutionNode* RerollDiceNode::getCopy() const { - RerollDiceNode* node = new RerollDiceNode(); + RerollDiceNode* node = new RerollDiceNode(m_reroll, m_adding); node->setValidator(m_validator); - node->setAddingMode(m_adding); if(nullptr!=m_nextNode) { node->setNextNode(m_nextNode->getCopy()); diff --git a/node/rerolldicenode.h b/node/rerolldicenode.h index c999dda..8bef6dd 100644 --- a/node/rerolldicenode.h +++ b/node/rerolldicenode.h @@ -18,8 +18,9 @@ public: enum ReRollMode {EQUAL,LESSER,GREATER}; /** * @brief RerollDiceNode + * @param reroll If true reroll the dice only once, otherwise until the condition is false */ - RerollDiceNode(); + RerollDiceNode(bool reroll, bool addingMode); /** * @brief ~RerollDiceNode @@ -40,12 +41,6 @@ public: * @return */ virtual QString toString(bool )const; - - - /** - * @brief setAddingMode - */ - virtual void setAddingMode(bool); /** * @brief getPriority * @return @@ -63,9 +58,11 @@ public: private: DiceResult* m_diceResult = nullptr; - bool m_adding; Validator* m_validator = nullptr; ExecutionNode* m_instruction = nullptr; + + const bool m_reroll; + const bool m_adding; }; #endif // REROLLDICENODE_H |