File indexing completed on 2024-05-12 09:42:08

0001 /***************************************************************************
0002  *   Copyright (C) 2016 by Renaud Guezennec                                *
0003  *   http:://www.rolisteam.org/contact                                     *
0004  *                                                                         *
0005  *   rolisteam is free software; you can redistribute it and/or modify     *
0006  *   it under the terms of the GNU General Public License as published by  *
0007  *   the Free Software Foundation; either version 2 of the License, or     *
0008  *   (at your option) any later version.                                   *
0009  *                                                                         *
0010  *   This program is distributed in the hope that it will be useful,       *
0011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0013  *   GNU General Public License for more details.                          *
0014  *                                                                         *
0015  *   You should have received a copy of the GNU General Public License     *
0016  *   along with this program; if not, write to the                         *
0017  *   Free Software Foundation, Inc.,                                       *
0018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
0019  ***************************************************************************/
0020 #include <diceparser/highlightdice.h>
0021 
0022 HighLightDice::HighLightDice(QList<qint64> result, bool isHighlighted, QString color, bool displayed, quint64 faces,
0023                              const QString& uuid)
0024     : m_result(result)
0025     , m_hasHighlight(isHighlighted)
0026     , m_color(color)
0027     , m_displayed(displayed)
0028     , m_faces(faces)
0029     , m_uuid(uuid)
0030 {
0031 }
0032 
0033 HighLightDice::~HighLightDice() {}
0034 
0035 QList<qint64> HighLightDice::result() const
0036 {
0037     return m_result;
0038 }
0039 
0040 void HighLightDice::setResult(const QList<qint64>& result)
0041 {
0042     m_result= result;
0043 }
0044 
0045 bool HighLightDice::isHighlighted() const
0046 {
0047     return m_hasHighlight;
0048 }
0049 
0050 void HighLightDice::setHighlight(bool hasHighlight)
0051 {
0052     m_hasHighlight= hasHighlight;
0053 }
0054 
0055 QString HighLightDice::color() const
0056 {
0057     return m_color;
0058 }
0059 
0060 void HighLightDice::setColor(const QString& color)
0061 {
0062     m_color= color;
0063 }
0064 
0065 bool HighLightDice::displayed() const
0066 {
0067     return m_displayed;
0068 }
0069 
0070 void HighLightDice::setDisplayed(bool displayed)
0071 {
0072     m_displayed= displayed;
0073 }
0074 
0075 quint64 HighLightDice::faces() const
0076 {
0077     return m_faces;
0078 }
0079 
0080 void HighLightDice::setFaces(const quint64& faces)
0081 {
0082     m_faces= faces;
0083 }
0084 
0085 QString HighLightDice::getResultString() const
0086 {
0087     if(m_result.size() == 1)
0088     {
0089         return QString::number(m_result.first());
0090     }
0091     else
0092     {
0093         QStringList list;
0094         std::transform(std::begin(m_result), std::end(m_result), std::back_inserter(list),
0095                        [](qint64 value) { return QString::number(value); });
0096 
0097         auto totalScore= std::accumulate(std::begin(m_result), std::end(m_result), 0);
0098         return QStringLiteral("%2 [%1]").arg(list.join(",")).arg(totalScore);
0099     }
0100 }
0101 
0102 QString HighLightDice::uuid() const
0103 {
0104     return m_uuid;
0105 }
0106 
0107 void HighLightDice::setUuid(const QString& uuid)
0108 {
0109     m_uuid= uuid;
0110 }