From f2051fb35b1ad49c4d940e6fbba2acc98b216e13 Mon Sep 17 00:00:00 2001 From: Renaud G Date: Tue, 12 Feb 2019 23:59:24 +0100 Subject: clang format --- cli/displaytoolbox.cpp | 233 +++++++++++++++-------------- cli/displaytoolbox.h | 14 +- cli/main.cpp | 393 ++++++++++++++++++++++++++++--------------------- 3 files changed, 351 insertions(+), 289 deletions(-) (limited to 'cli') diff --git a/cli/displaytoolbox.cpp b/cli/displaytoolbox.cpp index 3c1048f..3474cf9 100644 --- a/cli/displaytoolbox.cpp +++ b/cli/displaytoolbox.cpp @@ -1,12 +1,12 @@ #include "displaytoolbox.h" -#include -#include #include +#include +#include #ifdef PAINTER_OP +#include #include #include -#include //#include #endif @@ -14,211 +14,209 @@ #define LINE_SPACING 5 -DisplayToolBox::DisplayToolBox() -{ - -} +DisplayToolBox::DisplayToolBox() {} #ifdef PAINTER_OP -QString DisplayToolBox::makeImage(QString scalarText, QString resultStr,QJsonArray array, bool withColor, QString cmd, QString comment, bool allSameFaceCount,bool allSameColor) +QString DisplayToolBox::makeImage(QString scalarText, QString resultStr, QJsonArray array, bool withColor, QString cmd, + QString comment, bool allSameFaceCount, bool allSameColor) { - //qDebug() <<"scarlarText:" <textTotal.size()) + if(comment.size() > textTotal.size()) { textTotal.prepend(QStringLiteral("%1\n").arg(comment)); } - QFont font("Helvetica", 15); //QFontDatabase::systemFont(QFontDatabase::GeneralFont); + QFont font("Helvetica", 15); // QFontDatabase::systemFont(QFontDatabase::GeneralFont); QFontMetrics fm(font); - QRect rect = fm.boundingRect(textTotal); + QRect rect= fm.boundingRect(textTotal); - QImage img(rect.width(),(rect.height()+LINE_SPACING)*lineCount,QImage::Format_ARGB32); - img.fill(QColor(255,255,255,100)); + QImage img(rect.width(), (rect.height() + LINE_SPACING) * lineCount, QImage::Format_ARGB32); + img.fill(QColor(255, 255, 255, 100)); QPainter painter(&img); painter.setFont(font); - int y = rect.height(); + int y= rect.height(); if(!comment.isEmpty()) { - QPen pen = painter.pen(); + QPen pen= painter.pen(); pen.setColor(Qt::black); painter.setPen(pen); - painter.drawText(QPoint(0,y),comment); - y += rect.height()+LINE_SPACING; + painter.drawText(QPoint(0, y), comment); + y+= rect.height() + LINE_SPACING; } if(!resultStr.isEmpty()) { - QPen pen = painter.pen(); + QPen pen= painter.pen(); pen.setColor(Qt::black); painter.setPen(pen); - painter.drawText(QPoint(0,y),resultStr); + painter.drawText(QPoint(0, y), resultStr); } else { painter.save(); - QPen pen = painter.pen(); + QPen pen= painter.pen(); pen.setColor(Qt::red); painter.setPen(pen); - painter.drawText(QPoint(5,y),scalarText); - y += rect.height()+LINE_SPACING; + painter.drawText(QPoint(5, y), scalarText); + y+= rect.height() + LINE_SPACING; painter.restore(); - int x = 5; - QString text=QStringLiteral("Details:[%1 (").arg(cmd); - painter.drawText(QPoint(x,y),text); - x += fm.boundingRect(text).width(); + int x= 5; + QString text= QStringLiteral("Details:[%1 (").arg(cmd); + painter.drawText(QPoint(x, y), text); + x+= fm.boundingRect(text).width(); if(allSameFaceCount) { - int i = 0; + int i= 0; for(auto item : array) { QStringList result; - bool last = (array.size()-1==i); - auto obj = item.toObject(); + bool last= (array.size() - 1 == i); + auto obj= item.toObject(); auto values= obj["values"].toArray(); for(auto valRef : values) { result.append(diceResultToString(valRef.toObject())); } painter.save(); - QPen pen = painter.pen(); + QPen pen= painter.pen(); QColor color; - auto colorStr = obj["color"].toString(); + auto colorStr= obj["color"].toString(); if(colorStr.isEmpty()) - color = QColor(Qt::black); + color= QColor(Qt::black); else color.setNamedColor(colorStr); pen.setColor(color); painter.setPen(pen); - text = QStringLiteral("%1").arg(result.join(',')); + text= QStringLiteral("%1").arg(result.join(',')); if(!last) { text.append(","); } - painter.drawText(QPoint(x,y),text); - x += fm.boundingRect(text).width(); + painter.drawText(QPoint(x, y), text); + x+= fm.boundingRect(text).width(); painter.restore(); ++i; } } else { - int i = 0; + int i= 0; for(auto item : array) { QStringList result; - auto obj = item.toObject(); - bool last = (array.size()-1==i); + auto obj= item.toObject(); + bool last= (array.size() - 1 == i); auto values= obj["values"].toArray(); for(auto valRef : values) { result.append(diceResultToString(valRef.toObject())); } - text =QStringLiteral("d%1:(").arg(obj["face"].toInt()); - painter.drawText(QPoint(x,y),text); - x += fm.boundingRect(text).width(); + text= QStringLiteral("d%1:(").arg(obj["face"].toInt()); + painter.drawText(QPoint(x, y), text); + x+= fm.boundingRect(text).width(); painter.save(); - QPen pen = painter.pen(); + QPen pen= painter.pen(); QColor color; - auto colorStr = obj["color"].toString(); + auto colorStr= obj["color"].toString(); if(colorStr.isEmpty()) - color = QColor(Qt::black); + color= QColor(Qt::black); else color.setNamedColor(colorStr); - + pen.setColor(color); painter.setPen(pen); - text = QStringLiteral("%1").arg(result.join(',')); - painter.drawText(QPoint(x,y),text); - x += fm.boundingRect(text).width(); + text= QStringLiteral("%1").arg(result.join(',')); + painter.drawText(QPoint(x, y), text); + x+= fm.boundingRect(text).width(); painter.restore(); painter.save(); - text = QStringLiteral(")"); + text= QStringLiteral(")"); if(!last) { text.append(","); } - painter.drawText(QPoint(x,y),text); - x += fm.boundingRect(text).width(); + painter.drawText(QPoint(x, y), text); + x+= fm.boundingRect(text).width(); painter.restore(); ++i; } } - text = QStringLiteral(")"); - x += fm.boundingRect(text).width(); - painter.drawText(QPoint(x,y),text); + text= QStringLiteral(")"); + x+= fm.boundingRect(text).width(); + painter.drawText(QPoint(x, y), text); } painter.end(); - img.save("/home/renaud/image.png","PNG"); + img.save("/home/renaud/image.png", "PNG"); QByteArray ba; QBuffer buffer(&ba); buffer.open(QIODevice::WriteOnly); img.save(&buffer, "PNG"); - //return {}; + // return {}; return ba.toBase64(); } #endif QString DisplayToolBox::colorToTermCode(QString str) { - if(str.isEmpty()|| str==QStringLiteral("black")) + if(str.isEmpty() || str == QStringLiteral("black")) { return QStringLiteral("\e[0;31m"); } - else if(str==QStringLiteral("white")) + else if(str == QStringLiteral("white")) { - return QStringLiteral("\e[97m"); + return QStringLiteral("\e[97m"); } - else if(str==QStringLiteral("blue")) + else if(str == QStringLiteral("blue")) { - return QStringLiteral("\e[34m"); + return QStringLiteral("\e[34m"); } - else if(str==QStringLiteral("red")) + else if(str == QStringLiteral("red")) { - return QStringLiteral("\e[31m"); + return QStringLiteral("\e[31m"); } - else if(str==QStringLiteral("black")) + else if(str == QStringLiteral("black")) { - return QStringLiteral("\e[30m"); + return QStringLiteral("\e[30m"); } - else if(str==QStringLiteral("green")) + else if(str == QStringLiteral("green")) { - return QStringLiteral("\e[32m"); + return QStringLiteral("\e[32m"); } - else if(str==QStringLiteral("yellow")) + else if(str == QStringLiteral("yellow")) { - return QStringLiteral("\e[33m"); + return QStringLiteral("\e[33m"); } - else if(str==QStringLiteral("reset")) + else if(str == QStringLiteral("reset")) { - return QStringLiteral("\e[0m"); + return QStringLiteral("\e[0m"); } return {}; } -QString DisplayToolBox::diceToSvg(QJsonArray array,bool withColor,bool allSameColor,bool allSameFaceCount ) +QString DisplayToolBox::diceToSvg(QJsonArray array, bool withColor, bool allSameColor, bool allSameFaceCount) { Q_UNUSED(allSameColor) if(allSameFaceCount) @@ -227,7 +225,7 @@ QString DisplayToolBox::diceToSvg(QJsonArray array,bool withColor,bool allSameCo for(auto item : array) { QStringList subResult; - auto obj = item.toObject(); + auto obj= item.toObject(); auto values= obj["values"].toArray(); for(auto valRef : values) { @@ -252,7 +250,7 @@ QString DisplayToolBox::diceToSvg(QJsonArray array,bool withColor,bool allSameCo for(auto item : array) { QStringList subResult; - auto obj = item.toObject(); + auto obj= item.toObject(); auto values= obj["values"].toArray(); for(auto valRef : values) @@ -277,67 +275,66 @@ QString DisplayToolBox::diceToSvg(QJsonArray array,bool withColor,bool allSameCo return result.join(""); } } -QJsonArray DisplayToolBox::diceToJson(QList& diceList,bool& allSameFaceCount,bool& allSameColor) +QJsonArray DisplayToolBox::diceToJson(QList& diceList, bool& allSameFaceCount, bool& allSameColor) { - allSameFaceCount = true; - allSameColor = true; + allSameFaceCount= true; + allSameColor= true; QJsonArray array; for(auto dice : diceList) { - if(dice.size()>1) + if(dice.size() > 1) { - allSameFaceCount = false; + allSameFaceCount= false; } - for(int face: dice.keys()) + for(int face : dice.keys()) { - ListDiceResult diceResults = dice.value(face); + ListDiceResult diceResults= dice.value(face); std::vector alreadyDoneColor; std::vector> sameColorDice; - for(auto & diceResult : diceResults) + for(auto& diceResult : diceResults) { if(!diceResult.getColor().isEmpty()) { - allSameColor = false; + allSameColor= false; } - auto it=std::find_if(alreadyDoneColor.begin(), alreadyDoneColor.end(),[diceResult](QString color){ - return color == diceResult.getColor(); - }); + auto it= std::find_if(alreadyDoneColor.begin(), alreadyDoneColor.end(), + [diceResult](QString color) { return color == diceResult.getColor(); }); - if( it == alreadyDoneColor.end()) + if(it == alreadyDoneColor.end()) { sameColorDice.push_back(std::vector()); alreadyDoneColor.push_back(diceResult.getColor()); - it = alreadyDoneColor.end(); + it= alreadyDoneColor.end(); --it; } - auto i = std::distance(alreadyDoneColor.begin(), it); + auto i= std::distance(alreadyDoneColor.begin(), it); sameColorDice[static_cast(i)].push_back(diceResult); } - int i = 0; - for(auto it = alreadyDoneColor.begin() ; it != alreadyDoneColor.end() && i < sameColorDice.size() ; ++it) + int i= 0; + for(auto it= alreadyDoneColor.begin(); it != alreadyDoneColor.end() && i < sameColorDice.size(); ++it) { - auto list = sameColorDice[static_cast(i)]; + auto list= sameColorDice[static_cast(i)]; QJsonObject object; - object["color"]=*it; - object["face"]=face; + object["color"]= *it; + object["face"]= face; QJsonArray values; for(auto const& dice : list) { QJsonObject diceObj; - auto listValues = dice.getResult(); + auto listValues= dice.getResult(); if(!listValues.isEmpty()) { - diceObj["total"]=static_cast(listValues.takeFirst()); + diceObj["total"]= static_cast(listValues.takeFirst()); QJsonArray subValues; for(auto result : listValues) { subValues.push_back(static_cast(result)); } - diceObj["subvalues"]=subValues; + diceObj["subvalues"]= subValues; } values.push_back(diceObj); } - object["values"]=values; + object["values"]= values; ++i; array.push_back(object); } @@ -347,8 +344,8 @@ QJsonArray DisplayToolBox::diceToJson(QList& diceList,bool& } QString DisplayToolBox::diceResultToString(QJsonObject val) { - auto total = QString::number(val["total"].toDouble()); - auto subvalues = val["subvalues"].toArray(); + auto total= QString::number(val["total"].toDouble()); + auto subvalues= val["subvalues"].toArray(); QStringList subStr; for(auto subval : subvalues) { @@ -360,45 +357,45 @@ QString DisplayToolBox::diceResultToString(QJsonObject val) } return total; } -QString DisplayToolBox::diceToText(QJsonArray array, bool withColor,bool allSameFaceCount, bool allSameColor) +QString DisplayToolBox::diceToText(QJsonArray array, bool withColor, bool allSameFaceCount, bool allSameColor) { Q_UNUSED(allSameColor) QStringList result; for(auto item : array) { QString subResult(""); - auto obj = item.toObject(); + auto obj= item.toObject(); auto values= obj["values"].toArray(); QStringList diceResult; for(auto valRef : values) { - diceResult += diceResultToString(valRef.toObject()); + diceResult+= diceResultToString(valRef.toObject()); } - if (!diceResult.isEmpty()) + if(!diceResult.isEmpty()) { if(!allSameFaceCount) { - subResult += QStringLiteral("d%1:(").arg(obj["face"].toInt()); + subResult+= QStringLiteral("d%1:(").arg(obj["face"].toInt()); } if(withColor) { - subResult += DisplayToolBox::colorToTermCode(obj["color"].toString()); + subResult+= DisplayToolBox::colorToTermCode(obj["color"].toString()); } - subResult += diceResult.join(" "); + subResult+= diceResult.join(" "); if(withColor) { - subResult += DisplayToolBox::colorToTermCode(QStringLiteral("reset")); + subResult+= DisplayToolBox::colorToTermCode(QStringLiteral("reset")); } if(!allSameFaceCount) { - subResult += QStringLiteral(")"); + subResult+= QStringLiteral(")"); } } - if (!subResult.isEmpty()) + if(!subResult.isEmpty()) { - result += subResult; + result+= subResult; } } return result.join(" - "); diff --git a/cli/displaytoolbox.h b/cli/displaytoolbox.h index e256be1..34859e9 100644 --- a/cli/displaytoolbox.h +++ b/cli/displaytoolbox.h @@ -1,8 +1,8 @@ #ifndef GENERATEIMAGE_H #define GENERATEIMAGE_H -#include #include +#include #include "diceparser.h" @@ -10,15 +10,15 @@ class DisplayToolBox { public: DisplayToolBox(); - #ifdef PAINTER_OP - static QString makeImage(QString scalarText, QString resultStr,QJsonArray array, bool withColor, QString cmd, QString comment, bool allSameFaceCount,bool allSameColor); - #endif +#ifdef PAINTER_OP + static QString makeImage(QString scalarText, QString resultStr, QJsonArray array, bool withColor, QString cmd, + QString comment, bool allSameFaceCount, bool allSameColor); +#endif static QString colorToTermCode(QString str); - static QString diceToText(QJsonArray array, bool withColor,bool allSameFaceCount, bool allSameColor); - static QJsonArray diceToJson(QList &diceList, bool &allSameFaceCount, bool &allSameColor); + static QString diceToText(QJsonArray array, bool withColor, bool allSameFaceCount, bool allSameColor); + static QJsonArray diceToJson(QList& diceList, bool& allSameFaceCount, bool& allSameColor); static QString diceToSvg(QJsonArray array, bool withColor, bool allSameColor, bool allSameFaceCount); static QString diceResultToString(QJsonObject val); }; - #endif // GENERATEIMAGE_H diff --git a/cli/main.cpp b/cli/main.cpp index edefd27..e261d63 100644 --- a/cli/main.cpp +++ b/cli/main.cpp @@ -1,33 +1,33 @@ /*************************************************************************** -* Copyright (C) 2014 by Renaud Guezennec * -* http://www.rolisteam.org/contact * -* * -* This file is part of DiceParser * -* * -* DiceParser is free software; you can redistribute it and/or modify * -* it under the terms of the GNU General Public License as published by * -* the Free Software Foundation; either version 2 of the License, or * -* (at your option) any later version. * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU General Public License * -* along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ + * Copyright (C) 2014 by Renaud Guezennec * + * http://www.rolisteam.org/contact * + * * + * This file is part of DiceParser * + * * + * DiceParser is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ -#include -#include #include -#include +#include +#include #include -#include #include -#include +#include +#include +#include #ifdef PAINTER_OP #include @@ -35,8 +35,8 @@ #include #endif -#include "displaytoolbox.h" #include "diceparser.h" +#include "displaytoolbox.h" #include "highlightdice.h" /** @@ -54,23 +54,37 @@ QTextStream out(stdout, QIODevice::WriteOnly); QTextStream err(stderr, QIODevice::WriteOnly); -bool markdown = false; +bool markdown= false; #ifdef PAINTER_OP -enum EXPORTFORMAT {TERMINAL, SVG, IMAGE, MARKDOWN, JSON, BOT}; +enum EXPORTFORMAT +{ + TERMINAL, + SVG, + IMAGE, + MARKDOWN, + JSON, + BOT +}; #else -enum EXPORTFORMAT {TERMINAL, SVG, MARKDOWN, JSON, BOT}; +enum EXPORTFORMAT +{ + TERMINAL, + SVG, + MARKDOWN, + JSON, + BOT +}; #endif -int returnValue = 0; - +int returnValue= 0; -QString diceToMarkdown(QJsonArray array,bool withColor,bool allSameColor,bool allSameFaceCount ) +QString diceToMarkdown(QJsonArray array, bool withColor, bool allSameColor, bool allSameFaceCount) { if(allSameFaceCount) { QStringList result; for(auto item : array) { - auto obj = item.toObject(); + auto obj= item.toObject(); auto values= obj["values"].toArray(); for(auto val : values) { @@ -85,7 +99,7 @@ QString diceToMarkdown(QJsonArray array,bool withColor,bool allSameColor,bool al for(auto item : array) { QStringList subResult; - auto obj = item.toObject(); + auto obj= item.toObject(); auto values= obj["values"].toArray(); for(auto val : values) { @@ -94,35 +108,38 @@ QString diceToMarkdown(QJsonArray array,bool withColor,bool allSameColor,bool al result.append(QStringLiteral("d%1:(").arg(obj["face"].toString())); result.append(subResult.join(',')); result.append(QStringLiteral(")")); - } return result.join(' '); } } #ifdef PAINTER_OP -void displayImage(QString scalarText, QString resultStr,QJsonArray array, bool withColor, QString cmd, QString comment, bool allSameFaceCount,bool allSameColor) +void displayImage(QString scalarText, QString resultStr, QJsonArray array, bool withColor, QString cmd, QString comment, + bool allSameFaceCount, bool allSameColor) { - out << DisplayToolBox::makeImage( scalarText, resultStr, array, withColor, cmd, comment, allSameFaceCount, allSameColor); + out << DisplayToolBox::makeImage( + scalarText, resultStr, array, withColor, cmd, comment, allSameFaceCount, allSameColor); } #endif -void displayJSon(QString scalarText, QString resultStr,QJsonArray array, bool withColor, QString cmd, QString error, QString warning, QString comment, bool allSameFaceCount,bool allSameColor) +void displayJSon(QString scalarText, QString resultStr, QJsonArray array, bool withColor, QString cmd, QString error, + QString warning, QString comment, bool allSameFaceCount, bool allSameColor) { Q_UNUSED(withColor); QJsonDocument doc; QJsonObject obj; - obj["values"]=array; - obj["comment"]=comment; - obj["error"]=error; - obj["scalar"]=scalarText; - obj["string"]=resultStr; - obj["allSameFace"]=allSameFaceCount; - obj["allSameColor"]=allSameColor; - obj["warning"]=warning; - obj["command"]=cmd; + obj["values"]= array; + obj["comment"]= comment; + obj["error"]= error; + obj["scalar"]= scalarText; + obj["string"]= resultStr; + obj["allSameFace"]= allSameFaceCount; + obj["allSameColor"]= allSameColor; + obj["warning"]= warning; + obj["command"]= cmd; doc.setObject(obj); out << doc.toJson() << "\n"; } -void displayMarkdown(QString scalarText, QString resultStr,QJsonArray array, bool withColor, QString cmd, QString error, QString warning, QString comment, bool allSameFaceCount,bool allSameColor) +void displayMarkdown(QString scalarText, QString resultStr, QJsonArray array, bool withColor, QString cmd, + QString error, QString warning, QString comment, bool allSameFaceCount, bool allSameColor) { Q_UNUSED(withColor); QString str("```Markdown\n"); @@ -139,50 +156,67 @@ void displayMarkdown(QString scalarText, QString resultStr,QJsonArray array, boo { str.prepend(QStringLiteral("%1\n").arg(comment)); } - auto diceList = DisplayToolBox::diceToText(array,false,allSameFaceCount,allSameColor); + auto diceList= DisplayToolBox::diceToText(array, false, allSameFaceCount, allSameColor); if(resultStr.isEmpty()) { - str.append(QStringLiteral("# %1\nDetails:[%3 (%2)]\n").arg(scalarText).arg(diceList).arg(cmd)); + str.append(QStringLiteral("# %1\nDetails:[%3 (%2)]\n").arg(scalarText).arg(diceList).arg(cmd)); } else if(!resultStr.isEmpty()) { - resultStr.replace("%2",diceList.trimmed()); + resultStr.replace("%2", diceList.trimmed()); str.append(QStringLiteral("%1\n").arg(resultStr)); } } str.append(QStringLiteral("```")); out << str; } -void displaySVG(QString scalarText, QString resultStr,QJsonArray array, bool withColor, QString cmd, QString error, QString warning, QString comment, bool allSameFaceCount,bool allSameColor) +void displaySVG(QString scalarText, QString resultStr, QJsonArray array, bool withColor, QString cmd, QString error, + QString warning, QString comment, bool allSameFaceCount, bool allSameColor) { - QString str("\n\n"); + QString str( + "\n\n"); if(!error.isEmpty()) { - str.append(QStringLiteral("%1").arg(error)); + str.append( + QStringLiteral("%1").arg(error)); } else { if(!warning.isEmpty()) - str.append(QStringLiteral("%1").arg(warning)); + str.append( + QStringLiteral("%1") + .arg(warning)); - int y = 20; + int y= 20; if(!comment.isEmpty()) { - str.append(QStringLiteral("%1").arg(comment).arg(y)); - y+=20; + str.append(QStringLiteral("%1") + .arg(comment) + .arg(y)); + y+= 20; } - auto diceList = DisplayToolBox::diceToSvg(array,withColor,allSameColor,allSameFaceCount); + auto diceList= DisplayToolBox::diceToSvg(array, withColor, allSameColor, allSameFaceCount); if(resultStr.isEmpty()) { if(withColor) - str.append(QStringLiteral("%1 details:[%3 (%2)]").arg(scalarText).arg(diceList).arg(cmd).arg(y)); + str.append(QStringLiteral( + "%1 details:[%3 (%2)]") + .arg(scalarText) + .arg(diceList) + .arg(cmd) + .arg(y)); else - str.append(QStringLiteral("%1 details:[%3 (%2)]").arg(scalarText).arg(diceList).arg(cmd).arg(y)); + str.append( + QStringLiteral("%1 details:[%3 (%2)]") + .arg(scalarText) + .arg(diceList) + .arg(cmd) + .arg(y)); } else if(!resultStr.isEmpty()) { - resultStr.replace("%2",diceList.trimmed()); + resultStr.replace("%2", diceList.trimmed()); str.append(QStringLiteral("%1").arg(resultStr).arg(y)); } } @@ -190,7 +224,8 @@ void displaySVG(QString scalarText, QString resultStr,QJsonArray array, bool wit out << str << "\n"; } -void displayCommandResult(QString scalarText, QString resultStr,QJsonArray array, bool withColor, QString cmd, QString error, QString warning, QString comment, bool allSameFaceCount,bool allSameColor) +void displayCommandResult(QString scalarText, QString resultStr, QJsonArray array, bool withColor, QString cmd, + QString error, QString warning, QString comment, bool allSameFaceCount, bool allSameColor) { // TODO display warning if(!error.isEmpty()) @@ -200,21 +235,21 @@ void displayCommandResult(QString scalarText, QString resultStr,QJsonArray array } if(!warning.isEmpty()) - err << "Warning: "<< warning << "\n"; + err << "Warning: " << warning << "\n"; QString str; - auto diceList = DisplayToolBox::diceToText(array,withColor,allSameFaceCount,allSameColor); + auto diceList= DisplayToolBox::diceToText(array, withColor, allSameFaceCount, allSameColor); if(withColor) - str = QString("Result: \e[0;31m%1\e[0m - details:[%3 (%2)]").arg(scalarText).arg(diceList).arg(cmd); + str= QString("Result: \e[0;31m%1\e[0m - details:[%3 (%2)]").arg(scalarText).arg(diceList).arg(cmd); else - str = QString("Result: %1 - details:[%3 (%2)]").arg(scalarText).arg(diceList).arg(cmd); + str= QString("Result: %1 - details:[%3 (%2)]").arg(scalarText).arg(diceList).arg(cmd); if(!resultStr.isEmpty()) { - resultStr.replace("%2",diceList.trimmed()); - str = resultStr; + resultStr.replace("%2", diceList.trimmed()); + str= resultStr; } if(!comment.isEmpty()) @@ -224,21 +259,22 @@ void displayCommandResult(QString scalarText, QString resultStr,QJsonArray array out << str << "\n"; } -int startDiceParsing(QStringList& cmds,QString& treeFile,bool withColor, EXPORTFORMAT format, QJsonArray array) +int startDiceParsing(QStringList& cmds, QString& treeFile, bool withColor, EXPORTFORMAT format, QJsonArray array) { DiceParser parser; - parser.insertAlias(new DiceAlias("L5R5R",QStringLiteral("L[-,⨀,⨀⬢,❂⬢,❁,❁⬢]")),0); - parser.insertAlias(new DiceAlias("L5R5S",QStringLiteral("L[-,-,⨀,⨀,⨀❁,⨀⬢,⨀⬢,❂,❂⬢,❁,❁,❁]")),1); - int i = 2; + parser.insertAlias(new DiceAlias("L5R5R", QStringLiteral("L[-,⨀,⨀⬢,❂⬢,❁,❁⬢]")), 0); + parser.insertAlias(new DiceAlias("L5R5S", QStringLiteral("L[-,-,⨀,⨀,⨀❁,⨀⬢,⨀⬢,❂,❂⬢,❁,❁,❁]")), 1); + int i= 2; for(auto alias : array) { - auto objAlias = alias.toObject(); - auto dice = new DiceAlias(objAlias["pattern"].toString(),objAlias["cmd"].toString(),!objAlias["regexp"].toBool()); + auto objAlias= alias.toObject(); + auto dice + = new DiceAlias(objAlias["pattern"].toString(), objAlias["cmd"].toString(), !objAlias["regexp"].toBool()); dice->setComment(objAlias["comment"].toString()); - parser.insertAlias(dice,i++); + parser.insertAlias(dice, i++); } - int rt=0; + int rt= 0; for(QString cmd : cmds) { if(parser.parseLine(cmd)) @@ -246,39 +282,39 @@ int startDiceParsing(QStringList& cmds,QString& treeFile,bool withColor, EXPORTF parser.start(); QList list; QList listFull; - bool homogeneous = true; - parser.getLastDiceResult(list,homogeneous); + bool homogeneous= true; + parser.getLastDiceResult(list, homogeneous); parser.getDiceResultFromAllInstruction(listFull); bool allSameFaceCount, allSameColor; - auto array = DisplayToolBox::diceToJson(list,allSameFaceCount,allSameColor); + auto array= DisplayToolBox::diceToJson(list, allSameFaceCount, allSameColor); QString resultStr; QString scalarText; QString lastScalarText; - QString comment = parser.getComment(); - QString error = parser.humanReadableError(); - QString warnings = parser.humanReadableWarning(); + QString comment= parser.getComment(); + QString error= parser.humanReadableError(); + QString warnings= parser.humanReadableWarning(); QStringList strLst; QStringList listOfDiceResult; - QString cmdRework = parser.getDiceCommand(); + QString cmdRework= parser.getDiceCommand(); if(parser.hasIntegerResultNotInFirst()) { - auto values = parser.getLastIntegerResults(); - for(auto val : values ) + auto values= parser.getLastIntegerResults(); + for(auto val : values) { strLst << QString::number(val); } - scalarText = QString("%1").arg(strLst.join(',')); - lastScalarText = strLst.last(); + scalarText= QString("%1").arg(strLst.join(',')); + lastScalarText= strLst.last(); } else if(!list.isEmpty()) { - auto values = parser.getSumOfDiceResult(); - for(auto val : values ) + auto values= parser.getSumOfDiceResult(); + for(auto val : values) { strLst << QString::number(val); } - scalarText = QString("%1").arg(strLst.join(',')); + scalarText= QString("%1").arg(strLst.join(',')); } if(!list.isEmpty()) { @@ -286,23 +322,23 @@ int startDiceParsing(QStringList& cmds,QString& treeFile,bool withColor, EXPORTF { for(auto key : map.keys()) { - auto dice = map[key]; + auto dice= map[key]; QString stringVal; for(auto val : dice) { - qint64 total=0; + qint64 total= 0; QStringList dicelist; - for(auto score: val.getResult()) + for(auto score : val.getResult()) { - total += score; - dicelist << QString::number(score); + total+= score; + dicelist << QString::number(score); } if(val.getResult().size() > 1) { - stringVal=QString("%1 [%2]").arg(total).arg(dicelist.join(',')); + stringVal= QString("%1 [%2]").arg(total).arg(dicelist.join(',')); listOfDiceResult << stringVal; } - else + else { listOfDiceResult << QString::number(total); } @@ -314,68 +350,73 @@ int startDiceParsing(QStringList& cmds,QString& treeFile,bool withColor, EXPORTF if(parser.hasStringResult()) { bool ok; - QStringList allStringlist = parser.getAllStringResult(ok); - QString stringResult = allStringlist.join(" ; "); - stringResult.replace("%1",scalarText); - stringResult.replace("%2",listOfDiceResult.join(",").trimmed()); - stringResult.replace("%3",lastScalarText); + QStringList allStringlist= parser.getAllStringResult(ok); + QString stringResult= allStringlist.join(" ; "); + stringResult.replace("%1", scalarText); + stringResult.replace("%2", listOfDiceResult.join(",").trimmed()); + stringResult.replace("%3", lastScalarText); stringResult.replace("\\n", "\n"); - int i = strLst.size(); - for(auto it = strLst.rbegin(); it != strLst.rend() ; ++it) + int i= strLst.size(); + for(auto it= strLst.rbegin(); it != strLst.rend(); ++it) { - stringResult.replace(QStringLiteral("$%1").arg(i),(*it)); + stringResult.replace(QStringLiteral("$%1").arg(i), (*it)); --i; } - i = listFull.size(); - for(auto it = strLst.rbegin(); it != strLst.rend() ; ++it) + i= listFull.size(); + for(auto it= strLst.rbegin(); it != strLst.rend(); ++it) { - stringResult.replace(QStringLiteral("µ%1").arg(i),(*it)); + stringResult.replace(QStringLiteral("µ%1").arg(i), (*it)); --i; } - resultStr = stringResult; + resultStr= stringResult; } if(format == BOT) { if(allSameColor) { - format = MARKDOWN; + format= MARKDOWN; } else { - #ifdef PAINTER_OP - format = IMAGE; - #else - format = MARKDOWN; - #endif +#ifdef PAINTER_OP + format= IMAGE; +#else + format= MARKDOWN; +#endif } if(!error.isEmpty()) { - format = MARKDOWN; + format= MARKDOWN; } } switch(format) { - case TERMINAL: - displayCommandResult(scalarText, resultStr, array, withColor, cmdRework, error,warnings, comment, allSameFaceCount, allSameColor); + case TERMINAL: + displayCommandResult(scalarText, resultStr, array, withColor, cmdRework, error, warnings, comment, + allSameFaceCount, allSameColor); break; - case SVG: - displaySVG(scalarText, resultStr, array, withColor, cmdRework, error,warnings, comment, allSameFaceCount, allSameColor); + case SVG: + displaySVG(scalarText, resultStr, array, withColor, cmdRework, error, warnings, comment, + allSameFaceCount, allSameColor); break; - case BOT: - case MARKDOWN: - displayMarkdown(scalarText, resultStr, array, withColor, cmdRework, error,warnings, comment, allSameFaceCount, allSameColor); + case BOT: + case MARKDOWN: + displayMarkdown(scalarText, resultStr, array, withColor, cmdRework, error, warnings, comment, + allSameFaceCount, allSameColor); break; - case JSON: - displayJSon(scalarText, resultStr, array, withColor, cmdRework, error,warnings, comment, allSameFaceCount, allSameColor); + case JSON: + displayJSon(scalarText, resultStr, array, withColor, cmdRework, error, warnings, comment, + allSameFaceCount, allSameColor); break; - #ifdef PAINTER_OP - case IMAGE: - displayImage(scalarText, resultStr, array, withColor, cmdRework, comment, allSameFaceCount, allSameColor); +#ifdef PAINTER_OP + case IMAGE: + displayImage( + scalarText, resultStr, array, withColor, cmdRework, comment, allSameFaceCount, allSameColor); break; - #endif +#endif } if(!treeFile.isEmpty()) { @@ -384,19 +425,19 @@ int startDiceParsing(QStringList& cmds,QString& treeFile,bool withColor, EXPORTF if(!error.isEmpty()) { - rt = 1; + rt= 1; } } else { - rt = 1; + rt= 1; } } return rt; } #include -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { #ifdef PAINTER_OP QGuiApplication a(argc, argv); @@ -408,23 +449,45 @@ int main(int argc, char *argv[]) QString cmd; QString dotFileStr; QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8")); - bool colorb=true; + bool colorb= true; out.setCodec("UTF-8"); - EXPORTFORMAT format = TERMINAL; + EXPORTFORMAT format= TERMINAL; QCommandLineParser optionParser; - QCommandLineOption color(QStringList() << "c"<< "color-off", "Disable color to highlight result"); - QCommandLineOption version(QStringList() << "v"<< "version", "Show the version and quit."); + QCommandLineOption color(QStringList() << "c" + << "color-off", + "Disable color to highlight result"); + QCommandLineOption version(QStringList() << "v" + << "version", + "Show the version and quit."); QCommandLineOption reset(QStringList() << "reset-settings", "Erase the settings and use the default parameters"); - QCommandLineOption alias(QStringList() << "a" << "alias", "path to alias json files: ","aliasfile"); - QCommandLineOption character(QStringList() << "s" << "charactersheet", "set Parameters to simulate character sheet: ","sheetfile"); - QCommandLineOption markdown(QStringList() << "m" <<"markdown", "The output is formatted in markdown."); - QCommandLineOption bot(QStringList() << "b" <<"bot", "Discord bot."); - QCommandLineOption svg(QStringList() << "g" <<"svg", "The output is formatted in svg."); - QCommandLineOption json(QStringList() << "j" <<"json", "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"); - QCommandLineOption translation(QStringList() << "t"<<"translation", "path to the translation file: ","translationfile"); - QCommandLineOption help(QStringList() << "h"<<"help", "Display this help"); + QCommandLineOption alias(QStringList() << "a" + << "alias", + "path to alias json files: ", "aliasfile"); + QCommandLineOption character(QStringList() << "s" + << "charactersheet", + "set Parameters to simulate character sheet: ", "sheetfile"); + QCommandLineOption markdown(QStringList() << "m" + << "markdown", + "The output is formatted in markdown."); + QCommandLineOption bot(QStringList() << "b" + << "bot", + "Discord bot."); + QCommandLineOption svg(QStringList() << "g" + << "svg", + "The output is formatted in svg."); + QCommandLineOption json(QStringList() << "j" + << "json", + "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"); + QCommandLineOption translation(QStringList() << "t" + << "translation", + "path to the translation file: ", "translationfile"); + QCommandLineOption help(QStringList() << "h" + << "help", + "Display this help"); optionParser.addOption(color); optionParser.addOption(version); @@ -438,7 +501,7 @@ int main(int argc, char *argv[]) optionParser.addOption(json); optionParser.addOption(translation); optionParser.addOption(help); - for(int i=0;i6];\$1c[=1];\$2-\$3i:[>0]{\"%3 Success[%2]\"}{i:[<0]{\"Critical fail %3 [%2]\"}{\"Fail %3 [%2]\"}}"; + QStringList cmdList= optionParser.positionalArguments(); + // cmdList << "8d10;\$1c[>6];\$1c[=1];\$2-\$3i:[>0]{\"%3 Success[%2]\"}{i:[<0]{\"Critical fail %3 [%2]\"}{\"Fail %3 + // [%2]\"}}"; QString aliasstr; QJsonArray aliases; if(optionParser.isSet(alias)) { - aliasstr = optionParser.value(alias); + aliasstr= optionParser.value(alias); QFile file(aliasstr); - + if(file.open(QIODevice::ReadOnly)) { - QJsonDocument doc = QJsonDocument::fromJson(file.readAll()); - aliases = doc.array(); + QJsonDocument doc= QJsonDocument::fromJson(file.readAll()); + aliases= doc.array(); } - } - returnValue = startDiceParsing(cmdList,dotFileStr,colorb,format,aliases); + returnValue= startDiceParsing(cmdList, dotFileStr, colorb, format, aliases); if(optionParser.isSet(help)) { out << optionParser.helpText(); -- cgit v1.2.3-70-g09d2