summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2017-08-20 00:34:20 +0300
committerAndrei Karas <akaras@inbox.ru>2017-08-20 00:34:20 +0300
commit899d3b925ccb249de881bbc957f6e4ddc754cbbd (patch)
tree4c35a6f21d909f9bc07ed091f0c8e3cb5f700105
parent1049de4c76ac6fc85c9f7f2bd35fb62ca787aa4c (diff)
downloadplus-899d3b925ccb249de881bbc957f6e4ddc754cbbd.tar.gz
plus-899d3b925ccb249de881bbc957f6e4ddc754cbbd.tar.bz2
plus-899d3b925ccb249de881bbc957f6e4ddc754cbbd.tar.xz
plus-899d3b925ccb249de881bbc957f6e4ddc754cbbd.zip
Add function for read float and double number from xml.
-rw-r--r--src/gui/windows/skilldialog.cpp24
-rw-r--r--src/particle/particle.cpp12
-rw-r--r--src/particle/particleemitter.cpp8
-rw-r--r--src/particle/particleengine.cpp12
-rw-r--r--src/resources/beingcommon.cpp12
-rw-r--r--src/resources/db/itemdb.cpp12
-rw-r--r--src/utils/xml/libxml.cpp22
-rw-r--r--src/utils/xml/libxml.h9
-rw-r--r--src/utils/xml/pugixml.cpp21
-rw-r--r--src/utils/xml/pugixml.h9
-rw-r--r--src/utils/xml/tinyxml2.cpp21
-rw-r--r--src/utils/xml/tinyxml2.h9
12 files changed, 119 insertions, 52 deletions
diff --git a/src/gui/windows/skilldialog.cpp b/src/gui/windows/skilldialog.cpp
index b4e277b98..b5a49b0ca 100644
--- a/src/gui/windows/skilldialog.cpp
+++ b/src/gui/windows/skilldialog.cpp
@@ -564,26 +564,26 @@ void SkillDialog::loadSkillData(XmlNodeConstPtr node,
MissileInfo &missile = data->missile;
missile.particle = XML::getProperty(
node, "missile-particle", "");
- missile.z = static_cast<float>(XML::getFloatProperty(
- node, "missile-z", 32.0f));
+ missile.z = XML::getFloatProperty(
+ node, "missile-z", 32.0f);
missile.lifeTime = XML::getProperty(
node, "missile-lifetime", 500);
- missile.speed = static_cast<float>(XML::getFloatProperty(
- node, "missile-speed", 7.0f));
- missile.dieDistance = static_cast<float>(
- XML::getFloatProperty(node, "missile-diedistance", 8.0f));
+ missile.speed = XML::getFloatProperty(
+ node, "missile-speed", 7.0f);
+ missile.dieDistance = XML::getFloatProperty(
+ node, "missile-diedistance", 8.0f);
MissileInfo &castingMissile = data->castingMissile;
castingMissile.particle = XML::getProperty(
node, "castingMissile-particle", "");
- castingMissile.z = static_cast<float>(XML::getFloatProperty(
- node, "castingMissile-z", 32.0f));
+ castingMissile.z = XML::getFloatProperty(
+ node, "castingMissile-z", 32.0f);
castingMissile.lifeTime = XML::getProperty(
node, "castingMissile-lifetime", 500);
- castingMissile.speed = static_cast<float>(XML::getFloatProperty(
- node, "castingMissile-speed", 7.0f));
- castingMissile.dieDistance = static_cast<float>(
- XML::getFloatProperty(node, "castingMissile-diedistance", 8.0f));
+ castingMissile.speed = XML::getFloatProperty(
+ node, "castingMissile-speed", 7.0f);
+ castingMissile.dieDistance = XML::getFloatProperty(
+ node, "castingMissile-diedistance", 8.0f);
data->castingAnimation = XML::getProperty(
node,
diff --git a/src/particle/particle.cpp b/src/particle/particle.cpp
index dd5b86913..3019aeda0 100644
--- a/src/particle/particle.cpp
+++ b/src/particle/particle.cpp
@@ -475,12 +475,12 @@ Particle *Particle::addEffect(const std::string &restrict particleEffectFile,
}
// Read and set the basic properties of the particle
- const float offsetX = static_cast<float>(XML::getFloatProperty(
- effectChildNode, "position-x", 0));
- const float offsetY = static_cast<float>(XML::getFloatProperty(
- effectChildNode, "position-y", 0));
- const float offsetZ = static_cast<float>(XML::getFloatProperty(
- effectChildNode, "position-z", 0));
+ const float offsetX = XML::getFloatProperty(
+ effectChildNode, "position-x", 0);
+ const float offsetY = XML::getFloatProperty(
+ effectChildNode, "position-y", 0);
+ const float offsetZ = XML::getFloatProperty(
+ effectChildNode, "position-z", 0);
const Vector position(mPos.x + static_cast<float>(pixelX) + offsetX,
mPos.y + static_cast<float>(pixelY) + offsetY,
mPos.z + offsetZ);
diff --git a/src/particle/particleemitter.cpp b/src/particle/particleemitter.cpp
index 326daea7a..642acd851 100644
--- a/src/particle/particleemitter.cpp
+++ b/src/particle/particleemitter.cpp
@@ -473,15 +473,15 @@ ParticleEmitter::readParticleEmitterProp(XmlNodePtrConst propertyNode, T def)
{
ParticleEmitterProp<T> retval;
- def = static_cast<T>(XML::getFloatProperty(propertyNode, "value",
+ def = static_cast<T>(XML::getDoubleProperty(propertyNode, "value",
static_cast<double>(def)));
- retval.set(static_cast<T>(XML::getFloatProperty(propertyNode, "min",
- static_cast<double>(def))), static_cast<T>(XML::getFloatProperty(
+ retval.set(static_cast<T>(XML::getDoubleProperty(propertyNode, "min",
+ static_cast<double>(def))), static_cast<T>(XML::getDoubleProperty(
propertyNode, "max", static_cast<double>(def))));
const std::string change = XML::getProperty(
propertyNode, "change-func", "none");
- T amplitude = static_cast<T>(XML::getFloatProperty(propertyNode,
+ T amplitude = static_cast<T>(XML::getDoubleProperty(propertyNode,
"change-amplitude", 0.0));
const int period = XML::getProperty(propertyNode, "change-period", 0);
diff --git a/src/particle/particleengine.cpp b/src/particle/particleengine.cpp
index 51620a11e..02e21e0bc 100644
--- a/src/particle/particleengine.cpp
+++ b/src/particle/particleengine.cpp
@@ -197,12 +197,12 @@ Particle *ParticleEngine::addEffect(const std::string &restrict
}
// Read and set the basic properties of the particle
- const float offsetX = static_cast<float>(XML::getFloatProperty(
- effectChildNode, "position-x", 0));
- const float offsetY = static_cast<float>(XML::getFloatProperty(
- effectChildNode, "position-y", 0));
- const float offsetZ = static_cast<float>(XML::getFloatProperty(
- effectChildNode, "position-z", 0));
+ const float offsetX = XML::getFloatProperty(
+ effectChildNode, "position-x", 0);
+ const float offsetY = XML::getFloatProperty(
+ effectChildNode, "position-y", 0);
+ const float offsetZ = XML::getFloatProperty(
+ effectChildNode, "position-z", 0);
const Vector position(static_cast<float>(pixelX) + offsetX,
static_cast<float>(pixelY) + offsetY,
offsetZ);
diff --git a/src/resources/beingcommon.cpp b/src/resources/beingcommon.cpp
index e2294f37d..441b1ee7c 100644
--- a/src/resources/beingcommon.cpp
+++ b/src/resources/beingcommon.cpp
@@ -231,14 +231,14 @@ bool BeingCommon::readObjectNodes(XmlNodePtrConst &spriteNode,
const std::string missileParticle = XML::getProperty(spriteNode,
"missile-particle", "");
- const float missileZ = static_cast<float>(XML::getFloatProperty(
- spriteNode, "missile-z", 32.0f));
+ const float missileZ = XML::getFloatProperty(
+ spriteNode, "missile-z", 32.0f);
const int missileLifeTime = XML::getProperty(
spriteNode, "missile-lifetime", 500);
- const float missileSpeed = static_cast<float>(XML::getFloatProperty(
- spriteNode, "missile-speed", 7.0f));
- const float missileDieDistance = static_cast<float>(
- XML::getFloatProperty(spriteNode, "missile-diedistance", 8.0f));
+ const float missileSpeed = XML::getFloatProperty(
+ spriteNode, "missile-speed", 7.0f);
+ const float missileDieDistance = XML::getFloatProperty(
+ spriteNode, "missile-diedistance", 8.0f);
currentInfo->addAttack(attackId,
spriteAction,
diff --git a/src/resources/db/itemdb.cpp b/src/resources/db/itemdb.cpp
index 9fcedeab1..a1395142a 100644
--- a/src/resources/db/itemdb.cpp
+++ b/src/resources/db/itemdb.cpp
@@ -396,14 +396,14 @@ void ItemDB::loadXmlFile(const std::string &fileName,
int attackRange = XML::getProperty(node, "attack-range", 0);
std::string missileParticle = XML::getProperty(
node, "missile-particle", "");
- float missileZ = static_cast<float>(XML::getFloatProperty(
- node, "missile-z", 32.0f));
+ float missileZ = XML::getFloatProperty(
+ node, "missile-z", 32.0f);
int missileLifeTime = XML::getProperty(
node, "missile-lifetime", 500);
- float missileSpeed = static_cast<float>(XML::getFloatProperty(
- node, "missile-speed", 7.0f));
- float missileDieDistance = static_cast<float>(XML::getFloatProperty(
- node, "missile-diedistance", 8.0f));
+ float missileSpeed = XML::getFloatProperty(
+ node, "missile-speed", 7.0f);
+ float missileDieDistance = XML::getFloatProperty(
+ node, "missile-diedistance", 8.0f);
int hitEffectId = XML::getProperty(node, "hit-effect-id",
paths.getIntValue("hitEffectId"));
int criticalEffectId = XML::getProperty(
diff --git a/src/utils/xml/libxml.cpp b/src/utils/xml/libxml.cpp
index 90204fb49..251f994d5 100644
--- a/src/utils/xml/libxml.cpp
+++ b/src/utils/xml/libxml.cpp
@@ -205,9 +205,25 @@ namespace XML
return ret;
}
- double getFloatProperty(XmlNodeConstPtr node,
- const char *const name,
- double def)
+ float getFloatProperty(XmlNodeConstPtr node,
+ const char *const name,
+ float def)
+ {
+ float &ret = def;
+
+ xmlChar *const prop = XmlGetProp(node, name);
+ if (prop != nullptr)
+ {
+ ret = atof(reinterpret_cast<char*>(prop));
+ xmlFree(prop);
+ }
+
+ return ret;
+ }
+
+ double getDoubleProperty(XmlNodeConstPtr node,
+ const char *const name,
+ double def)
{
double &ret = def;
diff --git a/src/utils/xml/libxml.h b/src/utils/xml/libxml.h
index d9f707a5e..6ec0ce08d 100644
--- a/src/utils/xml/libxml.h
+++ b/src/utils/xml/libxml.h
@@ -98,7 +98,14 @@ namespace XML
/**
* Gets an floating point property from an XmlNodePtr.
*/
- double getFloatProperty(XmlNodeConstPtr node,
+ float getFloatProperty(XmlNodeConstPtr node,
+ const char *const name,
+ float def) A_WARN_UNUSED;
+
+ /**
+ * Gets an double point property from an XmlNodePtr.
+ */
+ double getDoubleProperty(XmlNodeConstPtr node,
const char *const name,
double def) A_WARN_UNUSED;
diff --git a/src/utils/xml/pugixml.cpp b/src/utils/xml/pugixml.cpp
index 12ae1d794..12d885a4f 100644
--- a/src/utils/xml/pugixml.cpp
+++ b/src/utils/xml/pugixml.cpp
@@ -212,9 +212,24 @@ namespace XML
return ret;
}
- double getFloatProperty(XmlNodeConstPtr node,
- const char *const name,
- double def)
+ float getFloatProperty(XmlNodeConstPtr node,
+ const char *const name,
+ float def)
+ {
+ float &ret = def;
+
+ if (!node)
+ return ret;
+ const pugi::xml_attribute &attr = node.attribute(name);
+ if (!attr.empty())
+ ret = atof(attr.value());
+
+ return ret;
+ }
+
+ double getDoubleProperty(XmlNodeConstPtr node,
+ const char *const name,
+ double def)
{
double &ret = def;
diff --git a/src/utils/xml/pugixml.h b/src/utils/xml/pugixml.h
index 14a3bdbdf..e4337140e 100644
--- a/src/utils/xml/pugixml.h
+++ b/src/utils/xml/pugixml.h
@@ -99,7 +99,14 @@ namespace XML
/**
* Gets an floating point property from an XmlNodePtr.
*/
- double getFloatProperty(XmlNodeConstPtr node,
+ float getFloatProperty(XmlNodeConstPtr node,
+ const char *const name,
+ float def) A_WARN_UNUSED;
+
+ /**
+ * Gets an double point property from an XmlNodePtr.
+ */
+ double getDoubleProperty(XmlNodeConstPtr node,
const char *const name,
double def) A_WARN_UNUSED;
diff --git a/src/utils/xml/tinyxml2.cpp b/src/utils/xml/tinyxml2.cpp
index 3a1646168..a7275b7f1 100644
--- a/src/utils/xml/tinyxml2.cpp
+++ b/src/utils/xml/tinyxml2.cpp
@@ -198,9 +198,24 @@ namespace XML
return ret;
}
- double getFloatProperty(XmlNodeConstPtr node,
- const char *const name,
- double def)
+ float getFloatProperty(XmlNodeConstPtr node,
+ const char *const name,
+ float def)
+ {
+ float &ret = def;
+
+ if (!node)
+ return ret;
+ const char *attr = node->Attribute(name);
+ if (attr != nullptr)
+ ret = atof(attr);
+
+ return ret;
+ }
+
+ double getDoubleProperty(XmlNodeConstPtr node,
+ const char *const name,
+ double def)
{
double &ret = def;
diff --git a/src/utils/xml/tinyxml2.h b/src/utils/xml/tinyxml2.h
index e817f7276..f056dc43a 100644
--- a/src/utils/xml/tinyxml2.h
+++ b/src/utils/xml/tinyxml2.h
@@ -99,7 +99,14 @@ namespace XML
/**
* Gets an floating point property from an XmlNodePtr.
*/
- double getFloatProperty(XmlNodeConstPtr node,
+ float getFloatProperty(XmlNodeConstPtr node,
+ const char *const name,
+ float def) A_WARN_UNUSED;
+
+ /**
+ * Gets an double point property from an XmlNodePtr.
+ */
+ double getDoubleProperty(XmlNodeConstPtr node,
const char *const name,
double def) A_WARN_UNUSED;