From 24d48effb863e458c00dcb1bea1ad5aa82309599 Mon Sep 17 00:00:00 2001 From: Renaud G Date: Fri, 6 Mar 2015 00:27:37 +0100 Subject: -Add new node to roll die as value of list. --- node/listsetrollnode.cpp | 60 ++++++++++++++++++++++++++++++++++++++++++++++++ node/listsetrollnode.h | 19 +++++++++++++++ 2 files changed, 79 insertions(+) (limited to 'node') diff --git a/node/listsetrollnode.cpp b/node/listsetrollnode.cpp index e89e139..3ab9a69 100644 --- a/node/listsetrollnode.cpp +++ b/node/listsetrollnode.cpp @@ -1,5 +1,65 @@ #include "listsetrollnode.h" +#include "die.h" ListSetRollNode::ListSetRollNode() + :m_diceResult(new DiceResult()),m_stringResult(new StringResult()) { + m_result = m_stringResult; +} + +QStringList ListSetRollNode::getList() +{ + return m_values; +} +QString ListSetRollNode::toString() const +{ + return QString("ListSetRollNode_").arg(m_values.join(',')); +} +qint64 ListSetRollNode::getPriority() const +{ + qint64 priority=4; +// if(NULL!=m_nextNode) +// { +// priority = m_nextNode->getPriority(); +// } + + + return priority; +} +void ListSetRollNode::run(ExecutionNode* previous) +{ + m_previousNode = previous; + if(NULL!=previous) + { + Result* result=previous->getResult(); + if(NULL!=result) + { + quint64 diceCount = result->getResult(Result::SCALAR).toReal(); + m_result->setPrevious(result); + QStringList rollResult; + for(quint64 i=0; i < diceCount ; ++i) + { + Die* die = new Die(); + die->setFaces(m_values.size()); + die->roll(); + m_diceResult->insertResult(die); + if(die->getValue()-1getValue()-1]; + } + } + m_stringResult->setText(rollResult.join(",")); + if(NULL!=m_nextNode) + { + m_nextNode->run(this); + } + } + } + + + +} +void ListSetRollNode::setListValue(QStringList lirs) +{ + m_values = lirs; } diff --git a/node/listsetrollnode.h b/node/listsetrollnode.h index 006557b..26fb378 100644 --- a/node/listsetrollnode.h +++ b/node/listsetrollnode.h @@ -1,10 +1,29 @@ #ifndef LISTSETROLLNODE_H #define LISTSETROLLNODE_H + +#include + +#include "executionnode.h" +#include "result/diceresult.h" +#include "result/stringresult.h" + class ListSetRollNode : public ExecutionNode { public: ListSetRollNode(); + virtual void run(ExecutionNode* previous = NULL); + virtual QString toString()const; + virtual qint64 getPriority() const; + QStringList getList(); + + void setListValue(QStringList); + +private: + QStringList m_values; + DiceResult* m_diceResult; + StringResult* m_stringResult; + }; #endif // LISTSETROLLNODE_H -- cgit v1.2.3-70-g09d2