aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/range.cpp
blob: 39a46ce803b96e35486fe1676d13f6e1ba6e6108 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/***************************************************************************
* Copyright (C) 2014 by Renaud Guezennec                                   *
* http://www.rolisteam.org/contact                      *
*                                                                          *
*  This file is part of DiceParser                                         *
*                                                                          *
* DiceParser is free software; you can redistribute it and/or modify       *
* it under the terms of the GNU General Public License as published by     *
* the Free Software Foundation; either version 2 of the License, or        *
* (at your option) any later version.                                      *
*                                                                          *
* This program is distributed in the hope that it will be useful,          *
* but WITHOUT ANY WARRANTY; without even the implied warranty of           *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the             *
* GNU General Public License for more details.                             *
*                                                                          *
* You should have received a copy of the GNU General Public License        *
* along with this program; if not, write to the                            *
* Free Software Foundation, Inc.,                                          *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.                 *
***************************************************************************/
#include "range.h"

Range::Range()
    : m_hasEnd(false),m_hasStart(false),m_emptyRange(false)
{


}
void Range::setValue(qint64 s,qint64 e)
{
    m_start = s;
    m_end=e;

    m_hasEnd = true;
    m_hasStart = true;
}

qint64 Range::hasValid(Die* m,bool recursive, bool unhighlight) const
{
    qint64 result = 0;
    if(recursive)
    {
        foreach(qint64 value, m->getListValue())
        {
            if((value>=m_start)&&(value<=m_end))
            {
                ++result;
            }
        }
    }
    else if((m->getLastRolledValue()>=m_start)&&(m->getLastRolledValue()<=m_end))
    {
        ++result;
    }
    if((unhighlight)&&(result==0))
    {
        m->setHighlighted(false);
    }
    return result;
}
QString Range::toString()
{
	return QStringLiteral("[%1-%2]").arg(m_start).arg(m_end);
}
quint64 Range::getValidRangeSize(quint64 faces) const
{
    Q_UNUSED(faces);
    return m_end-m_start;
}
void Range::setStart(qint64 start)
{
    m_start = start;
    m_hasStart = true;
}
void Range::setEnd(qint64 end)
{
    m_end = end;
    m_hasEnd = true;
}

bool Range::isFullyDefined() const
{
    return (m_hasEnd && m_hasStart);
}
qint64 Range::getStart() const
{
 return m_start;
}
qint64 Range::getEnd() const
{
    return m_end;
}
void Range::setEmptyRange(bool b)
{
    m_emptyRange = b;
}

bool Range::isEmptyRange()
{
    return m_emptyRange;
}
Validator* Range::getCopy() const
{
    Range* val =  new Range();
    val->setEmptyRange(m_emptyRange);
    if(m_hasEnd)
    {
        val->setEnd(m_end);
    }
    if(m_hasStart)
    {
        val->setStart(m_start);
    }
    return  val;
}