From eef188c6cc953fcff9cf4491b0ae8256608caa14 Mon Sep 17 00:00:00 2001 From: Renaud G Date: Tue, 23 Oct 2018 20:01:40 +0200 Subject: first draft for diceresult --- cli/main.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ diceparser.cpp | 14 ++++++++++++-- 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/cli/main.cpp b/cli/main.cpp index dee3d05..30b05a3 100644 --- a/cli/main.cpp +++ b/cli/main.cpp @@ -242,6 +242,7 @@ int startDiceParsing(QStringList& cmds,QString& treeFile,bool withColor, EXPORTF QString comment = parser.getComment(); QString error = parser.humanReadableError(); QStringList strLst; + QStringList listOfDiceResult; if(parser.hasIntegerResultNotInFirst()) { @@ -262,7 +263,41 @@ int startDiceParsing(QStringList& cmds,QString& treeFile,bool withColor, EXPORTF } scalarText = QString("%1").arg(strLst.join(',')); } + if(!list.isEmpty()) + { + qDebug() << "list is not empty" << list.size(); + for(auto map : list) + { + qDebug() << "loop map"<< map.size(); + for(auto key : map.keys()) + { + qDebug() << "key: "< 1) + { + stringVal=QString("%1 [%2]").arg(total).arg(dicelist.join(',')); + listOfDiceResult << stringVal; + } + else + { + listOfDiceResult << QString::number(total); + } + } + } + } + } + qDebug() << listOfDiceResult; if(parser.hasStringResult()) { bool ok; @@ -277,6 +312,11 @@ int startDiceParsing(QStringList& cmds,QString& treeFile,bool withColor, EXPORTF stringResult.replace(QStringLiteral("$%1").arg(i),(*it)); --i; } + for(auto it = strLst.rbegin(); it != strLst.rend() ; ++it) + { + stringResult.replace(QStringLiteral("µ%1").arg(i),(*it)); + --i; + } resultStr = stringResult; } diff --git a/diceparser.cpp b/diceparser.cpp index 41a91e5..0d41f4d 100644 --- a/diceparser.cpp +++ b/diceparser.cpp @@ -494,19 +494,23 @@ QStringList DiceParser::getAllDiceResult(bool& hasAlias) } void DiceParser::getLastDiceResult(QList& diceValuesList,bool& homogeneous) { + int i = 0; for(auto start : m_startNodes) { ExportedDiceResult diceValues; ExecutionNode* next = getLeafNode(start); Result* result=next->getResult(); - + qDebug() << "tour:"<hasResultOfType(Result::DICE_LIST)) { + qDebug() << "has diceresult"<(result); if(nullptr!=diceResult) { + qDebug() << "cast diceresult"; if(homogeneous) { @@ -516,8 +520,9 @@ void DiceParser::getLastDiceResult(QList& diceValuesList,boo ListDiceResult listpair; for(Die* die : diceResult->getResultList()) { - if(!die->hasBeenDisplayed()) + // if(!die->hasBeenDisplayed()) { + qDebug() << "dice has NOT been displayed"; QList valuesResult; valuesResult.append(die->getValue()); die->displayed(); @@ -533,9 +538,14 @@ void DiceParser::getLastDiceResult(QList& diceValuesList,boo //QPair,bool> pair(valuesResult,die->isHighlighted()); listpair.append(hlDice); } + // else + { + qDebug() << "dice has been displayed"; + } } if(!listpair.isEmpty()) { + qDebug() << "list pair not empty "; if(!diceValues.contains(face)) { diceValues.insert(face,listpair); -- cgit v1.2.3-70-g09d2 From 0586f25925f4db4a181c7d7d0a3925bb8a6daecf Mon Sep 17 00:00:00 2001 From: Renaud G Date: Wed, 24 Oct 2018 21:37:58 +0200 Subject: DiceParser: better display. --- cli/main.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cli/main.cpp b/cli/main.cpp index 30b05a3..c40cff6 100644 --- a/cli/main.cpp +++ b/cli/main.cpp @@ -304,6 +304,7 @@ int startDiceParsing(QStringList& cmds,QString& treeFile,bool withColor, EXPORTF QStringList allStringlist = parser.getAllStringResult(ok); QString stringResult = allStringlist.join(" ; "); stringResult.replace("%1",scalarText); + resultStr.replace("%2",diceList.trimmed()); stringResult.replace("%3",lastScalarText); int i = strLst.size(); @@ -312,6 +313,7 @@ int startDiceParsing(QStringList& cmds,QString& treeFile,bool withColor, EXPORTF stringResult.replace(QStringLiteral("$%1").arg(i),(*it)); --i; } + i = strLst.size(); for(auto it = strLst.rbegin(); it != strLst.rend() ; ++it) { stringResult.replace(QStringLiteral("µ%1").arg(i),(*it)); -- cgit v1.2.3-70-g09d2 From b210bda3d2362e9b5f1606c7a21f546dcd2e6a67 Mon Sep 17 00:00:00 2001 From: Renaud G Date: Wed, 17 Oct 2018 17:50:56 +0200 Subject: Update HelpMe.md add one best practice --- HelpMe.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/HelpMe.md b/HelpMe.md index 2da834c..2bd1e02 100644 --- a/HelpMe.md +++ b/HelpMe.md @@ -600,6 +600,14 @@ As DiceParser provides more and more features, you may find several ways to do t The merge operator is useful when you want to use dice operator on all rolled dice. +```Bad``` +> 1d20K1+1d10K1 + +```Good``` +> 1d20+1d10 + +The k operator to keeps as many dice as you roll is pretty useless because it is the default behaviour. + ## Plateform specific documentation ### Roll dice on each platform -- cgit v1.2.3-70-g09d2 From 250431661bc4abb819bf790ff3348babfadf98b4 Mon Sep 17 00:00:00 2001 From: Renaud G Date: Sat, 27 Oct 2018 00:46:35 +0200 Subject: copy data parameter when copy variable node --- node/variablenode.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/node/variablenode.cpp b/node/variablenode.cpp index b1c9e3b..fafc722 100644 --- a/node/variablenode.cpp +++ b/node/variablenode.cpp @@ -53,6 +53,10 @@ ExecutionNode *VariableNode::getCopy() const { VariableNode* node = new VariableNode(); node->setIndex(m_index); + if(nullptr != m_data) + { + node->setData(m_data); + } if(nullptr!=m_nextNode) { node->setNextNode(m_nextNode->getCopy()); -- cgit v1.2.3-70-g09d2 From ab902d65c6640e7b388cc5d89588e2fc6b32759a Mon Sep 17 00:00:00 2001 From: Renaud G Date: Sat, 27 Oct 2018 00:25:05 +0200 Subject: Clean up die class. --- die.cpp | 5 ----- die.h | 10 +++++----- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/die.cpp b/die.cpp index 7cacf18..d398021 100644 --- a/die.cpp +++ b/die.cpp @@ -29,13 +29,8 @@ Die::Die() : m_hasValue(false),m_displayStatus(false),m_highlighted(true),m_base(1),m_color(""),m_op(Die::PLUS)//,m_mt(m_randomDevice) { -// uint seed = quintptr(this) + QDateTime::currentDateTime().toMSecsSinceEpoch(); - - // qsrand(seed); - auto seed = std::chrono::high_resolution_clock::now().time_since_epoch().count(); m_rng = std::mt19937(quintptr(this)+seed); - } Die::Die(const Die& die) { diff --git a/die.h b/die.h index b17ced4..79bed6d 100644 --- a/die.h +++ b/die.h @@ -135,12 +135,12 @@ public: void setOp(const Die::ArithmeticOperator &op); private: - qint64 m_value; + qint64 m_value = 0; QList m_rollResult; - bool m_selected; - bool m_hasValue; - bool m_displayStatus; - bool m_highlighted; + bool m_selected = false; + bool m_hasValue = false; + bool m_displayStatus = false; + bool m_highlighted = true; qint64 m_maxValue; qint64 m_base; QString m_color; -- cgit v1.2.3-70-g09d2 From c98b88063b0edd45c240902a767804f232af9a43 Mon Sep 17 00:00:00 2001 From: Renaud G Date: Sat, 27 Oct 2018 00:25:55 +0200 Subject: HighLightDice: add member to help. --- highlightdice.cpp | 24 ++++++++++++++++++++++-- highlightdice.h | 14 ++++++++++---- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/highlightdice.cpp b/highlightdice.cpp index 47ed79e..1c4b2e7 100644 --- a/highlightdice.cpp +++ b/highlightdice.cpp @@ -19,8 +19,8 @@ ***************************************************************************/ #include "highlightdice.h" -HighLightDice::HighLightDice(QList result,bool isHighlighted, QString color) - : m_result(result),m_hasHighlight(isHighlighted),m_color(color) +HighLightDice::HighLightDice(QList result, bool isHighlighted, QString color, bool displayed, quint64 faces) + : m_result(result),m_hasHighlight(isHighlighted),m_color(color), m_displayed(displayed),m_faces(faces) { } @@ -60,3 +60,23 @@ void HighLightDice::setColor(const QString &color) { m_color = color; } + +bool HighLightDice::getDisplayed() const +{ + return m_displayed; +} + +void HighLightDice::setDisplayed(bool displayed) +{ + m_displayed = displayed; +} + +quint64 HighLightDice::getFaces() const +{ + return m_faces; +} + +void HighLightDice::setFaces(const quint64 &faces) +{ + m_faces = faces; +} diff --git a/highlightdice.h b/highlightdice.h index a74d747..72e696f 100644 --- a/highlightdice.h +++ b/highlightdice.h @@ -27,11 +27,9 @@ class HighLightDice { public: - HighLightDice(QList result,bool isHighlighted, QString color); + HighLightDice(QList result,bool isHighlighted, QString color, bool displayed,quint64 faces); virtual ~HighLightDice(); - - QList getResult() const; void setResult(const QList &result); @@ -41,10 +39,18 @@ public: QString getColor() const; void setColor(const QString &color); + bool getDisplayed() const; + void setDisplayed(bool displayed); + + quint64 getFaces() const; + void setFaces(const quint64 &faces); + private: QList m_result; - bool m_hasHighlight; + bool m_hasHighlight = true; QString m_color; + bool m_displayed = false; + quint64 m_faces; }; #endif // HighLightDice_H -- cgit v1.2.3-70-g09d2 From 0994c2713eb17a7568369bbb09ca73d4e4045028 Mon Sep 17 00:00:00 2001 From: Renaud G Date: Sat, 27 Oct 2018 00:35:00 +0200 Subject: Commit before rebase. --- diceparser.cpp | 46 +++++++++++++++++++++++++++++++++------------- diceparser.h | 3 ++- 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/diceparser.cpp b/diceparser.cpp index 0d41f4d..6182a89 100644 --- a/diceparser.cpp +++ b/diceparser.cpp @@ -492,6 +492,37 @@ QStringList DiceParser::getAllDiceResult(bool& hasAlias) return stringListResult; } + +void DiceParser::getDiceResultFromAllInstruction(QList& resultList) +{ + int i = 0; + for(auto start : m_startNodes) + { + ExecutionNode* next = getLeafNode(start); + Result* result=next->getResult(); + ExportedDiceResult nodeResult; + while(nullptr!=result) + { + if(result->hasResultOfType(Result::DICE_LIST)) + { + DiceResult* diceResult = dynamic_cast(result); + QList list; + quint64 faces = 0; + + for(Die* die : diceResult->getResultList()) + { + faces = die->getFaces(); + HighLightDice hlDice(die->getListValue(),die->isHighlighted(),die->getColor(), die->hasBeenDisplayed(),die->getFaces()); + list.append(hlDice); + } + nodeResult.insert(static_cast(faces),list); + } + result = result->getPrevious(); + } + resultList.append(nodeResult); + } +} + void DiceParser::getLastDiceResult(QList& diceValuesList,bool& homogeneous) { int i = 0; @@ -500,17 +531,13 @@ void DiceParser::getLastDiceResult(QList& diceValuesList,boo ExportedDiceResult diceValues; ExecutionNode* next = getLeafNode(start); Result* result=next->getResult(); - qDebug() << "tour:"<hasResultOfType(Result::DICE_LIST)) { - qDebug() << "has diceresult"<(result); if(nullptr!=diceResult) { - qDebug() << "cast diceresult"; if(homogeneous) { @@ -520,9 +547,8 @@ void DiceParser::getLastDiceResult(QList& diceValuesList,boo ListDiceResult listpair; for(Die* die : diceResult->getResultList()) { - // if(!die->hasBeenDisplayed()) + if(!die->hasBeenDisplayed()) { - qDebug() << "dice has NOT been displayed"; QList valuesResult; valuesResult.append(die->getValue()); die->displayed(); @@ -534,18 +560,12 @@ void DiceParser::getLastDiceResult(QList& diceValuesList,boo valuesResult.append(i); } } - HighLightDice hlDice(valuesResult,die->isHighlighted(),die->getColor()); - //QPair,bool> pair(valuesResult,die->isHighlighted()); + HighLightDice hlDice(valuesResult,die->isHighlighted(),die->getColor(), die->hasBeenDisplayed(),0); listpair.append(hlDice); } - // else - { - qDebug() << "dice has been displayed"; - } } if(!listpair.isEmpty()) { - qDebug() << "list pair not empty "; if(!diceValues.contains(face)) { diceValues.insert(face,listpair); diff --git a/diceparser.h b/diceparser.h index 2ede553..3d5ba8f 100644 --- a/diceparser.h +++ b/diceparser.h @@ -129,7 +129,7 @@ public: * @brief getLastDiceResult * @return */ - void getLastDiceResult(QList& diceValues,bool& homogeneous); + void getLastDiceResult(QList& diceValues, bool& homogeneous); /** * @brief hasIntegerResultNotInFirst * @return @@ -219,6 +219,7 @@ public: bool readOptionFromNull(QString &str, ExecutionNode *&node); bool readInstructionList(QString &str); + void getDiceResultFromAllInstruction(QList &resultList); protected: bool readParameterNode(QString &str, ExecutionNode *&node); private: -- cgit v1.2.3-70-g09d2 From 4a6b19b27866326fa069a422ed2c862ab9e9d4d2 Mon Sep 17 00:00:00 2001 From: Renaud G Date: Sat, 27 Oct 2018 00:35:15 +0200 Subject: Get full result. --- cli/main.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cli/main.cpp b/cli/main.cpp index c40cff6..7cf2b7b 100644 --- a/cli/main.cpp +++ b/cli/main.cpp @@ -232,8 +232,10 @@ int startDiceParsing(QStringList& cmds,QString& treeFile,bool withColor, EXPORTF { parser.start(); QList list; + QList listFull; bool homogeneous = true; parser.getLastDiceResult(list,homogeneous); + parser.getDiceResultFromAllInstruction(listFull); bool allSameFaceCount, allSameColor; auto array = DisplayToolBox::diceToJson(list,allSameFaceCount,allSameColor); QString resultStr; @@ -313,7 +315,7 @@ int startDiceParsing(QStringList& cmds,QString& treeFile,bool withColor, EXPORTF stringResult.replace(QStringLiteral("$%1").arg(i),(*it)); --i; } - i = strLst.size(); + i = listFull.size(); for(auto it = strLst.rbegin(); it != strLst.rend() ; ++it) { stringResult.replace(QStringLiteral("µ%1").arg(i),(*it)); -- cgit v1.2.3-70-g09d2 From 1d8bd391b1df4fd2f2f274828db14c9ce695eb8b Mon Sep 17 00:00:00 2001 From: Renaud G Date: Fri, 9 Nov 2018 23:47:26 +0100 Subject: fix some warnings --- diceparser.cpp | 2 -- result/diceresult.cpp | 5 +++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/diceparser.cpp b/diceparser.cpp index 6182a89..daa8d9d 100644 --- a/diceparser.cpp +++ b/diceparser.cpp @@ -495,7 +495,6 @@ QStringList DiceParser::getAllDiceResult(bool& hasAlias) void DiceParser::getDiceResultFromAllInstruction(QList& resultList) { - int i = 0; for(auto start : m_startNodes) { ExecutionNode* next = getLeafNode(start); @@ -525,7 +524,6 @@ void DiceParser::getDiceResultFromAllInstruction(QList& resu void DiceParser::getLastDiceResult(QList& diceValuesList,bool& homogeneous) { - int i = 0; for(auto start : m_startNodes) { ExportedDiceResult diceValues; diff --git a/result/diceresult.cpp b/result/diceresult.cpp index 7894b60..c1089dd 100644 --- a/result/diceresult.cpp +++ b/result/diceresult.cpp @@ -114,6 +114,9 @@ qreal DiceResult::getScalarResult() case Die::MINUS: scalar-=tmp->getValue(); break; + case Die::POW: + scalar=static_cast(pow(static_cast(scalar),static_cast(tmp->getValue()))); + break; case Die::DIVIDE: case Die::INTEGER_DIVIDE: if(tmp->getValue()!=0) @@ -135,8 +138,6 @@ qreal DiceResult::getScalarResult() } return scalar; } - - return 0; } Die::ArithmeticOperator DiceResult::getOperator() const -- cgit v1.2.3-70-g09d2