diff options
| -rw-r--r-- | README.md | 94 | ||||
| -rw-r--r-- | cli/main.cpp | 44 | ||||
| -rw-r--r-- | diceparser.cpp | 36 | ||||
| -rw-r--r-- | diceparser.h | 3 | ||||
| -rw-r--r-- | die.cpp | 8 | ||||
| -rw-r--r-- | die.h | 10 | ||||
| -rw-r--r-- | highlightdice.cpp | 24 | ||||
| -rw-r--r-- | highlightdice.h | 14 | ||||
| -rw-r--r-- | node/keepdiceexecnode.cpp | 6 | ||||
| -rw-r--r-- | operationcondition.cpp | 2 | ||||
| -rw-r--r-- | result/diceresult.cpp | 5 | ||||
| -rw-r--r-- | result/diceresult.h | 1 |
12 files changed, 181 insertions, 66 deletions
@@ -1,9 +1,61 @@ - -[](http://www.rolisteam.org) +[](http://www.rolisteam.org) # DiceParser -Rolisteam Dice Parser +Rolisteam Dice Parser run dice commands. It is available on several platforms. +The syntax is simple and powerful. + +[Full documentation here](https://github.com/Rolisteam/DiceParser/blob/master/HelpMe.md) + + +## [Invite to Your Discord Server](https://discordapp.com/oauth2/authorize?&client_id=279722369260453888&scope=bot&permissions=0) + +[](https://discordbots.org/bot/279722369260453888) + + +## Features + +* `99.9%` uptime +* Roll any kind of dice +* Customizable prefix +* Custom alias/macro to improve game experience +* Manage colorized dice +* Many operators + +## Examples: + +### 3D100 +Roll 3 dice with 100 faces + +### 10D10e[=10]s +Roll 10 dice with 10 faces, 10 explodes, and sort the result. + +### 100291D66666666s +roll 100291 dice with 66666666666 faces and sort result + +### 15D10c[>7] +roll 15 dice with 10 faces and it counts number of dice which are above 7 + +### 1D8+2D6+7 +roll 1 die with 8 faces and add the result to 2 dice with 6 faces and add 7. + +### D25 +roll 1 die with 25 faces + +### 88-1D20 +88 minus the value of 1 die of 20 faces + +### 8+8+8 +compute: 24 + + + +### 100/28*3 +compute: 100/28 = 3 +3*3 = 9 + + +More examples at : https://github.com/Rolisteam/DiceParser/blob/master/HelpMe.md ## Grammar The grammar is something like this: @@ -50,39 +102,3 @@ Parenthese =: (expression) Count =: c Validator ``` - -## Example: - - -### 3D100 -Roll 3 dice with 100 faces - -### 10D10e[=10]s -Roll 10 dice with 10 faces, 10 explodes, and sort the result. - -### 100291D66666666s -roll 100291 dice with 66666666666 faces and sort result - -### 15D10c[>7] -roll 15 dice with 10 faces and it counts number of dice which are above 7 - -### 1D8+2D6+7 -roll 1 die with 8 faces and add the result to 2 dice with 6 faces and add 7. - -### D25 -roll 1 die with 25 faces - -### 88-1D20 -88 minus the value of 1 die of 20 faces - -### 8+8+8 -compute: 24 - - - -### 100/28*3 -compute: 100/28 = 3 -3*3 = 9 - - -More examples at : https://github.com/Rolisteam/DiceParser/blob/master/HelpMe.md 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 41a91e5..3e90fe8 100644 --- a/diceparser.cpp +++ b/diceparser.cpp @@ -24,6 +24,7 @@ #include <QStringList> #include <QObject> #include <QFile> +#include <functional> #include "node/startingnode.h" #include "node/scalaroperatornode.h" @@ -48,7 +49,6 @@ #include "node/variablenode.h" #include "node/bind.h" - #define DEFAULT_FACES_NUMBER 10 DiceParser::DiceParser() @@ -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) { @@ -108,6 +103,9 @@ qint64 Die::getValue() const //error(); } break; + case POW: + value=static_cast<qint64>(std::pow(value,tmp)); + break; } } else @@ -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/node/keepdiceexecnode.cpp b/node/keepdiceexecnode.cpp index 347931d..dbd1591 100644 --- a/node/keepdiceexecnode.cpp +++ b/node/keepdiceexecnode.cpp @@ -51,7 +51,7 @@ void KeepDiceExecNode::run(ExecutionNode* previous) m_numberOfDice = diceList.size() + m_numberOfDice; } - QList<Die*> diceList3= diceList.mid(0,m_numberOfDice); + QList<Die*> diceList3= diceList.mid(0,static_cast<int>(m_numberOfDice)); QList<Die*> diceList2; for(Die* die : diceList3) @@ -64,12 +64,12 @@ void KeepDiceExecNode::run(ExecutionNode* previous) - if(m_numberOfDice > static_cast<quint64>(diceList.size())) + if(m_numberOfDice > static_cast<qint64>(diceList.size())) { m_errors.insert(TOO_MANY_DICE,QObject::tr(" You ask to keep %1 dice but the result only has %2").arg(m_numberOfDice).arg(diceList.size())); } - for(Die* tmp : diceList.mid(m_numberOfDice,-1)) + for(Die* tmp : diceList.mid(static_cast<int>(m_numberOfDice),-1)) { tmp->setHighlighted(false); } diff --git a/operationcondition.cpp b/operationcondition.cpp index 2a83fec..6b4e819 100644 --- a/operationcondition.cpp +++ b/operationcondition.cpp @@ -108,7 +108,7 @@ QString OperationCondition::toString() } return QStringLiteral("[%1%2%3]").arg(str).arg(valueToScalar()).arg(m_boolean->toString()); } -bool OperationCondition::isValidRangeSize(std::pair<qint64,qint64> range) const +bool OperationCondition::isValidRangeSize(std::pair<qint64,qint64>) const { auto value = valueToScalar(); bool valid = true; 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 diff --git a/result/diceresult.h b/result/diceresult.h index 8ff041f..8ea807a 100644 --- a/result/diceresult.h +++ b/result/diceresult.h @@ -22,6 +22,7 @@ #ifndef DICERESULT_H #define DICERESULT_H #include <QList> +#include <functional> #include "die.h" #include "result.h" |