diff options
| author | 2018-11-11 17:38:53 +0100 | |
|---|---|---|
| committer | 2018-11-11 17:38:53 +0100 | |
| commit | 750cc31e9157bf92f54a66b8a076e5287c4cef3a (patch) | |
| tree | 8931522a6b82cf82f997029ef76608243a27e904 | |
| parent | bd4a0c837bd5e3b4dbf9d3dcef892850d04ec6ac (diff) | |
| parent | 1d8bd391b1df4fd2f2f274828db14c9ce695eb8b (diff) | |
| download | OneRoll-750cc31e9157bf92f54a66b8a076e5287c4cef3a.tar.gz OneRoll-750cc31e9157bf92f54a66b8a076e5287c4cef3a.zip | |
Merge branch 'diceResult'
| -rw-r--r-- | cli/main.cpp | 44 | ||||
| -rw-r--r-- | diceparser.cpp | 34 | ||||
| -rw-r--r-- | diceparser.h | 3 | ||||
| -rw-r--r-- | die.cpp | 5 | ||||
| -rw-r--r-- | die.h | 10 | ||||
| -rw-r--r-- | highlightdice.cpp | 24 | ||||
| -rw-r--r-- | highlightdice.h | 14 | ||||
| -rw-r--r-- | result/diceresult.cpp | 5 |
8 files changed, 117 insertions, 22 deletions
diff --git a/cli/main.cpp b/cli/main.cpp index dee3d05..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<ExportedDiceResult> list; + QList<ExportedDiceResult> listFull; bool homogeneous = true; parser.getLastDiceResult(list,homogeneous); + parser.getDiceResultFromAllInstruction(listFull); bool allSameFaceCount, allSameColor; auto array = DisplayToolBox::diceToJson(list,allSameFaceCount,allSameColor); QString resultStr; @@ -242,6 +244,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,13 +265,48 @@ 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: "<<key; + auto dice = map[key]; + QString stringVal; + for(auto val : dice) + { + qint64 total=0; + QStringList dicelist; + for(auto score: val.getResult()) + { + total += score; + dicelist << QString::number(score); + } + if(val.getResult().size() > 1) + { + stringVal=QString("%1 [%2]").arg(total).arg(dicelist.join(',')); + listOfDiceResult << stringVal; + } + else + { + listOfDiceResult << QString::number(total); + } + } + } + } + } + qDebug() << listOfDiceResult; if(parser.hasStringResult()) { bool ok; 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(); @@ -277,6 +315,12 @@ int startDiceParsing(QStringList& cmds,QString& treeFile,bool withColor, EXPORTF stringResult.replace(QStringLiteral("$%1").arg(i),(*it)); --i; } + i = listFull.size(); + 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 6108eb8..3e90fe8 100644 --- a/diceparser.cpp +++ b/diceparser.cpp @@ -492,6 +492,36 @@ QStringList DiceParser::getAllDiceResult(bool& hasAlias) return stringListResult; } + +void DiceParser::getDiceResultFromAllInstruction(QList<ExportedDiceResult>& resultList) +{ + 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<DiceResult*>(result); + QList<HighLightDice> 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<int>(faces),list); + } + result = result->getPrevious(); + } + resultList.append(nodeResult); + } +} + void DiceParser::getLastDiceResult(QList<ExportedDiceResult>& diceValuesList,bool& homogeneous) { for(auto start : m_startNodes) @@ -499,7 +529,6 @@ void DiceParser::getLastDiceResult(QList<ExportedDiceResult>& diceValuesList,boo ExportedDiceResult diceValues; ExecutionNode* next = getLeafNode(start); Result* result=next->getResult(); - while(nullptr!=result) { if(result->hasResultOfType(Result::DICE_LIST)) @@ -529,8 +558,7 @@ void DiceParser::getLastDiceResult(QList<ExportedDiceResult>& diceValuesList,boo valuesResult.append(i); } } - HighLightDice hlDice(valuesResult,die->isHighlighted(),die->getColor()); - //QPair<QList<quint64>,bool> pair(valuesResult,die->isHighlighted()); + HighLightDice hlDice(valuesResult,die->isHighlighted(),die->getColor(), die->hasBeenDisplayed(),0); listpair.append(hlDice); } } 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<ExportedDiceResult>& diceValues,bool& homogeneous); + void getLastDiceResult(QList<ExportedDiceResult>& diceValues, bool& homogeneous); /** * @brief hasIntegerResultNotInFirst * @return @@ -219,6 +219,7 @@ public: bool readOptionFromNull(QString &str, ExecutionNode *&node); bool readInstructionList(QString &str); + void getDiceResultFromAllInstruction(QList<ExportedDiceResult> &resultList); protected: bool readParameterNode(QString &str, ExecutionNode *&node); private: @@ -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) { @@ -135,12 +135,12 @@ public: void setOp(const Die::ArithmeticOperator &op); private: - qint64 m_value; + qint64 m_value = 0; QList<qint64> 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; 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<qint64> result,bool isHighlighted, QString color) - : m_result(result),m_hasHighlight(isHighlighted),m_color(color) +HighLightDice::HighLightDice(QList<qint64> 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<qint64> result,bool isHighlighted, QString color); + HighLightDice(QList<qint64> result,bool isHighlighted, QString color, bool displayed,quint64 faces); virtual ~HighLightDice(); - - QList<qint64> getResult() const; void setResult(const QList<qint64> &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<qint64> m_result; - bool m_hasHighlight; + bool m_hasHighlight = true; QString m_color; + bool m_displayed = false; + quint64 m_faces; }; #endif // HighLightDice_H 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<int>(pow(static_cast<double>(scalar),static_cast<double>(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 |