diff options
| author | 2016-02-04 17:58:00 +0100 | |
|---|---|---|
| committer | 2016-02-04 17:58:00 +0100 | |
| commit | c671d21b54d43dbd6112f3ab50fc6ebd63dc4aef (patch) | |
| tree | 34ad9a7a84e0e71cb45f8b381eccae431ca39d25 | |
| parent | c796cef9dbbf48dcaf21dc4f4ea62db2ba4fe629 (diff) | |
| download | OneRoll-c671d21b54d43dbd6112f3ab50fc6ebd63dc4aef.tar.gz OneRoll-c671d21b54d43dbd6112f3ab50fc6ebd63dc4aef.zip | |
Add Management of Color
| -rw-r--r-- | CMakeLists.txt | 2 | ||||
| -rw-r--r-- | cli/main.cpp | 110 | ||||
| -rw-r--r-- | diceparser.cpp | 17 | ||||
| -rw-r--r-- | diceparser.h | 7 | ||||
| -rw-r--r-- | die.cpp | 10 | ||||
| -rw-r--r-- | die.h | 3 | ||||
| -rw-r--r-- | node/helpnode.h | 2 | ||||
| -rw-r--r-- | node/ifnode.cpp | 11 | ||||
| -rw-r--r-- | node/ifnode.h | 4 | ||||
| -rw-r--r-- | parsingtoolbox.cpp | 21 | ||||
| -rw-r--r-- | parsingtoolbox.h | 3 |
11 files changed, 86 insertions, 104 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index cc9a6ef..8306d1a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,12 +50,14 @@ add_executable( node/listsetrollnode.cpp node/numbernode.cpp node/parenthesesnode.cpp + node/paintnode.cpp node/rerolldicenode.cpp node/scalaroperatornode.cpp node/sortresult.cpp node/startingnode.cpp node/ifnode.cpp cli/main.cpp + highlightdice.cpp ) #add_executable(dice cli/main.cpp) diff --git a/cli/main.cpp b/cli/main.cpp index dd21ea7..21bb1ca 100644 --- a/cli/main.cpp +++ b/cli/main.cpp @@ -25,6 +25,7 @@ #include <QCommandLineParser> #include <QCommandLineOption> #include <QTextStream> +#include "highlightdice.h" /** * @page Dice @@ -51,20 +52,31 @@ QString diceToText(ExportedDiceResult& dice,bool highlight,bool homogeneous) QStringList result; ListDiceResult diceResult = dice.value(face); //patternColor = patternColorarg(); - foreach (DiceAndHighlight tmp, diceResult) + foreach (HighLightDice tmp, diceResult) { QStringList diceListStr; QStringList diceListChildren; - for(int i =0; i < tmp.first.size(); ++i) + for(int i =0; i < tmp.getResult().size(); ++i) { - qint64 dievalue = tmp.first[i]; + qint64 dievalue = tmp.getResult()[i]; QString prefix("%1"); - if((tmp.second)&&(highlight)) + if((tmp.isHighlighted())&&(highlight)) { - prefix = "\e[0;31m%1\e[0m"; + if(tmp.getColor().isEmpty()|| tmp.getColor()=="black") + { + prefix = "\e[0;31m%1\e[0m"; + } + if(tmp.getColor()=="white") + { + prefix = "\e[97m%1\e[0m"; + } + if(tmp.getColor()=="blue") + { + prefix = "\e[34m%1\e[0m"; + } } if(i==0) @@ -94,51 +106,6 @@ QString diceToText(ExportedDiceResult& dice,bool highlight,bool homogeneous) resultGlobal << result; } } - /* } - else - { - foreach(int face, dice.keys()) - { - QStringList result; - ListDiceResult diceResult = dice.value(face); - foreach (DiceAndHighlight tmp, diceResult) - { - QStringList diceListStr; - QStringList diceListChildren; - - - for(int i =0; i < tmp.first.size(); ++i) - { - qint64 dievalue = tmp.first[i]; - QString prefix("%1"); - - if((tmp.second)&&(highlight)) - { - prefix = "\e[0;31m%1\e[0m"; - } - - if(i==0) - { - diceListStr << prefix.arg(QString::number(dievalue)); - } - else - { - diceListChildren << prefix.arg(QString::number(dievalue)); - } - } - if(!diceListChildren.isEmpty()) - { - diceListStr << QString("[%1]").arg(diceListChildren.join(' ')); - } - - result << diceListStr.join(' '); - // qDebug() << result << tmp.first << tmp.second; - } - - resultGlobal << QString(" (%1) ").arg(result.join(',')); - - } - }*/ return resultGlobal.join(' '); } @@ -301,46 +268,5 @@ int main(int argc, char *argv[]) } } - /*commands<< "10d10c[>6]+@c[=10]" - << "1L[cheminée,chocolat,épée,arc,chute de pierre]" - << "10d10c[>=6]-@c[=1]" - << "10d10c[>=6]-@c[=1]-@c[=1]" - << "10d10c[>6]+@c[=10]" - << "1+1D10" - << "3d10c[>=5]" - << "3nwod" - << "1+(4*3)D10" - << "2+4/4" - << "2D10*2D20*8" - <<"1+(4*3)D10" - <<"(4D6)D10" - << "1D100a[>=95]a[>=96]a[>=97]a[>=98]a[>=99]e[>=100]" - << "3D100" - << "4k3" - << "10D10e[>=6]sc[>=6]" - << "100190D6666666s" - << "10D10e10s" - << "10D10s" - << "15D10e10c[8-10]" - << "10d10e11" - << "1D8+2D6+7" - << "100190D6666666s" - << "D25" - << "D25+D10" - << "D25;D10" - << "8+8+8" - << "1D20-88" - << "100*1D20*2D6" - << "100/28*3" - << "100/8" - << "100*3*8" - << "help" - << "la" - << "400000D20/400000" - << "100*3*8";// -*/ - - - - return 0; + return 0; } diff --git a/diceparser.cpp b/diceparser.cpp index 98a8d29..ba75b01 100644 --- a/diceparser.cpp +++ b/diceparser.cpp @@ -40,6 +40,7 @@ #include "node/listaliasnode.h" #include "node/mergenode.h" #include "node/ifnode.h" +#include "node/paintnode.h" #define DEFAULT_FACES_NUMBER 10 @@ -61,7 +62,9 @@ DiceParser::DiceParser() m_OptionOp->insert(QStringLiteral("r"),Reroll); m_OptionOp->insert(QStringLiteral("e"),Explosing); m_OptionOp->insert(QStringLiteral("a"),RerollAndAdd); + m_OptionOp->insert(QStringLiteral("m"),Merge); m_OptionOp->insert(QStringLiteral("i"),ifOperator); + m_OptionOp->insert(QStringLiteral("p"),Painter); m_aliasList = new QList<DiceAlias*>(); @@ -476,8 +479,9 @@ void DiceParser::getLastDiceResult(ExportedDiceResult& diceValues,bool& homogene valuesResult.append(i); } } - QPair<QList<quint64>,bool> pair(valuesResult,die->isHighlighted()); - listpair.append(pair); + HighLightDice hlDice(valuesResult,die->isHighlighted(),die->getColor()); + //QPair<QList<quint64>,bool> pair(valuesResult,die->isHighlighted()); + listpair.append(hlDice); } } if(!listpair.isEmpty()) @@ -946,6 +950,15 @@ bool DiceParser::readOption(QString& str,ExecutionNode* previous, bool hasDice)/ } break; + case Painter: + { + PainterNode* painter = new PainterNode(); + m_parsingToolbox->readPainterParameter(painter,str); + previous->setNextNode(painter); + node = painter; + isFine = true; + } + break; case ifOperator: { IfNode* nodeif = new IfNode(); diff --git a/diceparser.h b/diceparser.h index e1a5ee5..15a8a84 100644 --- a/diceparser.h +++ b/diceparser.h @@ -33,10 +33,9 @@ #include "booleancondition.h" #include "parsingtoolbox.h" #include "dicealias.h" +#include "highlightdice.h" - -typedef QPair<QList<quint64>,bool> DiceAndHighlight; -typedef QList<DiceAndHighlight > ListDiceResult; +typedef QList<HighLightDice > ListDiceResult; typedef QMap<int,ListDiceResult > ExportedDiceResult; class ExploseDiceNode; @@ -77,7 +76,7 @@ public: /** * @brief The OptionOperator enum gathering all options availables for result. */ - enum OptionOperator {KeepAndExplose,Keep,Reroll,Explosing,Sort,Count,RerollAndAdd,Merge,ifOperator}; + enum OptionOperator {KeepAndExplose,Keep,Reroll,Explosing,Sort,Count,RerollAndAdd,Merge,ifOperator,Painter}; /** * @brief The CommandOperator enum */ @@ -149,3 +149,13 @@ void Die::setBase(qint64 base) { m_base = base; } +QString Die::getColor() const +{ + return m_color; +} + +void Die::setColor(const QString &color) +{ + m_color = color; +} + @@ -125,6 +125,9 @@ public: */ void setBase(qint64); + QString getColor() const; + void setColor(const QString &color); + private: qint64 m_value; QList<qint64> m_rollResult; diff --git a/node/helpnode.h b/node/helpnode.h index ba59f1f..14edde4 100644 --- a/node/helpnode.h +++ b/node/helpnode.h @@ -1,6 +1,6 @@ /*************************************************************************** * Copyright (C) 2015 by Renaud Guezennec * - * http://renaudguezennec.homelinux.org/accueil,3.html * + * http:://www.rolisteam.org/contact * * * * rolisteam is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * diff --git a/node/ifnode.cpp b/node/ifnode.cpp index 864faf1..a8982a8 100644 --- a/node/ifnode.cpp +++ b/node/ifnode.cpp @@ -106,9 +106,16 @@ void IfNode::setInstructionFalse(ExecutionNode* node) m_false = node; } -QString IfNode::toString(bool) const +QString IfNode::toString(bool wl) const { - + if(wl) + { + return QString("%1 [label=\"IfNode\"]").arg(m_id); + } + else + { + return m_id; + } } qint64 IfNode::getPriority() const diff --git a/node/ifnode.h b/node/ifnode.h index 6f8bbcf..5872f79 100644 --- a/node/ifnode.h +++ b/node/ifnode.h @@ -1,6 +1,6 @@ /*************************************************************************** - * Copyright (C) 2016 by Renaud Guezennec * - * http://renaudguezennec.homelinux.org/accueil,3.html * + * Copyright (C) 2015 by Renaud Guezennec * + * http:://www.rolisteam.org/contact * * * * rolisteam is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * diff --git a/parsingtoolbox.cpp b/parsingtoolbox.cpp index d396d9c..5e26af3 100644 --- a/parsingtoolbox.cpp +++ b/parsingtoolbox.cpp @@ -406,6 +406,27 @@ ParsingToolBox::LIST_OPERATOR ParsingToolBox::readListOperator(QString& str) return NONE; } +void ParsingToolBox::readPainterParameter(PainterNode* painter,QString& str) +{ + if(str.startsWith('[')) + { + str=str.remove(0,1); + int pos = str.indexOf(']'); + if(pos>-1) + { + QString data = str.left(pos); + QStringList duos = data.split(','); + foreach(QString duoStr,duos) + { + QStringList keyValu = duoStr.split(':'); + if(keyValu.size()==2) + { + painter->insertColorItem(keyValu[1],keyValu[0].toInt()); + } + } + } + } +} void ParsingToolBox::readProbability(QStringList& str,QList<Range>& ranges) { diff --git a/parsingtoolbox.h b/parsingtoolbox.h index 1af0efd..8c80d13 100644 --- a/parsingtoolbox.h +++ b/parsingtoolbox.h @@ -31,7 +31,7 @@ #include "compositevalidator.h" #include "range.h" #include "node/scalaroperatornode.h" - +#include "node/paintnode.h" /** * @brief The ParsingToolBox is gathering many useful methods for dice parsing. * Its goal is to make the diceparser a bit lighter. @@ -148,6 +148,7 @@ public: bool readArithmeticOperator(QString& str, ScalarOperatorNode::ArithmeticOperator& op); + void readPainterParameter(PainterNode *painter, QString &str); private: QMap<QString,BooleanCondition::LogicOperator>* m_logicOp; QMap<QString,CompositeValidator::LogicOperation>* m_logicOperation; |