diff options
| author | 2019-07-10 11:49:45 +0200 | |
|---|---|---|
| committer | 2019-07-12 22:06:35 +0200 | |
| commit | 9698a39a46f736cf37e31f8940e7c1a0a164185b (patch) | |
| tree | 2193ae89ae6cfb59d7b6eed443992bd0245ac5a4 | |
| parent | 64ca7904fd36ad86826b5d5c72f47ffdf0ff365a (diff) | |
| download | OneRoll-9698a39a46f736cf37e31f8940e7c1a0a164185b.tar.gz OneRoll-9698a39a46f736cf37e31f8940e7c1a0a164185b.zip | |
Add valueslistnode
| -rw-r--r-- | CMakeLists.txt | 1 | ||||
| -rw-r--r-- | diceparser.cpp | 36 | ||||
| -rw-r--r-- | diceparser.h | 2 | ||||
| -rw-r--r-- | diceparser.pri | 2 | ||||
| -rw-r--r-- | node/valueslistnode.cpp | 58 | ||||
| -rw-r--r-- | node/valueslistnode.h | 24 |
6 files changed, 123 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 8642f97..9a9a340 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,6 +50,7 @@ SET( dice_sources node/uniquenode.cpp highlightdice.cpp node/variablenode.cpp + node/valueslistnode.cpp ) add_library(diceparser SHARED ${dice_sources} ) diff --git a/diceparser.cpp b/diceparser.cpp index 18be076..1f58948 100644 --- a/diceparser.cpp +++ b/diceparser.cpp @@ -271,6 +271,11 @@ bool DiceParser::readExpression(QString& str, ExecutionNode*& node) node= operandNode; return true; } + else if(readValuesList(str, operandNode)) + { + node= operandNode; + return true; + } else { ExecutionNode* diceNode= nullptr; @@ -316,6 +321,37 @@ bool DiceParser::readOperatorFromNull(QString& str, ExecutionNode*& node) return false; } +bool DiceParser::readValuesList(QString& str, ExecutionNode*& node) +{ + if(str.startsWith("[")) + { + str= str.remove(0, 1); + int pos= ParsingToolBox::findClosingCharacterIndexOf('[', ']', str, 1); // str.indexOf("]"); + if(-1 != pos) + { + QString liststr= str.left(pos); + auto list= liststr.split(","); + str= str.remove(0, pos + 1); + auto values= new ValuesListNode(); + for(auto var : list) + { + qint64 number= 1; + QString error; + if(ParsingToolBox::readDynamicVariable(var, number)) + { + VariableNode* variableNode= new VariableNode(); + variableNode->setIndex(number - 1); + variableNode->setData(&m_startNodes); + values->insertValue(variableNode); + } + } + node= values; + return true; + } + } + return false; +} + bool DiceParser::readNode(QString& str, ExecutionNode*& node) { if(str.isEmpty()) diff --git a/diceparser.h b/diceparser.h index 72e6937..8ecfb50 100644 --- a/diceparser.h +++ b/diceparser.h @@ -250,6 +250,8 @@ public: void getDiceResultFromAllInstruction(QList<ExportedDiceResult>& resultList); QString humanReadableWarning(); + bool readValuesList(QString& str, ExecutionNode*& node); + protected: bool readParameterNode(QString& str, ExecutionNode*& node); diff --git a/diceparser.pri b/diceparser.pri index 933bed0..2424c18 100644 --- a/diceparser.pri +++ b/diceparser.pri @@ -38,6 +38,7 @@ SOURCES += $$PWD/diceparser.cpp \ $$PWD/node/paintnode.cpp \ $$PWD/node/ifnode.cpp \ $$PWD/node/splitnode.cpp \ + $$PWD/node/valueslistnode.cpp \ $$PWD/node/uniquenode.cpp \ $$PWD/node/listsetrollnode.cpp\ $$PWD/node/variablenode.cpp\ @@ -76,6 +77,7 @@ HEADERS += \ $$PWD/node/keepdiceexecnode.h \ $$PWD/node/countexecutenode.h \ $$PWD/node/explodedicenode.h \ + $$PWD/node/valueslistnode.h \ $$PWD/node/parenthesesnode.h \ $$PWD/node/helpnode.h \ $$PWD/node/jumpbackwardnode.h \ diff --git a/node/valueslistnode.cpp b/node/valueslistnode.cpp new file mode 100644 index 0000000..e022741 --- /dev/null +++ b/node/valueslistnode.cpp @@ -0,0 +1,58 @@ +#include "valueslistnode.h" + +ValuesListNode::ValuesListNode() : m_diceResult(new DiceResult()) +{ + m_result= m_diceResult; +} + +void ValuesListNode::run(ExecutionNode* previous) +{ + m_previousNode= previous; + for(auto node : m_data) + { + node->run(this); + auto result= node->getResult(); + if(!result) + continue; + auto val= result->getResult(Result::SCALAR).toInt(); + Die* die= new Die(); + die->displayed(); + die->insertRollValue(val); + m_diceResult->insertResult(die); + } + + if(nullptr != m_nextNode) + { + m_nextNode->run(this); + } +} + +void ValuesListNode::insertValue(ExecutionNode* value) +{ + m_data.push_back(value); +} +ExecutionNode* ValuesListNode::getCopy() const +{ + ValuesListNode* node= new ValuesListNode(); + if(nullptr != m_nextNode) + { + node->setNextNode(m_nextNode->getCopy()); + } + return node; +} +QString ValuesListNode::toString(bool wl) const +{ + if(wl) + { + return QString("%1 [label=\"ValuesListNode list:\"]").arg(m_id); + } + else + { + return m_id; + } +} +qint64 ValuesListNode::getPriority() const +{ + qint64 priority= 4; + return priority; +} diff --git a/node/valueslistnode.h b/node/valueslistnode.h new file mode 100644 index 0000000..100f275 --- /dev/null +++ b/node/valueslistnode.h @@ -0,0 +1,24 @@ +#ifndef VALUESLISTNODE_H +#define VALUESLISTNODE_H + +#include "executionnode.h" +#include "result/diceresult.h" + +class ValuesListNode : public ExecutionNode +{ +public: + ValuesListNode(); + + virtual void run(ExecutionNode* previous= nullptr) override; + virtual QString toString(bool) const override; + virtual qint64 getPriority() const override; + virtual ExecutionNode* getCopy() const override; + + void insertValue(ExecutionNode*); + +private: + std::vector<ExecutionNode*> m_data; + DiceResult* m_diceResult = nullptr; +}; + +#endif // VALUESLISTNODE_H |