diff options
| author | 2018-12-19 23:40:23 +0100 | |
|---|---|---|
| committer | 2018-12-19 23:40:23 +0100 | |
| commit | 1eb8c0de4e7a2ff7c9ea1d3e2091524a5e67ad25 (patch) | |
| tree | 55e014b57135e85511c6a2adafb90e42aae94eca | |
| parent | 517dcb09609999dd96390a7db1690a35bf39508f (diff) | |
| parent | 747ad7d4edca9a37a94603cb25253ebf6833eee0 (diff) | |
| download | OneRoll-1eb8c0de4e7a2ff7c9ea1d3e2091524a5e67ad25.tar.gz OneRoll-1eb8c0de4e7a2ff7c9ea1d3e2091524a5e67ad25.zip | |
Merge branch 'master' of github.com:Rolisteam/DiceParser
| -rw-r--r-- | HelpMe.md | 5 | ||||
| -rw-r--r-- | dicealias.cpp | 2 | ||||
| -rw-r--r-- | diceparser.cpp | 106 | ||||
| -rw-r--r-- | diceparser.h | 2 |
4 files changed, 12 insertions, 103 deletions
@@ -678,9 +678,10 @@ There are two kinds of macro: normal ones and regular-expression-based. The first kind the conversion it is just a replacement. -> !macro k d10e10k +> !macro k d10e10k 0 The user input (8k4) becomes 8d10e10k4 (l5r system). As you can see the k has been replaced by the macro value. +The third parameter 0 describes this macro as a simple replacement. The third parameter is mandatory. In more complexe situations, control/change some parts inside the command can be achieved by using regular-expression based macro. @@ -689,8 +690,6 @@ In more complexe situations, control/change some parts inside the command can be The 1 at the end means "this command has regular-expression". The user input (8w6) becomes 8d10e10c[>=6]-@c[=1] (old world of darkness system). -**ATTENTION**: the system does not support space character into command. Use _ instead for the moment. - ## Remove macro > !macro rm 0 diff --git a/dicealias.cpp b/dicealias.cpp index 5730187..cc06510 100644 --- a/dicealias.cpp +++ b/dicealias.cpp @@ -26,8 +26,6 @@ QString makeReplament(const QString& pattern, const QString& replacement, QString cmd) { - - // FIXME try to do the same with RegularExpression auto hasPattern = cmd.contains(pattern); if(hasPattern) { diff --git a/diceparser.cpp b/diceparser.cpp index 7210d8c..79e31f5 100644 --- a/diceparser.cpp +++ b/diceparser.cpp @@ -181,6 +181,9 @@ bool DiceParser::parseLine(QString str, bool allowAlias) m_warningMap.insert(ExecutionNode::UNEXPECTED_CHARACTER,QObject::tr("Unexpected character at %1 - end of command was ignored \"%2\"").arg(i).arg(str)); } + if(!m_errorMap.isEmpty()) + value = false; + return value; } @@ -320,99 +323,6 @@ void DiceParser::start() } } -QString DiceParser::displayResult() -{ - QStringList resultList; - for(auto start : m_startNodes) - { - ExecutionNode* next = start; - int nodeCount=0; - int resulCount=0; - while(nullptr != next->getNextNode() ) - { - next = next->getNextNode(); - ++nodeCount; - } - ////////////////////////////////// - // - // Display - // - ////////////////////////////////// - - QString str; - QTextStream stream(&str); - Result* result=next->getResult(); - - QString totalValue("you got %1 ;"); - QString dieValue("D%1 : {%2} "); - - bool scalarDone=false; - while(nullptr!=result) - { - ++resulCount; - if((result->hasResultOfType(Result::SCALAR))&&(!scalarDone)) - { - stream << totalValue.arg(result->getResult(Result::SCALAR).toReal()) << endl; //.arg(m_command) - scalarDone=true; - } - else if(result->hasResultOfType(Result::DICE_LIST)) - { - - DiceResult* myDiceResult = dynamic_cast<DiceResult*>(result); - if(nullptr!=myDiceResult) - { - - QString resulStr; - quint64 face=0; - for(Die* die : myDiceResult->getResultList()) - { - if(!die->hasBeenDisplayed()) - { - resulStr+=QStringLiteral("%1").arg(die->getValue()); - die->displayed(); - face = die->getFaces(); - - - if(die->hasChildrenValue()) - { - resulStr+=QStringLiteral(" ["); - for(qint64 i : die->getListValue()) - { - resulStr+=QStringLiteral("%1 ").arg(i); - } - resulStr.remove(resulStr.size()-1,1); - resulStr+=QStringLiteral("]"); - } - resulStr+=QStringLiteral(", "); - } - } - resulStr.remove(resulStr.size()-2,2); - - if(!resulStr.isEmpty()) - { - stream << dieValue.arg(face).arg(resulStr); - } - - } - } - else if(result->hasResultOfType(Result::STRING)) - { - stream << result->getResult(Result::STRING).toString(); - } - - result = result->getPrevious(); - } - - QTextStream out(stdout); - out << str << "you rolled: " <<m_command << endl; - out << endl; - - - resultList << QStringLiteral("%1, you rolled:%3").arg(str.simplified()).arg(m_command) ; - } - - return resultList.join('\n'); -} QList<qreal> DiceParser::getLastIntegerResults() { QList<qreal> resultValues; @@ -548,7 +458,7 @@ void DiceParser::getDiceResultFromAllInstruction(QList<ExportedDiceResult>& resu HighLightDice hlDice(die->getListValue(),die->isHighlighted(),die->getColor(), die->hasBeenDisplayed(),die->getFaces()); list.append(hlDice); } - nodeResult.insert(static_cast<int>(faces),list); + nodeResult.insert(faces,list); } result = result->getPrevious(); } @@ -660,7 +570,7 @@ bool DiceParser::hasResultOfType(Result::RESULT_TYPE type, ExecutionNode* node, Result* result=next->getResult(); while((result!=nullptr)&&(!scalarDone)) { - if(result->hasResultOfType(type) && ((!notthelast)||(notthelast && (nullptr!=result->getPrevious())))) + if(result->hasResultOfType(type) && ((!notthelast)||(nullptr!=result->getPrevious()))) { scalarDone=true; } @@ -699,7 +609,7 @@ QList<qreal> DiceParser::getSumOfDiceResult() } int DiceParser::getStartNodeCount() const { - return m_startNodes.size(); + return static_cast<int>(m_startNodes.size()); } ExecutionNode* DiceParser::getLeafNode(ExecutionNode* start) { @@ -812,6 +722,7 @@ bool DiceParser::readCommand(QString& str,ExecutionNode* & node) { if(str== QLatin1String("help")) { + str=str.remove(0,QLatin1String("help").size()); HelpNode* help = new HelpNode(); if(!m_helpPath.isEmpty()) { @@ -822,6 +733,7 @@ bool DiceParser::readCommand(QString& str,ExecutionNode* & node) } else if(str== QLatin1String("la")) { + str=str.remove(0,QLatin1String("la").size()); node = new ListAliasNode(m_aliasList); } return true; @@ -1053,7 +965,7 @@ bool DiceParser::readOption(QString& str,ExecutionNode* previous)//, DiceRollerNode* nodeTmp = dynamic_cast<DiceRollerNode*>(previous); if(nullptr!=nodeTmp) { - previous = addExplodeDiceNode(nodeTmp->getFaces(),previous); + previous = addExplodeDiceNode(static_cast<qint64>(nodeTmp->getFaces()),previous); } node = m_parsingToolbox->addSort(previous,ascending); diff --git a/diceparser.h b/diceparser.h index 8d06b44..0305dc7 100644 --- a/diceparser.h +++ b/diceparser.h @@ -36,7 +36,7 @@ #include "highlightdice.h" typedef QList<HighLightDice > ListDiceResult; -typedef QMap<int,ListDiceResult > ExportedDiceResult; +typedef QMap<quint64,ListDiceResult > ExportedDiceResult; class ExplodeDiceNode; /** |