diff options
| author | 2016-11-03 17:36:21 +0100 | |
|---|---|---|
| committer | 2016-11-03 17:36:21 +0100 | |
| commit | 9d389e561339e4fd7a68d60f593ad233e3941d13 (patch) | |
| tree | 39e98d9d3a612be9c6cf449f5a7a5dfdf4593865 | |
| parent | 120add8ca2f3a7e075b415a611bcd09034bd6200 (diff) | |
| download | OneRoll-9d389e561339e4fd7a68d60f593ad233e3941d13.tar.gz OneRoll-9d389e561339e4fd7a68d60f593ad233e3941d13.zip | |
-Add FilterNode to dice system.
| -rw-r--r-- | diceparser.cpp | 25 | ||||
| -rw-r--r-- | diceparser.h | 2 | ||||
| -rw-r--r-- | diceparser.pri | 6 | ||||
| -rw-r--r-- | node/filternode.cpp | 70 | ||||
| -rw-r--r-- | node/filternode.h | 30 | ||||
| -rw-r--r-- | parsingtoolbox.cpp | 1 | ||||
| -rw-r--r-- | result/stringresult.cpp | 19 | ||||
| -rw-r--r-- | result/stringresult.h | 1 |
8 files changed, 141 insertions, 13 deletions
diff --git a/diceparser.cpp b/diceparser.cpp index b6081a7..87a972c 100644 --- a/diceparser.cpp +++ b/diceparser.cpp @@ -27,6 +27,7 @@ #include "node/startingnode.h" #include "node/scalaroperatornode.h" +#include "node/filternode.h" #include "node/numbernode.h" #include "node/keepdiceexecnode.h" #include "node/sortresult.h" @@ -65,6 +66,8 @@ DiceParser::DiceParser() m_OptionOp->insert(QStringLiteral("m"),Merge); m_OptionOp->insert(QStringLiteral("i"),ifOperator); m_OptionOp->insert(QStringLiteral("p"),Painter); + m_OptionOp->insert(QStringLiteral("f"),Filter); + m_aliasList = new QList<DiceAlias*>(); @@ -832,15 +835,9 @@ bool DiceParser::readOption(QString& str,ExecutionNode* previous)//, bool ascending = m_parsingToolbox->readAscending(str); if(m_parsingToolbox->readNumber(str,myNumber)) { - /* if(!hasDice) - { - previous = addRollDiceNode(DEFAULT_FACES_NUMBER,previous); - }*/ node = m_parsingToolbox->addSort(previous,ascending); - KeepDiceExecNode* nodeK = new KeepDiceExecNode(); nodeK->setDiceKeepNumber(myNumber); - node->setNextNode(nodeK); node = nodeK; found = true; @@ -875,6 +872,22 @@ bool DiceParser::readOption(QString& str,ExecutionNode* previous)//, } } break; + case Filter: + { + Validator* validator = m_parsingToolbox->readCompositeValidator(str); + if(NULL!=validator) + { + m_parsingToolbox->isValidValidator(previous,validator); + + FilterNode* filterNode = new FilterNode(); + filterNode->setValidator(validator); + + previous->setNextNode(filterNode); + node = filterNode; + found = true; + } + } + break; case Sort: { bool ascending = m_parsingToolbox->readAscending(str); diff --git a/diceparser.h b/diceparser.h index 6baef6a..fb56685 100644 --- a/diceparser.h +++ b/diceparser.h @@ -82,7 +82,7 @@ public: /** * @brief The OptionOperator enum gathering all options availables for result. */ - enum OptionOperator {KeepAndExplose,Keep,Reroll,Explosing,Sort,Count,RerollAndAdd,Merge,ifOperator,Painter}; + enum OptionOperator {KeepAndExplose,Keep,Reroll,Explosing,Sort,Count,RerollAndAdd,Merge,ifOperator,Painter,Filter}; /** * @brief The CommandOperator enum */ diff --git a/diceparser.pri b/diceparser.pri index ef975a0..124ac62 100644 --- a/diceparser.pri +++ b/diceparser.pri @@ -16,7 +16,8 @@ SOURCES += $$PWD/diceparser.cpp \ $$PWD/result/stringresult.cpp \ $$PWD/compositevalidator.cpp \ $$PWD/dicealias.cpp \ - $$PWD/operationcondition.cpp + $$PWD/operationcondition.cpp \ + $$PWD/node/filternode.cpp HEADERS += \ @@ -33,7 +34,8 @@ HEADERS += \ $$PWD/result/stringresult.h \ $$PWD/compositevalidator.h \ $$PWD/dicealias.h \ - $$PWD/operationcondition.h + $$PWD/operationcondition.h \ + $$PWD/node/filternode.h HEADERS += \ diff --git a/node/filternode.cpp b/node/filternode.cpp index 433f3c7..8fe99c3 100644 --- a/node/filternode.cpp +++ b/node/filternode.cpp @@ -1,6 +1,76 @@ #include "filternode.h" FilterNode::FilterNode() + : m_diceResult(new DiceResult()),m_eachValue(false) { + m_result = m_diceResult; +} + +FilterNode::~FilterNode() +{ + if(NULL!=m_validator) + { + delete m_validator; + } +} +void FilterNode::setValidator(Validator* validator) +{ + m_validator = validator; +} +void FilterNode::run(ExecutionNode* previous) +{ + m_previousNode = previous; + if(NULL==previous) + { + return; + } + DiceResult* previousDiceResult = static_cast<DiceResult*>(previous->getResult()); + m_result->setPrevious(previousDiceResult); + if(NULL!=previousDiceResult) + { + QList<Die*> diceList=previousDiceResult->getResultList(); + QList<Die*> diceList2; + + + for(Die* tmp : diceList) + { + if(m_validator->hasValid(tmp,m_eachValue)) + { + diceList2.append(tmp); + } + else + { + tmp->setHighlighted(false); + } + } + + m_diceResult->setResultList(diceList2); + if(NULL!=m_nextNode) + { + m_nextNode->run(this); + } + } +} + +QString FilterNode::toString(bool wl) const +{ + if(wl) + { + return QString("%1 [label=\"FilterNode\"]").arg(m_id); + } + else + { + return m_id; + } +} +qint64 FilterNode::getPriority() const +{ + qint64 priority=0; + if(NULL!=m_nextNode) + { + priority = m_nextNode->getPriority(); + } + + return priority; } diff --git a/node/filternode.h b/node/filternode.h index b87dff7..ca08c3b 100644 --- a/node/filternode.h +++ b/node/filternode.h @@ -1,11 +1,37 @@ #ifndef FILTERNODE_H #define FILTERNODE_H +#include "executionnode.h" -class FilterNode +#include "validator.h" +#include "result/diceresult.h" + +class FilterNode : public ExecutionNode { public: FilterNode(); + virtual ~FilterNode(); + + virtual void run(ExecutionNode* previous); + /** + * @brief setValidator + */ + virtual void setValidator(Validator* ); + /** + * @brief toString + * @return + */ + virtual QString toString(bool withLabel)const; + /** + * @brief getPriority + * @return + */ + virtual qint64 getPriority() const; + +private: + DiceResult* m_diceResult; + Validator* m_validator; + bool m_eachValue; }; -#endif // FILTERNODE_H
\ No newline at end of file +#endif // FILTERNODE_H diff --git a/parsingtoolbox.cpp b/parsingtoolbox.cpp index 212c006..a52743d 100644 --- a/parsingtoolbox.cpp +++ b/parsingtoolbox.cpp @@ -38,6 +38,7 @@ ParsingToolBox::ParsingToolBox() m_logicOp->insert("<",BooleanCondition::LesserThan); m_logicOp->insert("=",BooleanCondition::Equal); m_logicOp->insert(">",BooleanCondition::GreaterThan); + m_logicOp->insert("!=",BooleanCondition::Different); //m_logicOperation = ; diff --git a/result/stringresult.cpp b/result/stringresult.cpp index 2dff0ac..be8050d 100644 --- a/result/stringresult.cpp +++ b/result/stringresult.cpp @@ -13,7 +13,21 @@ StringResult::~StringResult() { } +bool StringResult::hasResultOfType(RESULT_TYPE resultType) const +{ + if(resultType & Result::STRING) + { + return true; + } + else if(resultType & Result::SCALAR) + { + bool ok=false; + getText().toInt(&ok); + return ok; + } + return false; +} QString StringResult::getText() const { return m_value; @@ -26,10 +40,11 @@ QVariant StringResult::getResult(RESULT_TYPE type) case STRING: return getText(); break; + case SCALAR: + return getText().toInt(); + break; } - - return QVariant(); } QString StringResult::toString(bool wl) diff --git a/result/stringresult.h b/result/stringresult.h index cdd7de2..2effea7 100644 --- a/result/stringresult.h +++ b/result/stringresult.h @@ -40,6 +40,7 @@ public: virtual void setHighLight(bool ); virtual bool hasHighLight() const; + virtual bool hasResultOfType(RESULT_TYPE resultType) const; private: QString m_value; bool m_highlight; |