aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--HelpMe.md7
-rw-r--r--README.md3
-rw-r--r--diceparser.cpp17
-rw-r--r--node/rerolldicenode.cpp36
-rw-r--r--node/rerolldicenode.h13
5 files changed, 31 insertions, 45 deletions
diff --git a/HelpMe.md b/HelpMe.md
index 5692285..149b6e4 100644
--- a/HelpMe.md
+++ b/HelpMe.md
@@ -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]
diff --git a/README.md b/README.md
index 8ea3407..510a37d 100644
--- a/README.md
+++ b/README.md
@@ -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