diff options
Diffstat (limited to 'node')
| -rw-r--r-- | node/dicerollernode.cpp | 11 | ||||
| -rw-r--r-- | node/dicerollernode.h | 6 | ||||
| -rw-r--r-- | node/scalaroperatornode.cpp | 24 | ||||
| -rw-r--r-- | node/scalaroperatornode.h | 9 | ||||
| -rw-r--r-- | node/splitnode.cpp | 91 | ||||
| -rw-r--r-- | node/splitnode.h | 43 |
6 files changed, 167 insertions, 17 deletions
diff --git a/node/dicerollernode.cpp b/node/dicerollernode.cpp index caff889..9ca0d35 100644 --- a/node/dicerollernode.cpp +++ b/node/dicerollernode.cpp @@ -33,6 +33,7 @@ void DiceRollerNode::run(ExecutionNode* previous) for(quint64 i=0; i < m_diceCount ; ++i) { Die* die = new Die(); + die->setOp(m_operator); die->setBase(m_min); die->setMaxValue(m_max); die->roll(); @@ -82,3 +83,13 @@ ExecutionNode* DiceRollerNode::getCopy() const } return node; } + +Die::ArithmeticOperator DiceRollerNode::getOperator() const +{ + return m_operator; +} + +void DiceRollerNode::setOperator(const Die::ArithmeticOperator &dieOperator) +{ + m_operator = dieOperator; +} diff --git a/node/dicerollernode.h b/node/dicerollernode.h index dcdbeb2..0857b30 100644 --- a/node/dicerollernode.h +++ b/node/dicerollernode.h @@ -44,11 +44,15 @@ public: virtual ExecutionNode* getCopy() const; //private members + Die::ArithmeticOperator getOperator() const; + void setOperator(const Die::ArithmeticOperator & dieOperator); + private: quint64 m_diceCount; qint64 m_max; /// faces - DiceResult* m_diceResult; + DiceResult* m_diceResult; qint64 m_min; + Die::ArithmeticOperator m_operator; }; #endif // DICEROLLERNODE_H diff --git a/node/scalaroperatornode.cpp b/node/scalaroperatornode.cpp index e670dee..9c86917 100644 --- a/node/scalaroperatornode.cpp +++ b/node/scalaroperatornode.cpp @@ -26,7 +26,7 @@ ScalarOperatorNode::ScalarOperatorNode() - : m_internalNode(NULL),m_scalarResult(new ScalarResult()),m_arithmeticOperator(PLUS) + : m_internalNode(NULL),m_scalarResult(new ScalarResult()),m_arithmeticOperator(Die::PLUS) { /*m_scalarOperationList.insert('+',PLUS); m_scalarOperationList.insert('-',MINUS); @@ -76,16 +76,16 @@ void ScalarOperatorNode::run(ExecutionNode* previous) switch(m_arithmeticOperator) { - case PLUS: + case Die::PLUS: m_scalarResult->setValue(add(previousResult->getResult(Result::SCALAR).toReal(),internalResult->getResult(Result::SCALAR).toReal())); break; - case MINUS: + case Die::MINUS: m_scalarResult->setValue(substract(previousResult->getResult(Result::SCALAR).toReal(),internalResult->getResult(Result::SCALAR).toReal())); break; - case MULTIPLICATION: + case Die::MULTIPLICATION: m_scalarResult->setValue(multiple(previousResult->getResult(Result::SCALAR).toReal(),internalResult->getResult(Result::SCALAR).toReal())); break; - case DIVIDE: + case Die::DIVIDE: m_scalarResult->setValue(divide(previousResult->getResult(Result::SCALAR).toReal(),internalResult->getResult(Result::SCALAR).toReal())); break; default: @@ -137,12 +137,12 @@ qint64 ScalarOperatorNode::multiple(qint64 a,qint64 b) { return a*b; } -ScalarOperatorNode::ArithmeticOperator ScalarOperatorNode::getArithmeticOperator() const +Die::ArithmeticOperator ScalarOperatorNode::getArithmeticOperator() const { return m_arithmeticOperator; } -void ScalarOperatorNode::setArithmeticOperator(const ScalarOperatorNode::ArithmeticOperator &arithmeticOperator) +void ScalarOperatorNode::setArithmeticOperator(const Die::ArithmeticOperator &arithmeticOperator) { m_arithmeticOperator = arithmeticOperator; } @@ -152,16 +152,16 @@ QString ScalarOperatorNode::toString(bool wl) const QString op=""; switch(m_arithmeticOperator) { - case PLUS: + case Die::PLUS: op="+"; break; - case MINUS: + case Die::MINUS: op="-"; break; - case MULTIPLICATION: + case Die::MULTIPLICATION: op="*"; break; - case DIVIDE: + case Die::DIVIDE: op="/"; break; default: @@ -179,7 +179,7 @@ QString ScalarOperatorNode::toString(bool wl) const } qint64 ScalarOperatorNode::getPriority() const { - if((m_arithmeticOperator==PLUS)||(m_arithmeticOperator==MINUS)) + if((m_arithmeticOperator==Die::PLUS)||(m_arithmeticOperator==Die::MINUS)) { return 1; } diff --git a/node/scalaroperatornode.h b/node/scalaroperatornode.h index 4b21b8c..0855a4c 100644 --- a/node/scalaroperatornode.h +++ b/node/scalaroperatornode.h @@ -27,6 +27,7 @@ #include "executionnode.h" #include "result/scalarresult.h" +#include "die.h" /** @@ -38,7 +39,7 @@ public: /** * @brief The ArithmeticOperator enum */ - enum ArithmeticOperator {PLUS,MINUS,DIVIDE,MULTIPLICATION}; + //enum ArithmeticOperator {PLUS,MINUS,DIVIDE,MULTIPLICATION}; /** * @brief ScalarOperatorNode */ @@ -81,12 +82,12 @@ public: * @brief getArithmeticOperator * @return */ - ScalarOperatorNode::ArithmeticOperator getArithmeticOperator() const; + Die::ArithmeticOperator getArithmeticOperator() const; /** * @brief setArithmeticOperator * @param arithmeticOperator */ - void setArithmeticOperator(const ScalarOperatorNode::ArithmeticOperator &arithmeticOperator); + void setArithmeticOperator(const Die::ArithmeticOperator &arithmeticOperator); /** * @brief getCopy @@ -118,7 +119,7 @@ private: private: ExecutionNode* m_internalNode; ScalarResult* m_scalarResult; - ArithmeticOperator m_arithmeticOperator; + Die::ArithmeticOperator m_arithmeticOperator; }; #endif // SCALAROPERATORNODE_H diff --git a/node/splitnode.cpp b/node/splitnode.cpp new file mode 100644 index 0000000..5ef082f --- /dev/null +++ b/node/splitnode.cpp @@ -0,0 +1,91 @@ +/*************************************************************************** +* 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 "splitnode.h" + +SplitNode::SplitNode() + : m_diceResult(new DiceResult()) +{ + m_result = m_diceResult; +} +void SplitNode::run(ExecutionNode* previous) +{ + m_previousNode = previous; + if(NULL!=previous) + { + m_result->setPrevious(previous->getResult()); + + Result* tmpResult = previous->getResult(); + if(nullptr != tmpResult) + { + DiceResult* dice = dynamic_cast<DiceResult*>(tmpResult); + if(nullptr!=dice) + { + for(Die* oldDie : dice->getResultList()) + { + m_diceResult->setOperator(oldDie->getOp()); + for(qint64 value : oldDie->getListValue()) + { + Die* tmpdie = new Die(); + tmpdie->setValue(value); + tmpdie->setOp(oldDie->getOp()); + m_diceResult->insertResult(tmpDie); + } + } + } + } + } + if(NULL!=m_nextNode) + { + m_nextNode->run(this); + } +} + +QString SplitNode::toString(bool withLabel) const +{ + if(withLabel) + { + return QString("%1 [label=\"Merge Node\"]").arg(m_id); + } + else + { + return m_id; + } +} +qint64 SplitNode::getPriority() const +{ + qint64 priority=0; + if(NULL!=m_nextNode) + { + priority = m_nextNode->getPriority(); + } + return priority; +} +ExecutionNode* SplitNode::getCopy() const +{ + SplitNode* node = new SplitNode(); + if(NULL!=m_nextNode) + { + node->setNextNode(m_nextNode->getCopy()); + } + return node; + +} diff --git a/node/splitnode.h b/node/splitnode.h new file mode 100644 index 0000000..1bb092e --- /dev/null +++ b/node/splitnode.h @@ -0,0 +1,43 @@ +/*************************************************************************** +* 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. * +***************************************************************************/ +#ifndef MERGENODE_H +#define MERGENODE_H + +#include "node/executionnode.h" +#include "result/diceresult.h" + +/** + * @brief The MergeNode class is an ExecutionNode. It is dedicated to merge result of several commands. + */ +class SplitNode : public ExecutionNode +{ +public: + SplitNode(); + void run(ExecutionNode* previous); + virtual QString toString(bool withLabel)const; + virtual qint64 getPriority() const; + virtual ExecutionNode *getCopy() const; +private: + DiceResult* m_diceResult; +}; + +#endif // NUMBERNODE_H |