aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/node
diff options
context:
space:
mode:
Diffstat (limited to 'node')
-rw-r--r--node/dicerollernode.cpp13
-rw-r--r--node/explodedicenode.cpp4
-rw-r--r--node/filternode.cpp4
-rw-r--r--node/forloopnode.cpp103
-rw-r--r--node/forloopnode.h36
-rw-r--r--node/jumpbackwardnode.cpp4
-rw-r--r--node/keepdiceexecnode.cpp4
-rw-r--r--node/mergenode.cpp4
-rw-r--r--node/occurencecountnode.cpp107
-rw-r--r--node/occurencecountnode.h6
-rw-r--r--node/rerolldicenode.cpp4
-rw-r--r--node/uniquenode.cpp4
-rw-r--r--node/valueslistnode.cpp62
-rw-r--r--node/valueslistnode.h24
14 files changed, 323 insertions, 56 deletions
diff --git a/node/dicerollernode.cpp b/node/dicerollernode.cpp
index 44b9e0a..f57d3e3 100644
--- a/node/dicerollernode.cpp
+++ b/node/dicerollernode.cpp
@@ -19,18 +19,19 @@ void DiceRollerNode::run(ExecutionNode* previous)
Result* result= previous->getResult();
if(nullptr != result)
{
- m_diceCount= static_cast<quint64>(result->getResult(Result::SCALAR).toReal());
- m_result->setPrevious(result);
-
- if(m_diceCount == 0)
+ auto num= result->getResult(Result::SCALAR).toReal();
+ if(num <= 0)
{
m_errors.insert(NO_DICE_TO_ROLL, QObject::tr("No dice to roll"));
}
+ m_diceCount= num > 0 ? static_cast<quint64>(num) : 0;
+ m_result->setPrevious(result);
+
auto possibleValue= static_cast<quint64>(std::abs((m_max - m_min) + 1));
if(possibleValue < m_diceCount && m_unique)
{
- m_errors.insert(
- TOO_MANY_DICE, QObject::tr("More unique values asked than possible values (D operator)"));
+ m_errors.insert(TOO_MANY_DICE,
+ QObject::tr("More unique values asked than possible values (D operator)"));
return;
}
diff --git a/node/explodedicenode.cpp b/node/explodedicenode.cpp
index 6df64ba..704ac8a 100644
--- a/node/explodedicenode.cpp
+++ b/node/explodedicenode.cpp
@@ -15,8 +15,8 @@ void ExplodeDiceNode::run(ExecutionNode* previous)
{
for(auto& die : previous_result->getResultList())
{
- Die* tmpdie= new Die();
- *tmpdie= *die;
+ Die* tmpdie= new Die(*die);
+// *tmpdie= *die;
m_diceResult->insertResult(tmpdie);
die->displayed();
}
diff --git a/node/filternode.cpp b/node/filternode.cpp
index bda9c20..d5d155a 100644
--- a/node/filternode.cpp
+++ b/node/filternode.cpp
@@ -34,8 +34,8 @@ void FilterNode::run(ExecutionNode* previous)
{
if(m_validator->hasValid(tmp, m_eachValue))
{
- Die* tmpdie= new Die();
- *tmpdie= *tmp;
+ Die* tmpdie= new Die(*tmp);
+ //*tmpdie= *tmp;
diceList2.append(tmpdie);
tmp->displayed();
}
diff --git a/node/forloopnode.cpp b/node/forloopnode.cpp
new file mode 100644
index 0000000..f65a389
--- /dev/null
+++ b/node/forloopnode.cpp
@@ -0,0 +1,103 @@
+#include "forloopnode.h"
+
+#include "die.h"
+
+MockNode::MockNode() {}
+
+void MockNode::run(ExecutionNode* node)
+{
+ return;
+}
+
+void MockNode::setResult(Result* result)
+{
+ m_result= result;
+}
+
+QString MockNode::toString(bool) const
+{
+ return {};
+};
+qint64 MockNode::getPriority() const
+{
+ return 0;
+}
+ExecutionNode* MockNode::getCopy() const
+{
+ return new MockNode();
+}
+// end mocknode
+
+ForLoopNode::ForLoopNode() : m_diceResult(new DiceResult) {}
+
+void ForLoopNode::setInternal(ExecutionNode* node)
+{
+ m_internal.reset(node);
+}
+
+void ForLoopNode::run(ExecutionNode* previous)
+{
+ if(nullptr != previous)
+ {
+ auto prevResult= dynamic_cast<DiceResult*>(previous->getResult());
+ if(nullptr != prevResult)
+ {
+ m_diceResult->setPrevious(prevResult);
+ QList<Die*> diceList= prevResult->getResultList();
+ for(Die* dice : diceList)
+ {
+ MockNode node;
+ DiceResult diceResult;
+ diceResult.insertResult(dice);
+ node.setResult(&diceResult);
+ m_internal->run(&node);
+
+ auto tmp= m_internal.get();
+ while(nullptr != tmp->getNextNode())
+ {
+ tmp= tmp->getNextNode();
+ }
+ Result* internalResult= tmp->getResult();
+ auto value= internalResult->getResult(Result::SCALAR).toInt();
+
+ Die* neodie= new Die();
+ *neodie= *dice;
+ neodie->setValue(value);
+ m_diceResult->insertResult(neodie);
+ node.setResult(nullptr);
+ diceResult.clear();
+ dice->displayed();
+ }
+ }
+ }
+ m_result= m_diceResult;
+ if(m_nextNode != nullptr)
+ m_nextNode->run(this);
+}
+
+qint64 ForLoopNode::getPriority() const
+{
+ return 2;
+}
+
+QString ForLoopNode::toString(bool withLabel) const
+{
+ if(withLabel)
+ {
+ return QString("%1 [label=\"ForLoopNode Node\"]").arg(m_id);
+ }
+ else
+ {
+ return m_id;
+ }
+}
+
+ExecutionNode* ForLoopNode::getCopy() const
+{
+ auto node= new ForLoopNode();
+ if(m_internal)
+ {
+ node->setInternal(m_internal->getCopy());
+ }
+ return node;
+}
diff --git a/node/forloopnode.h b/node/forloopnode.h
new file mode 100644
index 0000000..a9acf20
--- /dev/null
+++ b/node/forloopnode.h
@@ -0,0 +1,36 @@
+#ifndef FORLOOPNODE_H
+#define FORLOOPNODE_H
+
+#include "executionnode.h"
+#include "result/diceresult.h"
+#include <memory>
+
+class MockNode : public ExecutionNode
+{
+public:
+ MockNode();
+ void run(ExecutionNode* node);
+ void setResult(Result* result);
+ QString toString(bool withLabel) const;
+ qint64 getPriority() const;
+ ExecutionNode* getCopy() const;
+};
+
+class ForLoopNode : public ExecutionNode
+{
+public:
+ ForLoopNode();
+ void run(ExecutionNode* previous);
+
+ void setInternal(ExecutionNode* internal);
+
+ QString toString(bool withLabel) const;
+ qint64 getPriority() const;
+ ExecutionNode* getCopy() const;
+
+private:
+ std::unique_ptr<ExecutionNode> m_internal;
+ DiceResult* m_diceResult;
+};
+
+#endif // FORLOOPNODE_H
diff --git a/node/jumpbackwardnode.cpp b/node/jumpbackwardnode.cpp
index 83bdb1e..15c7063 100644
--- a/node/jumpbackwardnode.cpp
+++ b/node/jumpbackwardnode.cpp
@@ -128,8 +128,8 @@ void JumpBackwardNode::run(ExecutionNode* previous)
{
for(auto& die : diceResult->getResultList())
{
- Die* tmpdie= new Die();
- *tmpdie= *die;
+ Die* tmpdie= new Die(*die);
+ //*tmpdie= *die;
m_diceResult->insertResult(tmpdie);
die->displayed();
}
diff --git a/node/keepdiceexecnode.cpp b/node/keepdiceexecnode.cpp
index bad2370..42b4c40 100644
--- a/node/keepdiceexecnode.cpp
+++ b/node/keepdiceexecnode.cpp
@@ -50,8 +50,8 @@ void KeepDiceExecNode::run(ExecutionNode* previous)
for(Die* die : diceList3)
{
- Die* tmpdie= new Die();
- *tmpdie= *die;
+ Die* tmpdie= new Die(*die);
+ //*tmpdie= *die;
diceList2.append(tmpdie);
die->displayed();
}
diff --git a/node/mergenode.cpp b/node/mergenode.cpp
index e708cef..4a11a76 100644
--- a/node/mergenode.cpp
+++ b/node/mergenode.cpp
@@ -61,8 +61,8 @@ void MergeNode::run(ExecutionNode* previous)
{
if(!m_diceResult->getResultList().contains(die) && (!die->hasBeenDisplayed()))
{
- Die* tmpdie= new Die();
- *tmpdie= *die;
+ Die* tmpdie= new Die(*die);
+ //*tmpdie= *die;
die->displayed();
m_diceResult->getResultList().append(tmpdie);
}
diff --git a/node/occurencecountnode.cpp b/node/occurencecountnode.cpp
index 4fdbc51..e0117ef 100644
--- a/node/occurencecountnode.cpp
+++ b/node/occurencecountnode.cpp
@@ -21,11 +21,7 @@
#include "result/diceresult.h"
#include "result/stringresult.h"
-OccurenceCountNode::OccurenceCountNode() : ExecutionNode()
-{
- m_stringResult= new StringResult();
- m_result= m_stringResult;
-}
+OccurenceCountNode::OccurenceCountNode() : ExecutionNode() {}
void OccurenceCountNode::run(ExecutionNode* previous)
{
@@ -35,7 +31,6 @@ void OccurenceCountNode::run(ExecutionNode* previous)
return;
DiceResult* previousDiceResult= dynamic_cast<DiceResult*>(m_previousNode->getResult());
- // m_diceResult->setPrevious(previousDiceResult);
if(nullptr == previousDiceResult)
return;
@@ -55,40 +50,13 @@ void OccurenceCountNode::run(ExecutionNode* previous)
}
std::sort(vec.begin(), vec.end());
-
- QStringList list;
- for(auto key : mapOccurence)
+ if(nullptr == m_nextNode)
{
- if(nullptr != m_validator)
- {
- Die die;
- die.insertRollValue(key.first);
- if(!m_validator->hasValid(&die, true))
- continue;
- }
-
- if(key.second < m_width)
- continue;
-
- if(key.first >= m_height)
- list << QStringLiteral("%1x%2").arg(key.second).arg(key.first);
+ runForStringResult(mapOccurence, vec);
}
-
- QStringList resultList;
- std::for_each(vec.begin(), vec.end(), [&resultList](qint64 val) { resultList << QString::number(val); });
-
- QString result;
-
- if(!list.isEmpty())
- result= list.join(',');
else
- result= QObject::tr("No matching result");
-
- m_stringResult->setText(QStringLiteral("%1 - [%2]").arg(result).arg(resultList.join(',')));
-
- if(nullptr != m_nextNode)
{
- m_nextNode->run(this);
+ runForDiceResult(mapOccurence);
}
}
QString OccurenceCountNode::toString(bool label) const
@@ -109,6 +77,7 @@ ExecutionNode* OccurenceCountNode::getCopy() const
qint64 OccurenceCountNode::getPriority() const
{
qint64 priority= 0;
+
if(nullptr != m_previousNode)
{
priority= m_previousNode->getPriority();
@@ -145,3 +114,69 @@ void OccurenceCountNode::setValidator(Validator* validator)
{
m_validator= validator;
}
+void OccurenceCountNode::runForStringResult(const std::map<qint64, qint64>& mapOccurence, QVector<qint64>& vec)
+{
+ m_stringResult= new StringResult();
+ m_result= m_stringResult;
+ QStringList list;
+ for(auto key : mapOccurence)
+ {
+ if(nullptr != m_validator)
+ {
+ Die die;
+ die.insertRollValue(key.first);
+ if(!m_validator->hasValid(&die, true))
+ continue;
+ }
+
+ if(key.second < m_width)
+ continue;
+
+ if(key.first >= m_height)
+ list << QStringLiteral("%1x%2").arg(key.second).arg(key.first);
+ }
+
+ QStringList resultList;
+ std::for_each(vec.begin(), vec.end(), [&resultList](qint64 val) { resultList << QString::number(val); });
+
+ QString result;
+
+ if(!list.isEmpty())
+ result= list.join(',');
+ else
+ result= QObject::tr("No matching result");
+
+ m_stringResult->setText(QStringLiteral("%1 - [%2]").arg(result).arg(resultList.join(',')));
+}
+void OccurenceCountNode::runForDiceResult(const std::map<qint64, qint64>& mapOccurence)
+{
+ m_diceResult= new DiceResult();
+ m_result= m_diceResult;
+ QStringList list;
+ for(auto key : mapOccurence)
+ {
+ if(nullptr != m_validator)
+ {
+ Die die;
+ die.insertRollValue(key.first);
+ if(!m_validator->hasValid(&die, true))
+ continue;
+ }
+
+ if(key.second < m_width)
+ continue;
+
+ if(key.first >= m_height)
+ {
+ // list << QStringLiteral("%1x%2").arg(key.second).arg(key.first);
+ Die* die= new Die();
+ die->insertRollValue(key.second * key.first);
+ m_diceResult->insertResult(die);
+ }
+ }
+
+ if(nullptr != m_nextNode)
+ {
+ m_nextNode->run(this);
+ }
+}
diff --git a/node/occurencecountnode.h b/node/occurencecountnode.h
index 125f340..492b295 100644
--- a/node/occurencecountnode.h
+++ b/node/occurencecountnode.h
@@ -24,6 +24,7 @@
#include "validator.h"
class StringResult;
+class DiceResult;
class OccurenceCountNode : public ExecutionNode
{
public:
@@ -45,10 +46,15 @@ public:
void setValidator(Validator* validator);
private:
+ void runForStringResult(const std::map<qint64, qint64>& mapOccurence, QVector<qint64>& vec);
+ void runForDiceResult(const std::map<qint64, qint64>& mapOccurence);
+
+private:
qint64 m_width= 1;
qint64 m_height= 0;
Validator* m_validator= nullptr;
StringResult* m_stringResult= nullptr;
+ DiceResult* m_diceResult= nullptr;
};
#endif // OCCURENCECOUNTNODE_H
diff --git a/node/rerolldicenode.cpp b/node/rerolldicenode.cpp
index 659e9c0..56ee6d9 100644
--- a/node/rerolldicenode.cpp
+++ b/node/rerolldicenode.cpp
@@ -25,8 +25,8 @@ void RerollDiceNode::run(ExecutionNode* previous)
{
for(auto& die : previous_result->getResultList())
{
- Die* tmpdie= new Die();
- *tmpdie= *die;
+ Die* tmpdie= new Die(*die);
+ //*tmpdie= *die;
m_diceResult->insertResult(tmpdie);
die->displayed();
}
diff --git a/node/uniquenode.cpp b/node/uniquenode.cpp
index 4ef7fa6..e937c6d 100644
--- a/node/uniquenode.cpp
+++ b/node/uniquenode.cpp
@@ -50,8 +50,8 @@ void UniqueNode::run(ExecutionNode* previous)
if(it == formerValues.end())
{
- auto die = new Die();
- *die = *oldDie;
+ auto die = new Die(*oldDie);
+ //*die = *oldDie;
m_diceResult->insertResult(die);
formerValues.push_back(value);
}
diff --git a/node/valueslistnode.cpp b/node/valueslistnode.cpp
new file mode 100644
index 0000000..b31ee84
--- /dev/null
+++ b/node/valueslistnode.cpp
@@ -0,0 +1,62 @@
+#include "valueslistnode.h"
+
+#include "variablenode.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();
+ auto dyna= dynamic_cast<VariableNode*>(node);
+ if(nullptr != dyna)
+ 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