diff options
| author | 2016-11-03 17:36:21 +0100 | |
|---|---|---|
| committer | 2016-11-03 17:36:21 +0100 | |
| commit | 9d389e561339e4fd7a68d60f593ad233e3941d13 (patch) | |
| tree | 39e98d9d3a612be9c6cf449f5a7a5dfdf4593865 /node | |
| parent | 120add8ca2f3a7e075b415a611bcd09034bd6200 (diff) | |
| download | OneRoll-9d389e561339e4fd7a68d60f593ad233e3941d13.tar.gz OneRoll-9d389e561339e4fd7a68d60f593ad233e3941d13.zip | |
-Add FilterNode to dice system.
Diffstat (limited to 'node')
| -rw-r--r-- | node/filternode.cpp | 70 | ||||
| -rw-r--r-- | node/filternode.h | 30 |
2 files changed, 98 insertions, 2 deletions
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 |