diff options
| -rw-r--r-- | cli/main.cpp | 33 | ||||
| -rw-r--r-- | diceparser.cpp | 29 | ||||
| -rw-r--r-- | node/repeaternode.cpp | 37 | ||||
| -rw-r--r-- | parsingtoolbox.cpp | 39 |
4 files changed, 74 insertions, 64 deletions
diff --git a/cli/main.cpp b/cli/main.cpp index 004e187..8362cdb 100644 --- a/cli/main.cpp +++ b/cli/main.cpp @@ -171,25 +171,27 @@ void displayMarkdown(QString scalarText, QString resultStr, QJsonArray array, bo QString displaySVG(QString scalarText, QString resultStr, QJsonArray array, bool withColor, QString cmd, QString error, QString warning, QString comment, bool allSameFaceCount, bool allSameColor) { - QString str( - "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<svg version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" " - "xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n"); + QString str("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<svg version=\"1.1\" " + "xmlns=\"http://www.w3.org/2000/svg\" " + "xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n"); if(!error.isEmpty()) { - str.append( - QStringLiteral("<text font-size=\"16\" x=\"0\" y=\"20\"><tspan fill=\"red\">%1</tspan></text>").arg(error)); + str.append(QStringLiteral("<text font-size=\"16\" x=\"0\" y=\"20\"><tspan " + "fill=\"red\">%1</tspan></text>") + .arg(error)); } else { if(!warning.isEmpty()) - str.append( - QStringLiteral("<text font-size=\"16\" x=\"0\" y=\"20\"><tspan fill=\"orange\">%1</tspan></text>") - .arg(warning)); + str.append(QStringLiteral("<text font-size=\"16\" x=\"0\" y=\"20\"><tspan " + "fill=\"orange\">%1</tspan></text>") + .arg(warning)); int y= 20; if(!comment.isEmpty()) { - str.append(QStringLiteral("<text font-size=\"16\" x=\"0\" y=\"%2\"><tspan fill=\"blue\">%1</tspan></text>") + str.append(QStringLiteral("<text font-size=\"16\" x=\"0\" y=\"%2\"><tspan " + "fill=\"blue\">%1</tspan></text>") .arg(comment) .arg(y)); y+= 20; @@ -198,7 +200,8 @@ QString displaySVG(QString scalarText, QString resultStr, QJsonArray array, bool if(resultStr.isEmpty()) { if(withColor) - str.append(QStringLiteral("<text font-size=\"16\" x=\"0\" y=\"%4\"><tspan fill=\"red\">%1</tspan>\n" + str.append(QStringLiteral("<text font-size=\"16\" x=\"0\" y=\"%4\"><tspan " + "fill=\"red\">%1</tspan>\n" "<tspan x=\"0\" y=\"%5\">details:</tspan>[%3 (%2)]</text>") .arg(scalarText) .arg(diceList) @@ -286,6 +289,7 @@ int startDiceParsing(QStringList& cmds, QString& treeFile, bool withColor, EXPOR int rt= 0; bool in_markdown= true; + for(QString cmd : cmds) { if(cmd.startsWith('&') && format == BOT) @@ -527,7 +531,8 @@ int main(int argc, char* argv[]) "The output is formatted in json."); QCommandLineOption dotFile(QStringList() << "d" << "dot-file", - "Instead of rolling dice, generate the execution tree and write it in <dotfile>", + "Instead of rolling dice, generate the execution tree and write it in " + "<dotfile>", "dotfile"); QCommandLineOption translation(QStringList() << "t" << "translation", @@ -599,6 +604,9 @@ int main(int argc, char* argv[]) } QStringList cmdList= optionParser.positionalArguments(); + cmdList.append("repeat(2d6c[<4];1d6;2d6c[<4];\"échecs: $1 [@1], succès $3 [@3], le dé " + "de balance: $2\",5)"); + if(!cmdList.isEmpty()) { if(cmdList[0].startsWith('&')) @@ -606,7 +614,8 @@ int main(int argc, char* argv[]) colorb= false; } } - // cmdList << "8d10;\$1c[>6];\$1c[=1];\$2-\$3i:[>0]{\"%3 Success[%2]\"}{i:[<0]{\"Critical fail %3 [%2]\"}{\"Fail %3 + // cmdList << "8d10;\$1c[>6];\$1c[=1];\$2-\$3i:[>0]{\"%3 + // Success[%2]\"}{i:[<0]{\"Critical fail %3 [%2]\"}{\"Fail %3 // [%2]\"}}"; QJsonArray aliases; if(optionParser.isSet(alias)) diff --git a/diceparser.cpp b/diceparser.cpp index 44a725a..e32d9e8 100644 --- a/diceparser.cpp +++ b/diceparser.cpp @@ -258,36 +258,7 @@ bool DiceParser::hasDiceResult() const } bool DiceParser::hasStringResult() const { - bool result= false; - for(auto node : m_parsingToolbox->getStartNodes()) - { - QVariant var; - result|= hasResultOfType(Dice::RESULT_TYPE::STRING, node, var); - } - return result; -} -bool DiceParser::hasResultOfType(Dice::RESULT_TYPE type, ExecutionNode* node, QVariant& value, bool notthelast) -{ - bool scalarDone= false; - ExecutionNode* next= ParsingToolBox::getLeafNode(node); - Result* result= next->getResult(); - while((result != nullptr) && (!scalarDone)) - { - bool lastResult= false; - if(notthelast) - lastResult= (nullptr == result->getPrevious()); - - if(result->hasResultOfType(type) && !lastResult) - { - scalarDone= true; - value= result->getResult(type); - } - result= result->getPrevious(); - } - return scalarDone; -======= return m_parsingToolbox->hasStringResult(); ->>>>>>> Rework exporting } int DiceParser::startNodeCount() const diff --git a/node/repeaternode.cpp b/node/repeaternode.cpp index e5e5c81..93d946b 100644 --- a/node/repeaternode.cpp +++ b/node/repeaternode.cpp @@ -26,6 +26,29 @@ #include "parsingtoolbox.h" #include "result/stringresult.h" +using InstructionSet= std::vector<ExecutionNode*>; + +QStringList allFirstResultAsString(std::vector<InstructionSet> startingNodes, bool& hasAlias) +{ + // QStringList allResult; + QStringList stringListResult; + for(auto node : startingNodes) + { + QVariant var; + if(ParsingToolBox::hasResultOfType(Dice::RESULT_TYPE::STRING, node, var)) + { + stringListResult << var.toString(); + hasAlias= true; + } + else if(hasResultOfType(Dice::RESULT_TYPE::SCALAR, node, var, true)) + { + stringListResult << QString::number(var.toReal()); + hasAlias= true; + } + } + return stringListResult; +} + std::vector<ExecutionNode*> makeCopy(std::vector<ExecutionNode*> cmds) { std::vector<ExecutionNode*> copy; @@ -46,11 +69,16 @@ void RepeaterNode::run(ExecutionNode* previousNode) m_times->run(this); m_times= ParsingToolBox::getLeafNode(m_times); auto times= m_times->getResult(); + if(!times) + return; + + std::vector<InstructionSet> m_startingNodes; auto timeCount= times->getResult(Dice::RESULT_TYPE::SCALAR).toInt(); auto cmd= makeCopy(m_cmd); std::vector<Result*> resultVec; for(int i= 0; i < timeCount; ++i) { + m_startingNodes.push_back(cmd); std::for_each(cmd.begin(), cmd.end(), [this, &resultVec](ExecutionNode* node) { node->run(this); auto end= ParsingToolBox::getLeafNode(node); @@ -74,9 +102,10 @@ void RepeaterNode::run(ExecutionNode* previousNode) } else { - auto string= new StringResult(); - QStringList list; - std::for_each(resultVec.begin(), resultVec.end(), [&list](Result* result) { + auto list= allFirstResultAsString(m_startingNodes, true); + // auto string= new StringResult(); + // QStringList list; + /*std::for_each(resultVec.begin(), resultVec.end(), [&list](Result* result) { auto value= result->getResult(Dice::RESULT_TYPE::SCALAR).toDouble(); auto diceList= result->getResult(Dice::RESULT_TYPE::DICE_LIST).value<QList<Die*>>(); auto string= result->getResult(Dice::RESULT_TYPE::STRING).toString(); @@ -103,7 +132,7 @@ void RepeaterNode::run(ExecutionNode* previousNode) }); string->addText(list.join('\n')); string->finished(); - m_result= string; + m_result= string;*/ } if(nullptr != m_nextNode) diff --git a/parsingtoolbox.cpp b/parsingtoolbox.cpp index af89aaf..8261d8a 100644 --- a/parsingtoolbox.cpp +++ b/parsingtoolbox.cpp @@ -1323,29 +1323,30 @@ void ParsingToolBox::readSubtitutionParameters(SubtituteInfo& info, QString& res bool ParsingToolBox::readReaperArguments(RepeaterNode* node, QString& source) { - if(readOpenParentheses(source)) + if(!readOpenParentheses(source)) + return false; + + auto instructions= readInstructionList(source, false); + if(instructions.empty()) + return false; + + readComma(source); + ExecutionNode* tmp; + if(readOperand(source, tmp)) { - auto instructions= readInstructionList(source, false); - if(!instructions.empty()) + if(source.startsWith("+")) { - readComma(source); - ExecutionNode* tmp; - if(readOperand(source, tmp)) - { - if(source.startsWith("+")) - { - node->setSumAll(true); - source= source.remove(0, 1); - } - if(readCloseParentheses(source)) - { - node->setCommand(instructions); - node->setTimeNode(tmp); - return true; - } - } + node->setSumAll(true); + source= source.remove(0, 1); + } + if(readCloseParentheses(source)) + { + node->setCommand(instructions); + node->setTimeNode(tmp); + return true; } } + return false; } bool ParsingToolBox::readExpression(QString& str, ExecutionNode*& node) |