arenaelementtype.cpp
Go to the documentation of this file.
1 #include "arenaelementtype.h"
2 #include "arenaelement.h"
3 
4 #include <QDebug>
5 
7  : m_instanceCount(0)
8 {
9 }
10 
11 bool ArenaElementType::load(const QDir &folderDir)
12 {
13  m_name = folderDir.dirName();
14 
15  QFile in(folderDir.filePath("properties.xml"));
16  Q_ASSERT(in.exists());
17  in.open(QFile::ReadOnly);
18  QDomDocument doc;
19  doc.setContent(&in);
20  in.close();
21 
22  QDomElement node = doc.firstChild().toElement();
23  Q_ASSERT(!node.isNull());
24  if (node.tagName() != "properties")
25  {
26  qDebug() << "Error loading properties.xml in " << QFileInfo(in).filePath() << ": Root element must be <property>!";
27  return false;
28  }
29 
30  QDomNodeList childNodes = node.childNodes();
31  for (int i = 0; i < childNodes.size(); i++)
32  {
33  QDomElement child = childNodes.at(i).toElement();
34  Q_ASSERT(!child.isNull());
35  /*
36  if (child.tagName() == "name")
37  {
38  m_name = child.text();
39  }
40  else */if (child.tagName() == "type")
41  {
42  if (child.text() == "floor")
43  m_type = FloorType;
44  else if (child.text() == "wall")
45  m_type = WallType;
46  else if (child.text() == "mountable-item")
48  else if (child.text() == "item")
49  m_type = ItemType;
50  else
51  {
52  qDebug() << "Error loading properties.xml in " << QFileInfo(in).filePath() << ": Unknown element type!";
53  return false;
54  }
55  }
56  else if (child.tagName() == "pixmap")
57  {
58  m_pixmap = QPixmap(folderDir.filePath(child.text()));
59  }
60  else if (child.tagName() == "mesh")
61  {
62  m_mesh = child.text();
63  }
64  else if (child.tagName() == "meta-info")
65  {
66  QDomNodeList metaInfos = child.childNodes();
67  for (int i = 0; i < metaInfos.size(); i++)
68  {
69  QDomElement metaInfo = metaInfos.at(i).toElement();
70  Q_ASSERT(!metaInfo.isNull());
71  // Only these elements are valid meta info nodes
72  if (metaInfo.tagName() == "mi")
73  {
74  if (!metaInfo.hasAttribute("desc"))
75  {
76  qDebug() << "Warning: meta-info element is missing \"desc\" attribute in "
77  << QFileInfo(in).filePath();
78  continue;
79  }
80  QString desc = metaInfo.attribute("desc");
81 
82  if (metaInfo.text().isEmpty())
83  {
84  qDebug() << "Warning: Empty meta-info element in "
85  << QFileInfo(in).filePath();
86  continue;
87  }
88  QString value = metaInfo.text();
89  m_metaInfos.append(QStringPair(desc, value));
90  }
91  }
92  }
93  else if (child.tagName() == "item-mount-points")
94  {
95  QDomNodeList itemMountPoints = child.childNodes();
96  for (int i = 0; i < itemMountPoints.size(); i++)
97  {
98  QDomElement itemMountPoint = itemMountPoints.at(i).toElement();
99  Q_ASSERT(!itemMountPoint.isNull());
100  // Only these elements are valid
101  if (itemMountPoint.tagName() == "item-mount-point")
102  {
103  QPointF pos;
104  QString desc;
105  if (itemMountPoint.hasAttribute("x"))
106  pos.rx() = itemMountPoint.attribute("x").toFloat();
107  if (itemMountPoint.hasAttribute("y"))
108  pos.ry() = itemMountPoint.attribute("y").toFloat();
109  if (itemMountPoint.hasAttribute("desc"))
110  desc = itemMountPoint.attribute("desc");
111  m_itemMountPoints.push_back(ItemMountPoint(desc, pos));
112  }
113  }
114  }
115  }
116  return true;
117 }
118 
120 {
121  foreach (QStringPair metaInfo, m_metaInfos)
122  if (metaInfo.first == "Name")
123  return metaInfo.second;
124  return name();
125 }
126 
128 {
129  ArenaElement *element = new ArenaElement(this, m_instanceCount++);
130  return element;
131 }
Item freely movable within a grid point.
QPair< QString, QString > QStringPair
QList< ItemMountPoint > itemMountPoints() const
bool load(const QDir &folderDir)
QVector< QStringPair > metaInfos() const
QPair< QString, QPointF > ItemMountPoint
QVector< QStringPair > m_metaInfos
QList< ItemMountPoint > m_itemMountPoints
Item that can be mounted to a wall element.
ArenaElement * createInstance() const
QString name() const
QString humanReadableName() const
Returns the "Name" meta info field if it exists, otherwise name()


hector_nist_arena_designer
Author(s): Stefan Kohlbrecher , Johannes Simon
autogenerated on Fri Aug 21 2020 10:45:27