File indexing completed on 2024-05-12 05:39:27
0001 #include "forloopnode.h" 0002 0003 #include "die.h" 0004 0005 MockNode::MockNode() {} 0006 0007 void MockNode::run(ExecutionNode* node) 0008 { 0009 return; 0010 } 0011 0012 void MockNode::setResult(Result* result) 0013 { 0014 m_result= result; 0015 } 0016 0017 QString MockNode::toString(bool) const 0018 { 0019 return {}; 0020 }; 0021 qint64 MockNode::getPriority() const 0022 { 0023 return 0; 0024 } 0025 ExecutionNode* MockNode::getCopy() const 0026 { 0027 return new MockNode(); 0028 } 0029 // end mocknode 0030 0031 ForLoopNode::ForLoopNode() : m_diceResult(new DiceResult) {} 0032 0033 void ForLoopNode::setInternal(ExecutionNode* node) 0034 { 0035 m_internal.reset(node); 0036 } 0037 0038 void ForLoopNode::run(ExecutionNode* previous) 0039 { 0040 if(nullptr != previous) 0041 { 0042 auto prevResult= dynamic_cast<DiceResult*>(previous->getResult()); 0043 if(nullptr != prevResult) 0044 { 0045 m_diceResult->setPrevious(prevResult); 0046 QList<Die*> diceList= prevResult->getResultList(); 0047 for(Die* dice : diceList) 0048 { 0049 MockNode node; 0050 DiceResult diceResult; 0051 diceResult.insertResult(dice); 0052 node.setResult(&diceResult); 0053 m_internal->run(&node); 0054 0055 auto tmp= m_internal.get(); 0056 while(nullptr != tmp->getNextNode()) 0057 { 0058 tmp= tmp->getNextNode(); 0059 } 0060 Result* internalResult= tmp->getResult(); 0061 auto value= internalResult->getResult(Dice::RESULT_TYPE::SCALAR).toInt(); 0062 0063 Die* neodie= new Die(); 0064 *neodie= *dice; 0065 neodie->setValue(value); 0066 m_diceResult->insertResult(neodie); 0067 node.setResult(nullptr); 0068 diceResult.clear(); 0069 dice->displayed(); 0070 } 0071 } 0072 } 0073 m_result= m_diceResult; 0074 if(m_nextNode != nullptr) 0075 m_nextNode->run(this); 0076 } 0077 0078 qint64 ForLoopNode::getPriority() const 0079 { 0080 return 2; 0081 } 0082 0083 QString ForLoopNode::toString(bool withLabel) const 0084 { 0085 if(withLabel) 0086 { 0087 return QString("%1 [label=\"ForLoopNode Node\"]").arg(m_id); 0088 } 0089 else 0090 { 0091 return m_id; 0092 } 0093 } 0094 0095 ExecutionNode* ForLoopNode::getCopy() const 0096 { 0097 auto node= new ForLoopNode(); 0098 if(m_internal) 0099 { 0100 node->setInternal(m_internal->getCopy()); 0101 } 0102 return node; 0103 }