diff options
| author | 2017-11-28 10:35:26 +0100 | |
|---|---|---|
| committer | 2017-11-28 10:35:26 +0100 | |
| commit | 4516fab0081b0db73b7401816a521453ab77ecc6 (patch) | |
| tree | 0cbdf6fc0c0b603a3a9dc9523f5e29302dd5467a | |
| parent | 95d4b12f2900f13e5836cb460261c96889bdd4e5 (diff) | |
| download | OneRoll-4516fab0081b0db73b7401816a521453ab77ecc6.tar.gz OneRoll-4516fab0081b0db73b7401816a521453ab77ecc6.zip | |
add stuff to debug if operator in if operator
| -rw-r--r-- | booleancondition.cpp | 5 | ||||
| -rw-r--r-- | cli/main.cpp | 12 | ||||
| -rw-r--r-- | diceparser.cpp | 18 | ||||
| -rw-r--r-- | diceparser.h | 1 | ||||
| -rw-r--r-- | node/ifnode.cpp | 8 | ||||
| -rw-r--r-- | node/stringnode.cpp | 77 |
6 files changed, 38 insertions, 83 deletions
diff --git a/booleancondition.cpp b/booleancondition.cpp index 7be9836..2a3e1b5 100644 --- a/booleancondition.cpp +++ b/booleancondition.cpp @@ -20,7 +20,7 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "booleancondition.h" - +#include <QDebug> BooleanCondition::BooleanCondition() : m_operator(Equal) @@ -39,8 +39,9 @@ qint64 BooleanCondition::hasValid(Die* b,bool recursive,bool unhighlight) const } qint64 sum= 0; - foreach(qint64 value, listValues) + for(qint64 value: listValues) { + qDebug() << "value" << value << m_value; switch(m_operator) { case Equal: diff --git a/cli/main.cpp b/cli/main.cpp index be02507..0672076 100644 --- a/cli/main.cpp +++ b/cli/main.cpp @@ -228,8 +228,8 @@ void startDiceParsingMarkdown(QString cmd) DiceParser parser; //setAlias - parser.insertAlias(new DiceAlias("l5r5R","L[-,⨀,⨀⬢,❂⬢,❁,❁⬢]"),0); - parser.insertAlias(new DiceAlias("l5r5S","L[-,-,⨀,⨀,⨀❁,⨀⬢,⨀⬢,❂,❂⬢,❁,❁,❁]"),1); + parser.insertAlias(new DiceAlias("L5R5R","L[-,⨀,⨀⬢,❂⬢,❁,❁⬢]"),0); + parser.insertAlias(new DiceAlias("L5R5S","L[-,-,⨀,⨀,⨀❁,⨀⬢,⨀⬢,❂,❂⬢,❁,❁,❁]"),1); if(parser.parseLine(cmd)) @@ -352,7 +352,13 @@ void startDiceParsing(QStringList& cmds,QString& treeFile,bool highlight) if(parser->hasStringResult()) { - str = parser->getStringResult().join(",");; + bool ok; + QStringList allStringlist = parser->getAllStringResult(ok); + QString stringResult = allStringlist.join(" ; "); + stringResult.replace("%1",scalarText); + stringResult.replace("%2",diceText.trimmed()); + str = stringResult; +// str = parser->getStringResult().join(","); } if(!parser->getComment().isEmpty()) { diff --git a/diceparser.cpp b/diceparser.cpp index c2191ce..d9871e2 100644 --- a/diceparser.cpp +++ b/diceparser.cpp @@ -247,6 +247,11 @@ bool DiceParser::readExpression(QString& str,ExecutionNode* & node) node = operandNode; return true; } + else if(readOptionFromNull(str,operandNode)) + { + node = operandNode; + return true; + } else { ExecutionNode* diceNode=nullptr; @@ -254,7 +259,7 @@ bool DiceParser::readExpression(QString& str,ExecutionNode* & node) { NumberNode* numberNode=new NumberNode(); numberNode->setNumber(1); - ExecutionNode* previous = diceNode->getPreviousNode(); + ExecutionNode* previous = diceNode->getPreviousNode(); numberNode->setPreviousNode(previous); numberNode->setNextNode(diceNode); node = numberNode; @@ -271,6 +276,17 @@ bool DiceParser::readExpression(QString& str,ExecutionNode* & node) } return true; } +bool DiceParser::readOptionFromNull(QString& str,ExecutionNode* & node) +{ + StartingNode nodePrevious; + if(readOption(str,&nodePrevious)) + { + auto nodeNext = nodePrevious.getNextNode(); + node = nodeNext; + return true; + } + return false; +} bool DiceParser::readNode(QString& str,ExecutionNode* & node) { QString key= str.left(1); diff --git a/diceparser.h b/diceparser.h index cd031bb..7cb1184 100644 --- a/diceparser.h +++ b/diceparser.h @@ -230,6 +230,7 @@ public: QString getComment() const; void setComment(const QString &comment); + bool readOptionFromNull(QString &str, ExecutionNode *&node); private: /** diff --git a/node/ifnode.cpp b/node/ifnode.cpp index b40ed82..a74667d 100644 --- a/node/ifnode.cpp +++ b/node/ifnode.cpp @@ -96,10 +96,12 @@ void IfNode::run(ExecutionNode *previous) bool result = m_validator->hasValid(dice,true,true); trueForAll = trueForAll ? result : false; falseForAll = falseForAll ? result : false; + qDebug() << "result" << result; - oneIsTrue = (oneIsTrue==false) ? result : true; - oneIsFalse = (oneIsFalse==false) ? result : true; + oneIsTrue |= result; + oneIsFalse = !result ? true : oneIsFalse; } + qDebug() << "OneIsVrai: " << oneIsTrue <<" oneIsFaux" <<oneIsFalse<<" vraiForAll" <<trueForAll <<" fauxForAll" <<falseForAll << m_conditionType; if(m_conditionType==OneOfThem) { if(oneIsTrue) @@ -119,7 +121,7 @@ void IfNode::run(ExecutionNode *previous) } else if(falseForAll) { - nextNode = (nullptr==m_false) ? nullptr: m_false->getCopy(); + nextNode = (nullptr==m_false) ? nullptr: m_false->getCopy(); } } diff --git a/node/stringnode.cpp b/node/stringnode.cpp index af2fcda..5c489be 100644 --- a/node/stringnode.cpp +++ b/node/stringnode.cpp @@ -28,86 +28,15 @@ QString StringNode::toString(bool withLabel) const { if(withLabel) { - return QString("%1 [label=\"StringNode %2\"]").arg(m_id).arg(m_data); + QString dataCopy = m_data; + + return QString("%1 [label=\"StringNode %2\"]").arg(m_id).arg(dataCopy.replace('%','\\')); } else { return m_id; } } -/*void StringNode::getScalarResult() -{ - QString scalarText; - - if(m_diceParser->hasIntegerResultNotInFirst()) - { - scalarText = QStringLiteral("%1").arg(m_diceParser->getLastIntegerResult()); - } - else if(hasDiceList) - { - scalarText = QStringLiteral("%1").arg(m_diceParser->getSumOfDiceResult()); - } -}*/ - -/*bool StringNode::getMessageResult(QString& value, QString& command, QString& list) -{ - QString scalarText; - QString diceText; - //QString pattern(""); - - - - bool hasDiceList = false; - if(m_diceParser->hasDiceResult()) - { - ExportedDiceResult diceList; - bool ok; - m_diceParser->getLastDiceResult(diceList,ok);//fills the ExportedDiceResult - diceText = diceToText(diceList); - hasDiceList= true; - } - if(m_diceParser->hasSeparator()) - { - bool ok; - QStringList allStringlist = m_diceParser->getAllDiceResult(ok); - if(ok) - { - QString patternColor("<span class=\"dice\">%1</span>"); - list = patternColor.arg(allStringlist.join(' ')); - scalarText = list; - } - } - else if(m_diceParser->hasIntegerResultNotInFirst()) - { - scalarText = QStringLiteral("%1").arg(m_diceParser->getLastIntegerResult()); - } - else if(hasDiceList) - { - scalarText = QStringLiteral("%1").arg(m_diceParser->getSumOfDiceResult()); - } - value=scalarText; - list = diceText.trimmed(); - command = m_diceParser->getDiceCommand().toHtmlEscaped(); - if(m_diceParser->hasStringResult()) - { - bool ok; - QStringList allStringlist = m_diceParser->getAllStringResult(ok); - if(ok) - { - QString patternColor("<span class=\"dice\">%1</span>"); - list = patternColor.arg(allStringlist.join(' ')); - value = list; - } - else - { - value = m_diceParser->getStringResult().replace("\n","<br/>"); - list = allStringlist.join(' '); - return true; - } - } - - return false; -}*/ qint64 StringNode::getPriority() const { qint64 priority=0; |