From 9698a39a46f736cf37e31f8940e7c1a0a164185b Mon Sep 17 00:00:00 2001 From: Renaud G Date: Wed, 10 Jul 2019 11:49:45 +0200 Subject: Add valueslistnode --- diceparser.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'diceparser.cpp') 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()) -- cgit v1.2.3-70-g09d2 From fb12f7ea65cf14398b5d23ffa1a56c78dc3e58b3 Mon Sep 17 00:00:00 2001 From: Renaud G Date: Wed, 10 Jul 2019 11:51:44 +0200 Subject: clang format --- diceparser.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'diceparser.cpp') diff --git a/diceparser.cpp b/diceparser.cpp index 1f58948..7add97d 100644 --- a/diceparser.cpp +++ b/diceparser.cpp @@ -176,7 +176,6 @@ bool DiceParser::parseLine(QString str, bool allowAlias) } m_command= str; bool hasInstruction= readInstructionList(str); - bool value= hasInstruction; if(!hasInstruction) { @@ -194,7 +193,6 @@ bool DiceParser::parseLine(QString str, bool allowAlias) ExecutionNode::UNEXPECTED_CHARACTER, QObject::tr("Unexpected character at %1 - end of command was ignored \"%2\"").arg(i).arg(str)); } - if(!m_errorMap.isEmpty()) value= false; -- cgit v1.2.3-70-g09d2 From 3900611f9bc0b8e47f198587defd632403beaf90 Mon Sep 17 00:00:00 2001 From: Renaud G Date: Fri, 12 Jul 2019 00:28:09 +0200 Subject: Fix errors --- diceparser.cpp | 10 +++++----- node/dicerollernode.cpp | 13 +++++++------ 2 files changed, 12 insertions(+), 11 deletions(-) (limited to 'diceparser.cpp') diff --git a/diceparser.cpp b/diceparser.cpp index 7add97d..0de05fc 100644 --- a/diceparser.cpp +++ b/diceparser.cpp @@ -231,6 +231,11 @@ bool DiceParser::readExpression(QString& str, ExecutionNode*& node) } } } + else if(readOperatorFromNull(str, operandNode)) + { + node= operandNode; + return true; + } else if(m_parsingToolbox->readOperand(str, operandNode)) { ExecutionNode* diceNode= nullptr; @@ -264,11 +269,6 @@ bool DiceParser::readExpression(QString& str, ExecutionNode*& node) node= operandNode; return true; } - else if(readOperatorFromNull(str, operandNode)) - { - node= operandNode; - return true; - } else if(readValuesList(str, operandNode)) { node= operandNode; 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(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(num) : 0; + m_result->setPrevious(result); + auto possibleValue= static_cast(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; } -- cgit v1.2.3-70-g09d2 From 713f548d5c3ddabd7f8a65d19edb38205a159091 Mon Sep 17 00:00:00 2001 From: Renaud G Date: Fri, 12 Jul 2019 22:40:01 +0200 Subject: Add values list node --- diceparser.cpp | 9 ++++++++- node/valueslistnode.cpp | 6 +++++- 2 files changed, 13 insertions(+), 2 deletions(-) (limited to 'diceparser.cpp') diff --git a/diceparser.cpp b/diceparser.cpp index 0de05fc..75247ba 100644 --- a/diceparser.cpp +++ b/diceparser.cpp @@ -28,6 +28,7 @@ #include "node/bind.h" #include "node/countexecutenode.h" +#include "node/dicerollernode.h" #include "node/explodedicenode.h" #include "node/filternode.h" #include "node/groupnode.h" @@ -49,10 +50,10 @@ #include "node/startingnode.h" #include "node/stringnode.h" #include "node/uniquenode.h" +#include "node/valueslistnode.h" #include "node/variablenode.h" #include "booleancondition.h" -#include "node/dicerollernode.h" #include "parsingtoolbox.h" #include "range.h" #include "validator.h" @@ -342,6 +343,12 @@ bool DiceParser::readValuesList(QString& str, ExecutionNode*& node) variableNode->setData(&m_startNodes); values->insertValue(variableNode); } + else if(ParsingToolBox::readNumber(var, number)) + { + NumberNode* numberNode= new NumberNode(); + numberNode->setNumber(number); + values->insertValue(numberNode); + } } node= values; return true; diff --git a/node/valueslistnode.cpp b/node/valueslistnode.cpp index e022741..b31ee84 100644 --- a/node/valueslistnode.cpp +++ b/node/valueslistnode.cpp @@ -1,5 +1,7 @@ #include "valueslistnode.h" +#include "variablenode.h" + ValuesListNode::ValuesListNode() : m_diceResult(new DiceResult()) { m_result= m_diceResult; @@ -16,7 +18,9 @@ void ValuesListNode::run(ExecutionNode* previous) continue; auto val= result->getResult(Result::SCALAR).toInt(); Die* die= new Die(); - die->displayed(); + auto dyna= dynamic_cast(node); + if(nullptr != dyna) + die->displayed(); die->insertRollValue(val); m_diceResult->insertResult(die); } -- cgit v1.2.3-70-g09d2