File indexing completed on 2024-05-05 05:40:26

0001 /***************************************************************************
0002  *   Copyright (C) 2015 by Renaud Guezennec                                *
0003  *   https://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 
0021 #include "data/charactervision.h"
0022 
0023 CharacterVision::CharacterVision(QObject* parent) : QObject(parent) {}
0024 
0025 CharacterVision::~CharacterVision() {}
0026 
0027 void CharacterVision::setAngle(qreal a)
0028 {
0029     if(a == m_angle)
0030         return;
0031     m_angle= a;
0032     emit angleChanged(m_angle);
0033     m_changes |= ChangedProperty::ANGLE;
0034 }
0035 
0036 void CharacterVision::setRadius(qreal r)
0037 {
0038     if(r == m_radius)
0039         return;
0040     m_radius= r;
0041     emit radiusChanged(m_radius);
0042     m_changes |= ChangedProperty::RADIUS;
0043 }
0044 
0045 void CharacterVision::setPosition(const QPointF& p)
0046 {
0047     if(p == m_pos)
0048         return;
0049     m_pos= p;
0050     emit positionChanged(m_pos);
0051     m_changes |= ChangedProperty::POSITION;
0052 }
0053 
0054 void CharacterVision::setShape(CharacterVision::SHAPE s)
0055 {
0056     if(s == m_shape)
0057         return;
0058     m_shape= s;
0059     emit shapeChanged(m_shape);
0060 }
0061 
0062 qreal CharacterVision::angle() const
0063 {
0064     return m_angle;
0065 }
0066 
0067 qreal CharacterVision::radius() const
0068 {
0069     return m_radius;
0070 }
0071 
0072 QPointF CharacterVision::position() const
0073 {
0074     return m_pos;
0075 }
0076 
0077 CharacterVision::SHAPE CharacterVision::shape() const
0078 {
0079     return m_shape;
0080 }
0081 
0082 void CharacterVision::setCornerVisible(bool b)
0083 {
0084     if(b == m_cornerVisible)
0085         return;
0086     m_cornerVisible= b;
0087     emit cornerVisibleChanged(m_cornerVisible);
0088 }
0089 
0090 void CharacterVision::endOfGeometryChanges()
0091 {
0092     if(m_changes & ChangedProperty::ANGLE)
0093         emit angleEdited();
0094     if(m_changes & ChangedProperty::RADIUS)
0095         emit radiusEdited();
0096     if(m_changes & ChangedProperty::ROTATION)
0097         emit rotationEdited();
0098     if(m_changes & ChangedProperty::POSITION)
0099         emit positionEdited();
0100     if(m_changes & ChangedProperty::PATH)
0101         emit pathEdited();
0102 
0103     m_changes = ChangedProperty::NONE;
0104 }
0105 
0106 void CharacterVision::updatePosition() {}
0107 /*void CharacterVision::setCornerPoint(ChildPointItem* b)
0108 {
0109     m_cornerPoint= b;
0110 }
0111 
0112 ChildPointItem* CharacterVision::getCornerPoint()
0113 {
0114     return m_cornerPoint;
0115 }*/
0116 
0117 bool CharacterVision::visible() const
0118 {
0119     return m_visible;
0120 }
0121 
0122 bool CharacterVision::cornerVisible() const
0123 {
0124     return m_cornerVisible;
0125 }
0126 
0127 void CharacterVision::setVisible(bool b)
0128 {
0129     if(b == m_visible)
0130         return;
0131     m_visible= b;
0132     emit visibleChanged(m_visible);
0133 }
0134 
0135 /*void CharacterVision::fill(NetworkMessageWriter* msg)
0136 {
0137     msg->int8((int)m_shape);
0138     // msg->real(m_pos.x());
0139     // msg->real(m_pos.y());
0140 
0141     msg->real(m_radius);
0142     msg->real(m_angle);
0143 }
0144 
0145 void CharacterVision::readMessage(NetworkMessageReader* msg)
0146 {
0147     m_shape= (CharacterVision::SHAPE)msg->int8();
0148 
0149     // m_pos.setX(msg->real());
0150     // m_pos.setY(msg->real());
0151     m_radius= msg->real();
0152     m_angle= msg->real();
0153 }*/
0154 
0155 QPainterPath CharacterVision::path() const
0156 {
0157     return m_path;
0158 }
0159 
0160 void CharacterVision::setPath(QPainterPath newPath)
0161 {
0162     if (m_path == newPath)
0163         return;
0164     m_path = newPath;
0165     emit pathChanged();
0166     m_changes |= ChangedProperty::PATH;
0167 }
0168 
0169 qreal CharacterVision::rotation() const
0170 {
0171     return m_rotation;
0172 }
0173 
0174 void CharacterVision::setRotation(qreal newRotation)
0175 {
0176     if (qFuzzyCompare(m_rotation, newRotation))
0177         return;
0178     m_rotation = newRotation;
0179     emit rotationChanged();
0180     m_changes |= ChangedProperty::ROTATION;
0181 }
0182 
0183 qreal CharacterVision::side() const
0184 {
0185     return m_side;
0186 }
0187 
0188 void CharacterVision::setSide(qreal newSide)
0189 {
0190     if (qFuzzyCompare(m_side, newSide))
0191         return;
0192     m_side = newSide;
0193     emit sideChanged();
0194 }
0195 
0196 bool CharacterVision::removed() const
0197 {
0198     return m_removed;
0199 }
0200 
0201 void CharacterVision::setRemoved(bool newRemoved)
0202 {
0203     if (m_removed == newRemoved)
0204         return;
0205     m_removed = newRemoved;
0206     emit removedChanged();
0207 }