summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <bjorn@lindeijer.nl>2025-01-19 20:29:13 +0100
committerThorbjørn Lindeijer <bjorn@lindeijer.nl>2025-01-20 10:46:09 +0100
commitaa2613c7037bd12448d58714b4bb317ea939d892 (patch)
tree8fb57a581b439b08d95a85ad57c2b6d1d91e17c4 /src
parentbbbc318634f3be2c4d755e71d99cdfba5c2b82f3 (diff)
downloadmana-aa2613c7037bd12448d58714b4bb317ea939d892.tar.gz
mana-aa2613c7037bd12448d58714b4bb317ea939d892.tar.bz2
mana-aa2613c7037bd12448d58714b4bb317ea939d892.tar.xz
mana-aa2613c7037bd12448d58714b4bb317ea939d892.zip
Wrapped xmlNodePtr access with a Node class
Slightly more ergonomic and this eliminates direct libxml2 usage from many places.
Diffstat (limited to 'src')
-rw-r--r--src/animationparticle.cpp2
-rw-r--r--src/animationparticle.h4
-rw-r--r--src/configuration.cpp23
-rw-r--r--src/configuration.h2
-rw-r--r--src/effectmanager.cpp16
-rw-r--r--src/gui/serverdialog.cpp42
-rw-r--r--src/gui/skilldialog.cpp22
-rw-r--r--src/gui/updaterwindow.cpp18
-rw-r--r--src/net/manaserv/inventoryhandler.cpp32
-rw-r--r--src/net/manaserv/inventoryhandler.h2
-rw-r--r--src/particle.cpp52
-rw-r--r--src/particleemitter.cpp98
-rw-r--r--src/particleemitter.h4
-rw-r--r--src/resources/action.h2
-rw-r--r--src/resources/animation.h2
-rw-r--r--src/resources/attributes.cpp35
-rw-r--r--src/resources/attributes.h4
-rw-r--r--src/resources/chardb.cpp24
-rw-r--r--src/resources/emotedb.cpp14
-rw-r--r--src/resources/emotedb.h2
-rw-r--r--src/resources/hairdb.cpp6
-rw-r--r--src/resources/hairdb.h6
-rw-r--r--src/resources/itemdb.cpp113
-rw-r--r--src/resources/itemdb.h14
-rw-r--r--src/resources/mapreader.cpp156
-rw-r--r--src/resources/mapreader.h4
-rw-r--r--src/resources/monsterdb.cpp50
-rw-r--r--src/resources/monsterdb.h2
-rw-r--r--src/resources/npcdb.cpp26
-rw-r--r--src/resources/npcdb.h2
-rw-r--r--src/resources/settingsmanager.cpp57
-rw-r--r--src/resources/specialdb.cpp18
-rw-r--r--src/resources/specialdb.h2
-rw-r--r--src/resources/spritedef.cpp74
-rw-r--r--src/resources/spritedef.h12
-rw-r--r--src/resources/theme.cpp47
-rw-r--r--src/rotationalparticle.cpp2
-rw-r--r--src/rotationalparticle.h4
-rw-r--r--src/simpleanimation.cpp33
-rw-r--r--src/simpleanimation.h4
-rw-r--r--src/statuseffect.cpp28
-rw-r--r--src/statuseffect.h2
-rw-r--r--src/units.cpp22
-rw-r--r--src/units.h2
-rw-r--r--src/utils/xml.cpp72
-rw-r--r--src/utils/xml.h215
46 files changed, 668 insertions, 705 deletions
diff --git a/src/animationparticle.cpp b/src/animationparticle.cpp
index 85f66a78..feb34cca 100644
--- a/src/animationparticle.cpp
+++ b/src/animationparticle.cpp
@@ -31,7 +31,7 @@ AnimationParticle::AnimationParticle(Map *map, Animation animation):
{
}
-AnimationParticle::AnimationParticle(Map *map, xmlNodePtr animationNode,
+AnimationParticle::AnimationParticle(Map *map, XML::Node animationNode,
const std::string &dyePalettes):
ImageParticle(map, nullptr),
mAnimation(animationNode, dyePalettes)
diff --git a/src/animationparticle.h b/src/animationparticle.h
index 69b2dbbe..432664e5 100644
--- a/src/animationparticle.h
+++ b/src/animationparticle.h
@@ -25,7 +25,7 @@
#include "imageparticle.h"
#include "simpleanimation.h"
-#include <libxml/tree.h>
+#include "utils/xml.h"
class Map;
@@ -34,7 +34,7 @@ class AnimationParticle : public ImageParticle
public:
AnimationParticle(Map *map, Animation animation);
- AnimationParticle(Map *map, xmlNodePtr animationNode,
+ AnimationParticle(Map *map, XML::Node animationNode,
const std::string &dyePalettes = std::string());
~AnimationParticle() override;
diff --git a/src/configuration.cpp b/src/configuration.cpp
index 084c8563..5fc4eabd 100644
--- a/src/configuration.cpp
+++ b/src/configuration.cpp
@@ -206,21 +206,20 @@ bool Configuration::getBoolValue(const std::string &key) const
return defaultValue;
}
-void ConfigurationObject::initFromXML(xmlNodePtr parent_node)
+void ConfigurationObject::initFromXML(XML::Node parent_node)
{
clear();
- for (auto node : XML::Children(parent_node))
+ for (auto node : parent_node.children())
{
- if (xmlStrEqual(node->name, BAD_CAST "list"))
+ if (node.name() == "list")
{
// List option handling.
- std::string name = XML::getProperty(node, "name", std::string());
+ std::string name = node.getProperty("name", std::string());
- for (auto subnode : XML::Children(node))
+ for (auto subnode : node.children())
{
- if (xmlStrEqual(subnode->name, BAD_CAST name.c_str())
- && subnode->type == XML_ELEMENT_NODE)
+ if (subnode.name() == name)
{
auto *cobj = new ConfigurationObject;
@@ -231,11 +230,11 @@ void ConfigurationObject::initFromXML(xmlNodePtr parent_node)
}
}
- else if (xmlStrEqual(node->name, BAD_CAST "option"))
+ else if (node.name() == "option")
{
// Single option handling.
- std::string name = XML::getProperty(node, "name", std::string());
- std::string value = XML::getProperty(node, "value", std::string());
+ std::string name = node.getProperty("name", std::string());
+ std::string value = node.getProperty("value", std::string());
if (!name.empty())
mOptions[name] = value;
@@ -258,9 +257,9 @@ void Configuration::init(const std::string &filename, bool useResManager)
return;
}
- xmlNodePtr rootNode = doc.rootNode();
+ XML::Node rootNode = doc.rootNode();
- if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "configuration"))
+ if (!rootNode || rootNode.name() != "configuration")
{
logger->log("Warning: No configuration file (%s)", filename.c_str());
return;
diff --git a/src/configuration.h b/src/configuration.h
index 41071304..c6c115f6 100644
--- a/src/configuration.h
+++ b/src/configuration.h
@@ -171,7 +171,7 @@ class ConfigurationObject
}
protected:
- void initFromXML(xmlNodePtr node);
+ void initFromXML(XML::Node node);
void writeToXML(XML::Writer &writer) const;
void deleteList(std::list<ConfigurationObject *> &list);
diff --git a/src/effectmanager.cpp b/src/effectmanager.cpp
index e318d1e6..903f08b2 100644
--- a/src/effectmanager.cpp
+++ b/src/effectmanager.cpp
@@ -31,12 +31,12 @@
EffectManager::EffectManager()
{
XML::Document doc("effects.xml");
- xmlNodePtr root = doc.rootNode();
+ XML::Node root = doc.rootNode();
- if (!root || !xmlStrEqual(root->name, BAD_CAST "effects"))
+ if (!root || root.name() != "effects")
{
// Handle old naming until the 0.5.x versions are obsolete.
- if (!root || !xmlStrEqual(root->name, BAD_CAST "being-effects"))
+ if (!root || root.name() != "being-effects")
{
logger->log("Error loading being effects file: effects.xml");
return;
@@ -47,14 +47,14 @@ EffectManager::EffectManager()
logger->log("Effects are now loading");
}
- for (auto node : XML::Children(root))
+ for (auto node : root.children())
{
- if (xmlStrEqual(node->name, BAD_CAST "effect"))
+ if (node.name() == "effect")
{
EffectDescription &ed = mEffects.emplace_back();
- ed.id = XML::getProperty(node, "id", -1);
- ed.GFX = XML::getProperty(node, "particle", "");
- ed.SFX = XML::getProperty(node, "audio", "");
+ ed.id = node.getProperty("id", -1);
+ ed.GFX = node.getProperty("particle", "");
+ ed.SFX = node.getProperty("audio", "");
}
}
}
diff --git a/src/gui/serverdialog.cpp b/src/gui/serverdialog.cpp
index d437baae..bb978a78 100644
--- a/src/gui/serverdialog.cpp
+++ b/src/gui/serverdialog.cpp
@@ -427,15 +427,15 @@ void ServerDialog::downloadServerList()
void ServerDialog::loadServers()
{
XML::Document doc(mDir + "/serverlist.xml", false);
- xmlNodePtr rootNode = doc.rootNode();
+ XML::Node rootNode = doc.rootNode();
- if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "serverlist"))
+ if (!rootNode || rootNode.name() != "serverlist")
{
logger->log("Error loading server list!");
return;
}
- int version = XML::getProperty(rootNode, "version", 0);
+ int version = rootNode.getProperty("version", 0);
if (version != 1)
{
logger->log("Error: unsupported online server list version: %d",
@@ -443,14 +443,14 @@ void ServerDialog::loadServers()
return;
}
- for (auto serverNode : XML::Children(rootNode))
+ for (auto serverNode : rootNode.children())
{
- if (!xmlStrEqual(serverNode->name, BAD_CAST "server"))
+ if (serverNode.name() != "server")
continue;
ServerInfo server;
- std::string type = XML::getProperty(serverNode, "type", "unknown");
+ std::string type = serverNode.getProperty("type", "unknown");
server.type = ServerInfo::parseType(type);
@@ -466,9 +466,9 @@ void ServerDialog::loadServers()
continue;
}
- server.name = XML::getProperty(serverNode, "name", std::string());
+ server.name = serverNode.getProperty("name", std::string());
- std::string version = XML::getProperty(serverNode, "minimumVersion",
+ std::string version = serverNode.getProperty("minimumVersion",
std::string());
bool meetsMinimumVersion = compareStrI(version, PACKAGE_VERSION) <= 0;
@@ -481,30 +481,26 @@ void ServerDialog::loadServers()
else
version = strprintf(_("requires v%s"), version.c_str());
- for (auto subNode : XML::Children(serverNode))
+ for (auto subNode : serverNode.children())
{
- if (xmlStrEqual(subNode->name, BAD_CAST "connection"))
+ if (subNode.name() == "connection")
{
- server.hostname = XML::getProperty(subNode, "hostname", std::string());
- server.port = XML::getProperty(subNode, "port", 0);
+ server.hostname = subNode.getProperty("hostname", std::string());
+ server.port = subNode.getProperty("port", 0);
if (server.port == 0)
{
// If no port is given, use the default for the given type
server.port = ServerInfo::defaultPortForServerType(server.type);
}
}
- else if (subNode->children && subNode->children->content)
+ else if (subNode.name() == "description")
{
- const char *text = (const char*) subNode->children->content;
-
- if (xmlStrEqual(subNode->name, BAD_CAST "description"))
- {
- server.description = text;
- }
- else if (xmlStrEqual(subNode->name, BAD_CAST "persistentIp"))
- {
- server.persistentIp = strcmp(text, "1") == 0 || strcmp(text, "true") == 0;
- }
+ server.description = subNode.textContent();
+ }
+ else if (subNode.name() == "persistentIp")
+ {
+ const auto text = subNode.textContent();
+ server.persistentIp = text == "1" || text == "true";
}
}
diff --git a/src/gui/skilldialog.cpp b/src/gui/skilldialog.cpp
index 5b1676e2..5b85252d 100644
--- a/src/gui/skilldialog.cpp
+++ b/src/gui/skilldialog.cpp
@@ -313,7 +313,7 @@ void SkillDialog::loadSkills()
clearSkills();
XML::Document doc(SKILLS_FILE);
- xmlNodePtr root = doc.rootNode();
+ XML::Node root = doc.rootNode();
int setCount = 0;
std::string setName;
@@ -321,7 +321,7 @@ void SkillDialog::loadSkills()
SkillListBox *listbox;
SkillTab *tab;
- if (!root || !xmlStrEqual(root->name, BAD_CAST "skills"))
+ if (!root || root.name() != "skills")
{
logger->log("Error loading skills file: %s", SKILLS_FILE);
@@ -357,23 +357,23 @@ void SkillDialog::loadSkills()
return;
}
- for (auto set : XML::Children(root))
+ for (auto set : root.children())
{
- if (xmlStrEqual(set->name, BAD_CAST "set") ||
- xmlStrEqual(set->name, BAD_CAST "skill-set"))
+ if (set.name() == "set" ||
+ set.name() == "skill-set")
{
setCount++;
- setName = XML::getProperty(set, "name", strprintf(_("Skill Set %d"), setCount));
+ setName = set.getProperty("name", strprintf(_("Skill Set %d"), setCount));
auto *model = new SkillModel();
- for (auto node : XML::Children(set))
+ for (auto node : set.children())
{
- if (xmlStrEqual(node->name, BAD_CAST "skill"))
+ if (node.name() == "skill")
{
- int id = atoi(XML::getProperty(node, "id", "-1").c_str());
- std::string name = XML::getProperty(node, "name", strprintf(_("Skill %d"), id));
- std::string icon = XML::getProperty(node, "icon", "");
+ int id = atoi(node.getProperty("id", "-1").c_str());
+ std::string name = node.getProperty("name", strprintf(_("Skill %d"), id));
+ std::string icon = node.getProperty("icon", "");
auto *skill = new SkillInfo;
skill->id = id;
diff --git a/src/gui/updaterwindow.cpp b/src/gui/updaterwindow.cpp
index 353e2b35..a92911b4 100644
--- a/src/gui/updaterwindow.cpp
+++ b/src/gui/updaterwindow.cpp
@@ -56,26 +56,26 @@ std::vector<UpdateFile> loadXMLFile(const std::string &fileName)
{
std::vector<UpdateFile> files;
XML::Document doc(fileName, false);
- xmlNodePtr rootNode = doc.rootNode();
+ XML::Node rootNode = doc.rootNode();
- if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "updates"))
+ if (!rootNode || rootNode.name() != "updates")
{
logger->log("Error loading update file: %s", fileName.c_str());
return files;
}
- for (auto fileNode : XML::Children(rootNode))
+ for (auto fileNode : rootNode.children())
{
// Ignore all tags except for the "update" tags
- if (!xmlStrEqual(fileNode->name, BAD_CAST "update"))
+ if (fileNode.name() != "update")
continue;
UpdateFile file;
- file.name = XML::getProperty(fileNode, "file", std::string());
- file.hash = XML::getProperty(fileNode, "hash", std::string());
- file.type = XML::getProperty(fileNode, "type", "data");
- file.desc = XML::getProperty(fileNode, "description", std::string());
- file.required = XML::getProperty(fileNode, "required", "yes") == "yes";
+ file.name = fileNode.getProperty("file", std::string());
+ file.hash = fileNode.getProperty("hash", std::string());
+ file.type = fileNode.getProperty("type", "data");
+ file.desc = fileNode.getProperty("description", std::string());
+ file.required = fileNode.getProperty("required", "yes") == "yes";
files.push_back(file);
}
diff --git a/src/net/manaserv/inventoryhandler.cpp b/src/net/manaserv/inventoryhandler.cpp
index 4c110179..9754beb0 100644
--- a/src/net/manaserv/inventoryhandler.cpp
+++ b/src/net/manaserv/inventoryhandler.cpp
@@ -198,9 +198,9 @@ void EquipBackend::readEquipFile()
clear();
XML::Document doc(EQUIP_FILE);
- xmlNodePtr rootNode = doc.rootNode();
+ XML::Node rootNode = doc.rootNode();
- if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "equip-slots"))
+ if (!rootNode || rootNode.name() != "equip-slots")
{
logger->log("ManaServ::EquipBackend: Error while reading "
EQUIP_FILE "!");
@@ -211,19 +211,19 @@ void EquipBackend::readEquipFile()
unsigned int slotIndex = 0;
mVisibleSlots = 0;
- for (auto slotNode : XML::Children(rootNode))
+ for (auto slotNode : rootNode.children())
{
- if (!xmlStrEqual(slotNode->name, BAD_CAST "slot"))
+ if (slotNode.name() != "slot")
continue;
Slot slot;
- slot.slotTypeId = XML::getProperty(slotNode, "id", 0);
- std::string name = XML::getProperty(slotNode, "name", std::string());
- const int capacity = XML::getProperty(slotNode, "capacity", 1);
- slot.weaponSlot = XML::getBoolProperty(slotNode, "weapon", false);
- slot.ammoSlot = XML::getBoolProperty(slotNode, "ammo", false);
+ slot.slotTypeId = slotNode.getProperty("id", 0);
+ std::string name = slotNode.getProperty("name", std::string());
+ const int capacity = slotNode.getProperty("capacity", 1);
+ slot.weaponSlot = slotNode.getBoolProperty("weapon", false);
+ slot.ammoSlot = slotNode.getBoolProperty("ammo", false);
- if (XML::getBoolProperty(slotNode, "visible", false))
+ if (slotNode.getBoolProperty("visible", false))
++mVisibleSlots;
if (slot.slotTypeId > 0 && capacity > 0)
@@ -255,20 +255,20 @@ void EquipBackend::readEquipFile()
}
}
-void EquipBackend::readBoxNode(xmlNodePtr slotNode)
+void EquipBackend::readBoxNode(XML::Node slotNode)
{
- for (auto boxNode : XML::Children(slotNode))
+ for (auto boxNode : slotNode.children())
{
- if (!xmlStrEqual(boxNode->name, BAD_CAST "box"))
+ if (boxNode.name() != "box")
continue;
- int x = XML::getProperty(boxNode, "x" , 0);
- int y = XML::getProperty(boxNode, "y" , 0);
+ int x = boxNode.getProperty("x" , 0);
+ int y = boxNode.getProperty("y" , 0);
mBoxesPositions.push_back(Position(x, y));
std::string backgroundFile =
- XML::getProperty(boxNode, "background" , std::string());
+ boxNode.getProperty("background" , std::string());
mBoxesBackgroundFile.push_back(backgroundFile);
}
}
diff --git a/src/net/manaserv/inventoryhandler.h b/src/net/manaserv/inventoryhandler.h
index a0e978cd..e01bb5d8 100644
--- a/src/net/manaserv/inventoryhandler.h
+++ b/src/net/manaserv/inventoryhandler.h
@@ -67,7 +67,7 @@ class EquipBackend final : public Equipment::Backend, public EventListener
private:
void readEquipFile() override;
- void readBoxNode(xmlNodePtr slotNode);
+ void readBoxNode(XML::Node slotNode);
struct Slot {
// Generic info
diff --git a/src/particle.cpp b/src/particle.cpp
index 40a51888..aa195c28 100644
--- a/src/particle.cpp
+++ b/src/particle.cpp
@@ -262,9 +262,9 @@ Particle *Particle::addEffect(const std::string &particleEffectFile,
dyePalettes = particleEffectFile.substr(pos + 1);
XML::Document doc(particleEffectFile.substr(0, pos));
- xmlNodePtr rootNode = doc.rootNode();
+ XML::Node rootNode = doc.rootNode();
- if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "effect"))
+ if (!rootNode || rootNode.name() != "effect")
{
logger->log("Error loading particle: %s", particleEffectFile.c_str());
return nullptr;
@@ -273,29 +273,29 @@ Particle *Particle::addEffect(const std::string &particleEffectFile,
ResourceManager *resman = ResourceManager::getInstance();
// Parse particles
- for (auto effectChildNode : XML::Children(rootNode))
+ for (auto effectChildNode : rootNode.children())
{
// We're only interested in particles
- if (!xmlStrEqual(effectChildNode->name, BAD_CAST "particle"))
+ if (effectChildNode.name() != "particle")
continue;
// Determine the exact particle type
- xmlNodePtr node;
+ XML::Node node;
// Animation
- if ((node = XML::findFirstChildByName(effectChildNode, "animation")))
+ if ((node = effectChildNode.findFirstChildByName("animation")))
{
newParticle = new AnimationParticle(mMap, node, dyePalettes);
}
// Rotational
- else if ((node = XML::findFirstChildByName(effectChildNode, "rotation")))
+ else if ((node = effectChildNode.findFirstChildByName("rotation")))
{
newParticle = new RotationalParticle(mMap, node, dyePalettes);
}
// Image
- else if ((node = XML::findFirstChildByName(effectChildNode, "image")))
+ else if ((node = effectChildNode.findFirstChildByName("image")))
{
- std::string imageSrc = (const char*)node->children->content;
+ std::string imageSrc { node.textContent() };
if (!imageSrc.empty() && !dyePalettes.empty())
Dye::instantiate(imageSrc, dyePalettes);
@@ -309,50 +309,50 @@ Particle *Particle::addEffect(const std::string &particleEffectFile,
}
// Read and set the basic properties of the particle
- float offsetX = XML::getFloatProperty(effectChildNode, "position-x", 0);
- float offsetY = XML::getFloatProperty(effectChildNode, "position-y", 0);
- float offsetZ = XML::getFloatProperty(effectChildNode, "position-z", 0);
- Vector position (mPos.x + (float)pixelX + offsetX,
- mPos.y + (float)pixelY + offsetY,
- mPos.z + offsetZ);
+ float offsetX = effectChildNode.getFloatProperty("position-x", 0);
+ float offsetY = effectChildNode.getFloatProperty("position-y", 0);
+ float offsetZ = effectChildNode.getFloatProperty("position-z", 0);
+ Vector position(mPos.x + (float)pixelX + offsetX,
+ mPos.y + (float)pixelY + offsetY,
+ mPos.z + offsetZ);
newParticle->moveTo(position);
- int lifetime = XML::getProperty(effectChildNode, "lifetime", -1);
+ int lifetime = effectChildNode.getProperty("lifetime", -1);
newParticle->setLifetime(lifetime);
- bool resizeable = "false" != XML::getProperty(effectChildNode, "size-adjustable", "false");
+ bool resizeable = "false" != effectChildNode.getProperty("size-adjustable", "false");
newParticle->setAllowSizeAdjust(resizeable);
// Look for additional emitters for this particle
- for (auto emitterNode : XML::Children(effectChildNode))
+ for (auto emitterNode : effectChildNode.children())
{
- if (xmlStrEqual(emitterNode->name, BAD_CAST "emitter"))
+ if (emitterNode.name() == "emitter")
{
ParticleEmitter *newEmitter;
newEmitter = new ParticleEmitter(emitterNode, newParticle, mMap,
rotation, dyePalettes);
newParticle->addEmitter(newEmitter);
}
- else if (xmlStrEqual(emitterNode->name, BAD_CAST "deatheffect"))
+ else if (emitterNode.name() == "deatheffect")
{
- std::string deathEffect = (const char*)emitterNode->children->content;
+ std::string deathEffect { emitterNode.textContent() };
char deathEffectConditions = 0x00;
- if (XML::getBoolProperty(emitterNode, "on-floor", true))
+ if (emitterNode.getBoolProperty("on-floor", true))
{
deathEffectConditions += Particle::DEAD_FLOOR;
}
- if (XML::getBoolProperty(emitterNode, "on-sky", true))
+ if (emitterNode.getBoolProperty("on-sky", true))
{
deathEffectConditions += Particle::DEAD_SKY;
}
- if (XML::getBoolProperty(emitterNode, "on-other", false))
+ if (emitterNode.getBoolProperty("on-other", false))
{
deathEffectConditions += Particle::DEAD_OTHER;
}
- if (XML::getBoolProperty(emitterNode, "on-impact", true))
+ if (emitterNode.getBoolProperty("on-impact", true))
{
deathEffectConditions += Particle::DEAD_IMPACT;
}
- if (XML::getBoolProperty(emitterNode, "on-timeout", true))
+ if (emitterNode.getBoolProperty("on-timeout", true))
{
deathEffectConditions += Particle::DEAD_TIMEOUT;
}
diff --git a/src/particleemitter.cpp b/src/particleemitter.cpp
index 3add4cb0..f45d39bd 100644
--- a/src/particleemitter.cpp
+++ b/src/particleemitter.cpp
@@ -39,7 +39,7 @@
#define SIN45 0.707106781f
#define DEG_RAD_FACTOR 0.017453293f
-ParticleEmitter::ParticleEmitter(xmlNodePtr emitterNode, Particle *target,
+ParticleEmitter::ParticleEmitter(XML::Node emitterNode, Particle *target,
Map *map, int rotation,
const std::string &dyePalettes)
{
@@ -67,11 +67,11 @@ ParticleEmitter::ParticleEmitter(xmlNodePtr emitterNode, Particle *target,
mOutputPause.set(0);
mParticleAlpha.set(1.0f);
- for (auto propertyNode : XML::Children(emitterNode))
+ for (auto propertyNode : emitterNode.children())
{
- if (xmlStrEqual(propertyNode->name, BAD_CAST "property"))
+ if (propertyNode.name() == "property")
{
- std::string name = XML::getProperty(propertyNode, "name", "");
+ std::string name = propertyNode.getProperty("name", "");
if (name == "position-x")
{
@@ -94,7 +94,7 @@ ParticleEmitter::ParticleEmitter(xmlNodePtr emitterNode, Particle *target,
}
else if (name == "image")
{
- std::string image = XML::getProperty(propertyNode, "value", "");
+ std::string image = propertyNode.getProperty("value", "");
// Don't leak when multiple images are defined
if (!image.empty() && !mParticleImage)
{
@@ -187,26 +187,26 @@ ParticleEmitter::ParticleEmitter(xmlNodePtr emitterNode, Particle *target,
);
}
}
- else if (xmlStrEqual(propertyNode->name, BAD_CAST "emitter"))
+ else if (propertyNode.name() == "emitter")
{
ParticleEmitter newEmitter(propertyNode, mParticleTarget, map,
rotation, dyePalettes);
mParticleChildEmitters.push_back(newEmitter);
}
- else if (xmlStrEqual(propertyNode->name, BAD_CAST "rotation"))
+ else if (propertyNode.name() == "rotation")
{
ImageSet *imageset = ResourceManager::getInstance()->getImageSet(
- XML::getProperty(propertyNode, "imageset", ""),
- XML::getProperty(propertyNode, "width", 0),
- XML::getProperty(propertyNode, "height", 0)
+ propertyNode.getProperty("imageset", ""),
+ propertyNode.getProperty("width", 0),
+ propertyNode.getProperty("height", 0)
);
// Get animation frames
- for (auto frameNode : XML::Children(propertyNode))
+ for (auto frameNode : propertyNode.children())
{
- int delay = XML::getProperty(frameNode, "delay", 0);
- int offsetX = XML::getProperty(frameNode, "offsetX", 0);
- int offsetY = XML::getProperty(frameNode, "offsetY", 0);
+ int delay = frameNode.getProperty("delay", 0);
+ int offsetX = frameNode.getProperty("offsetX", 0);
+ int offsetY = frameNode.getProperty("offsetY", 0);
if (mMap)
{
offsetX -= imageset->getWidth() / 2
@@ -214,9 +214,9 @@ ParticleEmitter::ParticleEmitter(xmlNodePtr emitterNode, Particle *target,
offsetY -= imageset->getHeight() - mMap->getTileHeight();
}
- if (xmlStrEqual(frameNode->name, BAD_CAST "frame"))
+ if (frameNode.name() == "frame")
{
- int index = XML::getProperty(frameNode, "index", -1);
+ int index = frameNode.getProperty("index", -1);
if (index < 0)
{
@@ -234,10 +234,10 @@ ParticleEmitter::ParticleEmitter(xmlNodePtr emitterNode, Particle *target,
mParticleRotation.addFrame(img, delay, offsetX, offsetY);
}
- else if (xmlStrEqual(frameNode->name, BAD_CAST "sequence"))
+ else if (frameNode.name() == "sequence")
{
- int start = XML::getProperty(frameNode, "start", -1);
- int end = XML::getProperty(frameNode, "end", -1);
+ int start = frameNode.getProperty("start", -1);
+ int end = frameNode.getProperty("end", -1);
if (start < 0 || end < 0)
{
@@ -259,20 +259,20 @@ ParticleEmitter::ParticleEmitter(xmlNodePtr emitterNode, Particle *target,
start++;
}
}
- else if (xmlStrEqual(frameNode->name, BAD_CAST "end"))
+ else if (frameNode.name() == "end")
{
mParticleRotation.addTerminator();
}
} // for frameNode
}
- else if (xmlStrEqual(propertyNode->name, BAD_CAST "animation"))
+ else if (propertyNode.name() == "animation")
{
std::string imagesetPath =
- XML::getProperty(propertyNode, "imageset", "");
+ propertyNode.getProperty("imageset", "");
ImageSet *imageset = ResourceManager::getInstance()->getImageSet(
imagesetPath,
- XML::getProperty(propertyNode, "width", 0),
- XML::getProperty(propertyNode, "height", 0)
+ propertyNode.getProperty("width", 0),
+ propertyNode.getProperty("height", 0)
);
if (!imageset)
@@ -280,17 +280,17 @@ ParticleEmitter::ParticleEmitter(xmlNodePtr emitterNode, Particle *target,
imagesetPath.c_str()));
// Get animation frames
- for (auto frameNode : XML::Children(propertyNode))
+ for (auto frameNode : propertyNode.children())
{
- int delay = XML::getProperty(frameNode, "delay", 0);
- int offsetX = XML::getProperty(frameNode, "offsetX", 0);
- int offsetY = XML::getProperty(frameNode, "offsetY", 0);
+ int delay = frameNode.getProperty("delay", 0);
+ int offsetX = frameNode.getProperty("offsetX", 0);
+ int offsetY = frameNode.getProperty("offsetY", 0);
offsetY -= imageset->getHeight() - 32;
offsetX -= imageset->getWidth() / 2 - 16;
- if (xmlStrEqual(frameNode->name, BAD_CAST "frame"))
+ if (frameNode.name() == "frame")
{
- int index = XML::getProperty(frameNode, "index", -1);
+ int index = frameNode.getProperty("index", -1);
if (index < 0)
{
@@ -308,10 +308,10 @@ ParticleEmitter::ParticleEmitter(xmlNodePtr emitterNode, Particle *target,
mParticleAnimation.addFrame(img, delay, offsetX, offsetY);
}
- else if (xmlStrEqual(frameNode->name, BAD_CAST "sequence"))
+ else if (frameNode.name() == "sequence")
{
- int start = XML::getProperty(frameNode, "start", -1);
- int end = XML::getProperty(frameNode, "end", -1);
+ int start = frameNode.getProperty("start", -1);
+ int end = frameNode.getProperty("end", -1);
if (start < 0 || end < 0)
{
@@ -333,32 +333,32 @@ ParticleEmitter::ParticleEmitter(xmlNodePtr emitterNode, Particle *target,
start++;
}
}
- else if (xmlStrEqual(frameNode->name, BAD_CAST "end"))
+ else if (frameNode.name() == "end")
{
mParticleAnimation.addTerminator();
}
} // for frameNode
- } else if (xmlStrEqual(propertyNode->name, BAD_CAST "deatheffect"))
+ } else if (propertyNode.name() == "deatheffect")
{
- mDeathEffect = (const char*)propertyNode->children->content;
+ mDeathEffect = propertyNode.textContent();
mDeathEffectConditions = 0x00;
- if (XML::getBoolProperty(propertyNode, "on-floor", true))
+ if (propertyNode.getBoolProperty("on-floor", true))
{
mDeathEffectConditions += Particle::DEAD_FLOOR;
}
- if (XML::getBoolProperty(propertyNode, "on-sky", true))
+ if (propertyNode.getBoolProperty("on-sky", true))
{
mDeathEffectConditions += Particle::DEAD_SKY;
}
- if (XML::getBoolProperty(propertyNode, "on-other", false))
+ if (propertyNode.getBoolProperty("on-other", false))
{
mDeathEffectConditions += Particle::DEAD_OTHER;
}
- if (XML::getBoolProperty(propertyNode, "on-impact", true))
+ if (propertyNode.getBoolProperty("on-impact", true))
{
mDeathEffectConditions += Particle::DEAD_IMPACT;
}
- if (XML::getBoolProperty(propertyNode, "on-timeout", true))
+ if (propertyNode.getBoolProperty("on-timeout", true))
{
mDeathEffectConditions += Particle::DEAD_TIMEOUT;
}
@@ -409,18 +409,18 @@ ParticleEmitter::~ParticleEmitter() = default;
template <typename T> ParticleEmitterProp<T>
-ParticleEmitter::readParticleEmitterProp(xmlNodePtr propertyNode, T def)
+ParticleEmitter::readParticleEmitterProp(XML::Node propertyNode, T def)
{
ParticleEmitterProp<T> retval;
- def = (T) XML::getFloatProperty(propertyNode, "value", (double) def);
- retval.set((T) XML::getFloatProperty(propertyNode, "min", (double) def),
- (T) XML::getFloatProperty(propertyNode, "max", (double) def));
+ def = (T) propertyNode.getFloatProperty("value", (double) def);
+ retval.set((T) propertyNode.getFloatProperty("min", (double) def),
+ (T) propertyNode.getFloatProperty("max", (double) def));
- std::string change = XML::getProperty(propertyNode, "change-func", "none");
- T amplitude = (T) XML::getFloatProperty(propertyNode, "change-amplitude", 0.0);
- int period = XML::getProperty(propertyNode, "change-period", 0);
- int phase = XML::getProperty(propertyNode, "change-phase", 0);
+ std::string change = propertyNode.getProperty("change-func", "none");
+ T amplitude = (T) propertyNode.getFloatProperty("change-amplitude", 0.0);
+ int period = propertyNode.getProperty("change-period", 0);
+ int phase = propertyNode.getProperty("change-phase", 0);
if (change == "saw" || change == "sawtooth")
retval.setFunction(FUNC_SAW, amplitude, period, phase);
else if (change == "sine" || change == "sinewave")
diff --git a/src/particleemitter.h b/src/particleemitter.h
index 512272ff..9d226209 100644
--- a/src/particleemitter.h
+++ b/src/particleemitter.h
@@ -42,7 +42,7 @@ class Particle;
class ParticleEmitter
{
public:
- ParticleEmitter(xmlNodePtr emitterNode, Particle *target, Map *map,
+ ParticleEmitter(XML::Node emitterNode, Particle *target, Map *map,
int rotation = 0,
const std::string& dyePalettes = std::string());
@@ -77,7 +77,7 @@ class ParticleEmitter
void adjustSize(int w, int h);
private:
- template <typename T> ParticleEmitterProp<T> readParticleEmitterProp(xmlNodePtr propertyNode, T def);
+ template <typename T> ParticleEmitterProp<T> readParticleEmitterProp(XML::Node propertyNode, T def);
/**
* initial position of particles:
diff --git a/src/resources/action.h b/src/resources/action.h
index 8a9a76f2..37f29810 100644
--- a/src/resources/action.h
+++ b/src/resources/action.h
@@ -22,8 +22,6 @@
#ifndef ACTION_H
#define ACTION_H
-#include <libxml/tree.h>
-
#include <map>
class Animation;
diff --git a/src/resources/animation.h b/src/resources/animation.h
index 7fc14857..812e0547 100644
--- a/src/resources/animation.h
+++ b/src/resources/animation.h
@@ -22,8 +22,6 @@
#ifndef ANIMATION_H
#define ANIMATION_H
-#include <libxml/tree.h>
-
#include <vector>
class Image;
diff --git a/src/resources/attributes.cpp b/src/resources/attributes.cpp
index 29ef8dec..ab270b65 100644
--- a/src/resources/attributes.cpp
+++ b/src/resources/attributes.cpp
@@ -235,9 +235,9 @@ namespace Attributes {
/**
* Read attribute node
*/
- void readAttributeNode(xmlNodePtr node, const std::string &filename)
+ void readAttributeNode(XML::Node node, const std::string &filename)
{
- int id = XML::getProperty(node, "id", 0);
+ int id = node.getProperty("id", 0);
if (!id)
{
@@ -250,7 +250,7 @@ namespace Attributes {
logger->log("Attributes: Redefinition of stat ID %d", id);
}
- std::string name = XML::getProperty(node, "name", "");
+ std::string name = node.getProperty("name", "");
if (name.empty())
{
@@ -260,24 +260,22 @@ namespace Attributes {
}
// Create the attribute.
- Attribute a;
+ Attribute &a = attributes[id];
a.id = id;
a.name = name;
- a.description = XML::getProperty(node, "desc", "");
- a.modifiable = XML::getBoolProperty(node, "modifiable", false);
- a.scope = XML::getProperty(node, "scope", "none");
+ a.description = node.getProperty("desc", std::string());
+ a.modifiable = node.getBoolProperty("modifiable", false);
+ a.scope = node.getProperty("scope", "none");
a.playerInfoId = getPlayerInfoIdFromAttrType(
- XML::getProperty(node, "player-info", ""));
-
- attributes[id] = a;
+ node.getProperty("player-info", ""));
unsigned int count = 0;
- for (auto effectNode : XML::Children(node))
+ for (auto effectNode : node.children())
{
- if (!xmlStrEqual(effectNode->name, BAD_CAST "modifier"))
+ if (effectNode.name() != "modifier")
continue;
++count;
- std::string tag = XML::getProperty(effectNode, "tag", "");
+ std::string tag = effectNode.getProperty("tag", "");
if (tag.empty())
{
if (name.empty())
@@ -293,7 +291,7 @@ namespace Attributes {
tag = toLower(tag) + toString(count);
}
- std::string effect = XML::getProperty(effectNode, "effect", "");
+ std::string effect = effectNode.getProperty("effect", "");
if (effect.empty())
{
if (name.empty())
@@ -311,18 +309,17 @@ namespace Attributes {
tags.insert(std::make_pair(tag, effect));
}
logger->log("Found %d tags for attribute %d.", count, id);
-
}
/**
* Read points node
*/
- void readPointsNode(xmlNodePtr node, const std::string &filename)
+ void readPointsNode(XML::Node node, const std::string &filename)
{
- creationPoints = XML::getProperty(node, "start",DEFAULT_POINTS);
- attributeMinimum = XML::getProperty(node, "minimum",
+ creationPoints = node.getProperty("start",DEFAULT_POINTS);
+ attributeMinimum = node.getProperty("minimum",
DEFAULT_MIN_PTS);
- attributeMaximum = XML::getProperty(node, "maximum",
+ attributeMaximum = node.getProperty("maximum",
DEFAULT_MAX_PTS);
logger->log("Loaded points: start: %i, min: %i, max: %i.",
creationPoints, attributeMinimum, attributeMaximum);
diff --git a/src/resources/attributes.h b/src/resources/attributes.h
index 41093af2..9071d6b8 100644
--- a/src/resources/attributes.h
+++ b/src/resources/attributes.h
@@ -31,9 +31,9 @@ namespace Attributes
void init();
- void readAttributeNode(xmlNodePtr node, const std::string &filename);
+ void readAttributeNode(XML::Node node, const std::string &filename);
- void readPointsNode(xmlNodePtr node, const std::string &filename);
+ void readPointsNode(XML::Node node, const std::string &filename);
void checkStatus();
diff --git a/src/resources/chardb.cpp b/src/resources/chardb.cpp
index ff0a4749..9001b6c2 100644
--- a/src/resources/chardb.cpp
+++ b/src/resources/chardb.cpp
@@ -38,10 +38,10 @@ namespace
std::vector<int> mDefaultItems;
}
-static void loadMinMax(xmlNodePtr node, unsigned *min, unsigned *max)
+static void loadMinMax(XML::Node node, unsigned *min, unsigned *max)
{
- *min = XML::getProperty(node, "min", 1);
- *max = XML::getProperty(node, "max", 10);
+ *min = node.getProperty("min", 1);
+ *max = node.getProperty("max", 10);
}
void CharDB::load()
@@ -50,32 +50,32 @@ void CharDB::load()
unload();
XML::Document doc("charcreation.xml");
- xmlNodePtr root = doc.rootNode();
+ XML::Node root = doc.rootNode();
- if (!root || !xmlStrEqual(root->name, BAD_CAST "chars"))
+ if (!root || root.name() != "chars")
{
logger->log("CharDB: Failed to parse charcreation.xml.");
return;
}
- for (auto node : XML::Children(root))
+ for (auto node : root.children())
{
- if (xmlStrEqual(node->name, BAD_CAST "haircolor"))
+ if (node.name() == "haircolor")
{
loadMinMax(node, &mMinHairColor, &mMaxHairColor);
}
- else if (xmlStrEqual(node->name, BAD_CAST "hairstyle"))
+ else if (node.name() == "hairstyle")
{
loadMinMax(node, &mMinHairStyle, &mMaxHairStyle);
}
- else if (xmlStrEqual(node->name, BAD_CAST "stat"))
+ else if (node.name() == "stat")
{
loadMinMax(node, &mMinStat, &mMaxStat);
- mSumStat = XML::getProperty(node, "sum", 0);
+ mSumStat = node.getProperty("sum", 0);
}
- else if (xmlStrEqual(node->name, BAD_CAST "item"))
+ else if (node.name() == "item")
{
- const int id = XML::getProperty(node, "id", 0);
+ const int id = node.getProperty("id", 0);
if (id > 0)
mDefaultItems.push_back(id);
}
diff --git a/src/resources/emotedb.cpp b/src/resources/emotedb.cpp
index a7130d58..6f1ec6e4 100644
--- a/src/resources/emotedb.cpp
+++ b/src/resources/emotedb.cpp
@@ -48,9 +48,9 @@ void EmoteDB::init()
ResourceManager::getInstance()->getImageRef("graphics/sprites/error.png"));
}
-void EmoteDB::readEmoteNode(xmlNodePtr node, const std::string &filename)
+void EmoteDB::readEmoteNode(XML::Node node, const std::string &filename)
{
- const int id = XML::getProperty(node, "id", -1);
+ const int id = node.getProperty("id", -1);
if (id == -1)
{
logger->log("Emote Database: Emote with missing ID in %s!", filename.c_str());
@@ -60,8 +60,8 @@ void EmoteDB::readEmoteNode(xmlNodePtr node, const std::string &filename)
Emote emote;
emote.id = id;
- emote.name = XML::getProperty(node, "name", "unknown");
- emote.effectId = XML::getProperty(node, "effectid", -1);
+ emote.name = node.getProperty("name", "unknown");
+ emote.effectId = node.getProperty("effectid", -1);
if (emote.effectId == -1)
{
@@ -70,9 +70,9 @@ void EmoteDB::readEmoteNode(xmlNodePtr node, const std::string &filename)
return;
}
- const std::string imageName = XML::getProperty(node, "image", "");
- const int width = XML::getProperty(node, "width", 0);
- const int height = XML::getProperty(node, "height", 0);
+ const std::string imageName = node.getProperty("image", "");
+ const int width = node.getProperty("width", 0);
+ const int height = node.getProperty("height", 0);
if (imageName.empty() || width <= 0 || height <= 0)
{
diff --git a/src/resources/emotedb.h b/src/resources/emotedb.h
index a6f93211..7c6f4644 100644
--- a/src/resources/emotedb.h
+++ b/src/resources/emotedb.h
@@ -48,7 +48,7 @@ namespace EmoteDB
{
void init();
- void readEmoteNode(xmlNodePtr node, const std::string &filename);
+ void readEmoteNode(XML::Node node, const std::string &filename);
void checkStatus();
diff --git a/src/resources/hairdb.cpp b/src/resources/hairdb.cpp
index 09ac14f4..6b88a4df 100644
--- a/src/resources/hairdb.cpp
+++ b/src/resources/hairdb.cpp
@@ -35,14 +35,14 @@ void HairDB::init()
mHairColors[0] = COLOR_WHITE;
}
-void HairDB::readHairColorNode(xmlNodePtr node, const std::string &filename)
+void HairDB::readHairColorNode(XML::Node node, const std::string &filename)
{
- int id = XML::getProperty(node, "id", 0);
+ int id = node.getProperty("id", 0);
if (mHairColors.find(id) != mHairColors.end())
logger->log("HairDb: Redefinition of color Id %d in %s", id, filename.c_str());
- mHairColors[id] = XML::getProperty(node, "value", COLOR_WHITE);
+ mHairColors[id] = node.getProperty("value", COLOR_WHITE);
}
void HairDB::checkStatus()
diff --git a/src/resources/hairdb.h b/src/resources/hairdb.h
index 7da08b8f..374f2e03 100644
--- a/src/resources/hairdb.h
+++ b/src/resources/hairdb.h
@@ -41,7 +41,7 @@ public:
void init();
- void readHairColorNode(xmlNodePtr node, const std::string &filename);
+ void readHairColorNode(XML::Node node, const std::string &filename);
void checkStatus();
@@ -76,14 +76,14 @@ private:
/**
* Load the hair colors, contained in a <colors> node.
*/
- void loadHairColorsNode(xmlNodePtr colorsNode);
+ void loadHairColorsNode(XML::Node colorsNode);
/**
* Load the hair styles, contained in a <styles> node.
* Used only by Manaserv. TMW-Athena is considering hairstyles as items.
* @see ItemDB
*/
- void loadHairStylesNode(xmlNodePtr stylesNode);
+ void loadHairStylesNode(XML::Node stylesNode);
// Hair colors Db
std::map<int, std::string> mHairColors;
diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp
index 752664d7..68ddcd75 100644
--- a/src/resources/itemdb.cpp
+++ b/src/resources/itemdb.cpp
@@ -31,7 +31,6 @@
#include "utils/stringutils.h"
#include "configuration.h"
-#include <libxml/tree.h>
#include <cassert>
@@ -116,12 +115,12 @@ const ItemInfo &ItemDB::get(const std::string &name) const
return *(i->second);
}
-void ItemDB::loadSpriteRef(ItemInfo &itemInfo, xmlNodePtr node)
+void ItemDB::loadSpriteRef(ItemInfo &itemInfo, XML::Node node)
{
- std::string gender = XML::getProperty(node, "gender", "unisex");
- std::string filename = (const char*) node->children->content;
+ std::string gender = node.getProperty("gender", "unisex");
+ std::string filename { node.textContent() };
- const int race = XML::getProperty(node, "race", 0);
+ const int race = node.getProperty("race", 0);
if (gender == "male" || gender == "unisex")
itemInfo.setSprite(filename, Gender::MALE, race);
if (gender == "female" || gender == "unisex")
@@ -130,10 +129,10 @@ void ItemDB::loadSpriteRef(ItemInfo &itemInfo, xmlNodePtr node)
itemInfo.setSprite(filename, Gender::HIDDEN, race);
}
-void ItemDB::loadSoundRef(ItemInfo &itemInfo, xmlNodePtr node)
+void ItemDB::loadSoundRef(ItemInfo &itemInfo, XML::Node node)
{
- std::string event = XML::getProperty(node, "event", std::string());
- std::string filename = (const char*) node->children->content;
+ std::string event = node.getProperty("event", std::string());
+ std::string filename { node.textContent() };
if (event == "hit")
{
@@ -150,20 +149,19 @@ void ItemDB::loadSoundRef(ItemInfo &itemInfo, xmlNodePtr node)
}
}
-void ItemDB::loadFloorSprite(SpriteDisplay &display, xmlNodePtr floorNode)
+void ItemDB::loadFloorSprite(SpriteDisplay &display, XML::Node floorNode)
{
- for (auto spriteNode : XML::Children(floorNode))
+ for (auto spriteNode : floorNode.children())
{
- if (xmlStrEqual(spriteNode->name, BAD_CAST "sprite"))
+ if (spriteNode.name() == "sprite")
{
SpriteReference &currentSprite = display.sprites.emplace_back();
- currentSprite.sprite = (const char*)spriteNode->children->content;
- currentSprite.variant = XML::getProperty(spriteNode, "variant", 0);
+ currentSprite.sprite = spriteNode.textContent();
+ currentSprite.variant = spriteNode.getProperty("variant", 0);
}
- else if (xmlStrEqual(spriteNode->name, BAD_CAST "particlefx"))
+ else if (spriteNode.name() == "particlefx")
{
- display.particles.emplace_back(
- (const char*)spriteNode->children->content);
+ display.particles.emplace_back(spriteNode.textContent());
}
}
}
@@ -181,9 +179,9 @@ void ItemDB::unload()
mLoaded = false;
}
-void ItemDB::loadCommonRef(ItemInfo &itemInfo, xmlNodePtr node, const std::string &filename)
+void ItemDB::loadCommonRef(ItemInfo &itemInfo, XML::Node node, const std::string &filename)
{
- itemInfo.id = XML::getProperty(node, "id", 0);
+ itemInfo.id = node.getProperty("id", 0);
if (!itemInfo.id)
{
@@ -195,40 +193,38 @@ void ItemDB::loadCommonRef(ItemInfo &itemInfo, xmlNodePtr node, const std::strin
logger->log("ItemDB: Redefinition of item Id %d in %s", itemInfo.id, filename.c_str());
}
- itemInfo.mView = XML::getProperty(node, "view", 0);
- itemInfo.name = XML::getProperty(node, "name", std::string());
- itemInfo.display.image = XML::getProperty(node, "image", std::string());
- itemInfo.description = XML::getProperty(node, "description", std::string());
- itemInfo.attackAction = XML::getProperty(node, "attack-action", SpriteAction::INVALID);
- itemInfo.attackRange = XML::getProperty(node, "attack-range", 0);
- itemInfo.missileParticleFile = XML::getProperty(node, "missile-particle", std::string());
- itemInfo.hitEffectId = XML::getProperty(node, "hit-effect-id",
+ itemInfo.mView = node.getProperty("view", 0);
+ itemInfo.name = node.getProperty("name", std::string());
+ itemInfo.display.image = node.getProperty("image", std::string());
+ itemInfo.description = node.getProperty("description", std::string());
+ itemInfo.attackAction = node.getProperty("attack-action", SpriteAction::INVALID);
+ itemInfo.attackRange = node.getProperty("attack-range", 0);
+ itemInfo.missileParticleFile = node.getProperty("missile-particle", std::string());
+ itemInfo.hitEffectId = node.getProperty("hit-effect-id",
paths.getIntValue("hitEffectId"));
- itemInfo.criticalHitEffectId = XML::getProperty(node, "critical-hit-effect-id",
+ itemInfo.criticalHitEffectId = node.getProperty("critical-hit-effect-id",
paths.getIntValue("criticalHitEffectId"));
// Load Ta Item Type
- std::string typeStr = XML::getProperty(node, "type", "other");
+ std::string typeStr = node.getProperty("type", "other");
itemInfo.type = itemTypeFromString(typeStr);
- itemInfo.weight = XML::getProperty(node, "weight", 0);
+ itemInfo.weight = node.getProperty("weight", 0);
- for (auto itemChild : XML::Children(node))
+ for (auto itemChild : node.children())
{
- if (xmlStrEqual(itemChild->name, BAD_CAST "sprite"))
+ if (itemChild.name() == "sprite")
{
loadSpriteRef(itemInfo, itemChild);
}
- else if (xmlStrEqual(itemChild->name, BAD_CAST "particlefx"))
+ else if (itemChild.name() == "particlefx")
{
- if (itemChild->children && itemChild->children->content)
- itemInfo.display.particles.emplace_back(
- (const char*)itemChild->children->content);
+ itemInfo.display.particles.emplace_back(itemChild.textContent());
}
- else if (xmlStrEqual(itemChild->name, BAD_CAST "sound"))
+ else if (itemChild.name() == "sound")
{
loadSoundRef(itemInfo, itemChild);
}
- else if (xmlStrEqual(itemChild->name, BAD_CAST "floor"))
+ else if (itemChild.name() == "floor")
{
loadFloorSprite(itemInfo.display, itemChild);
}
@@ -299,7 +295,7 @@ void TaItemDB::init()
unload();
}
-void TaItemDB::readItemNode(xmlNodePtr node, const std::string &filename)
+void TaItemDB::readItemNode(XML::Node node, const std::string &filename)
{
auto *itemInfo = new ItemInfo;
@@ -314,19 +310,19 @@ void TaItemDB::readItemNode(xmlNodePtr node, const std::string &filename)
std::vector<std::string> effect;
for (auto field : fields)
{
- int value = XML::getProperty(node, field[0], 0);
+ int value = node.getProperty(field[0], 0);
if (!value)
continue;
effect.push_back(strprintf(gettext(field[1]), value));
}
for (auto &extraStat : extraStats)
{
- int value = XML::getProperty(node, extraStat.mTag.c_str(), 0);
+ int value = node.getProperty(extraStat.mTag.c_str(), 0);
if (!value)
continue;
effect.push_back(strprintf(extraStat.mFormat.c_str(), value));
}
- std::string temp = XML::getProperty(node, "effect", std::string());
+ std::string temp = node.getProperty("effect", std::string());
if (!temp.empty())
effect.push_back(temp);
@@ -369,7 +365,7 @@ void ManaServItemDB::init()
unload();
}
-void ManaServItemDB::readItemNode(xmlNodePtr node, const std::string &filename)
+void ManaServItemDB::readItemNode(XML::Node node, const std::string &filename)
{
// Trigger table for effect descriptions
// FIXME: This should ideally be softcoded via XML or similar.
@@ -393,18 +389,17 @@ void ManaServItemDB::readItemNode(xmlNodePtr node, const std::string &filename)
// Load <equip>, and <effect> sub nodes.
std::vector<std::string> effect;
- for (auto itemChild : XML::Children(node))
+ for (auto itemChild : node.children())
{
- if (xmlStrEqual(itemChild->name, BAD_CAST "equip"))
+ if (itemChild.name() == "equip")
{
// The fact that there is a way to equip is enough.
// Discard any details, but mark the item as equippable.
itemInfo->equippable = true;
}
- else if (xmlStrEqual(itemChild->name, BAD_CAST "effect"))
+ else if (itemChild.name() == "effect")
{
- std::string trigger = XML::getProperty(
- itemChild, "trigger", std::string());
+ std::string trigger = itemChild.getProperty("trigger", std::string());
if (trigger.empty())
{
logger->log("Found empty trigger effect label in %s, skipping.", filename.c_str());
@@ -422,16 +417,13 @@ void ManaServItemDB::readItemNode(xmlNodePtr node, const std::string &filename)
continue;
}
- for (auto effectChild : XML::Children(itemChild))
+ for (auto effectChild : itemChild.children())
{
- if (xmlStrEqual(effectChild->name, BAD_CAST "modifier"))
+ if (effectChild.name() == "modifier")
{
- std::string attribute = XML::getProperty(
- effectChild, "attribute", std::string());
- double value = XML::getFloatProperty(
- effectChild, "value", 0.0);
- int duration = XML::getProperty(
- effectChild, "duration", 0);
+ std::string attribute = effectChild.getProperty("attribute", std::string());
+ double value = effectChild.getFloatProperty("value", 0.0);
+ int duration = effectChild.getProperty("duration", 0);
if (attribute.empty() || !value)
{
logger->log("Warning: incomplete modifier definition in %s, skipping.", filename.c_str());
@@ -452,15 +444,14 @@ void ManaServItemDB::readItemNode(xmlNodePtr node, const std::string &filename)
strprintf("%%s%%s. This effect lasts %d ticks.", duration).c_str()
: "%s%s.", it->mFormat.c_str(), triggerLabel->second).c_str(), value));
}
- else if (xmlStrEqual(effectChild->name, BAD_CAST "modifier"))
+ else if (effectChild.name() == "modifier")
effect.push_back(strprintf("Provides an autoattack%s.",
triggerLabel->second));
- else if (xmlStrEqual(effectChild->name, BAD_CAST "consumes"))
+ else if (effectChild.name() == "consumes")
effect.push_back(strprintf("This will be consumed%s.",
triggerLabel->second));
- else if (xmlStrEqual(effectChild->name, BAD_CAST "label"))
- effect.emplace_back(
- (const char*)effectChild->children->content);
+ else if (effectChild.name() == "label")
+ effect.emplace_back(effectChild.textContent());
}
}
@@ -475,7 +466,7 @@ void ManaServItemDB::readItemNode(xmlNodePtr node, const std::string &filename)
itemInfo->type = ITEM_USABLE;
else if (itemInfo->equippable)
itemInfo->type = ITEM_EQUIPMENT_TORSO;
- } // end for (auto itemChild : XML::Children(node))
+ } // end for (auto itemChild : node.children())
itemInfo->effect = effect;
diff --git a/src/resources/itemdb.h b/src/resources/itemdb.h
index 37fec717..ef0985a3 100644
--- a/src/resources/itemdb.h
+++ b/src/resources/itemdb.h
@@ -94,7 +94,7 @@ class ItemDB
virtual void init() = 0;
- virtual void readItemNode(xmlNodePtr node, const std::string &filename) = 0;
+ virtual void readItemNode(XML::Node node, const std::string &filename) = 0;
virtual void checkStatus() = 0;
@@ -103,7 +103,7 @@ class ItemDB
* Permits to load item definitions which are common
* for each protocols to avoid code duplication.
*/
- void loadCommonRef(ItemInfo &itemInfo, xmlNodePtr node, const std::string &filename);
+ void loadCommonRef(ItemInfo &itemInfo, XML::Node node, const std::string &filename);
/**
* Checks the items parameters consistency.
@@ -129,17 +129,17 @@ class ItemDB
/**
* Loads the sprite references contained in a <sprite> tag.
*/
- void loadSpriteRef(ItemInfo &itemInfo, xmlNodePtr node);
+ void loadSpriteRef(ItemInfo &itemInfo, XML::Node node);
/**
* Loads the sound references contained in a <sound> tag.
*/
- void loadSoundRef(ItemInfo &itemInfo, xmlNodePtr node);
+ void loadSoundRef(ItemInfo &itemInfo, XML::Node node);
/**
* Loads the floor item references contained in a <floor> tag.
*/
- void loadFloorSprite(SpriteDisplay &display, xmlNodePtr node);
+ void loadFloorSprite(SpriteDisplay &display, XML::Node node);
// Items database
std::map<int, ItemInfo *> mItemInfos;
@@ -161,7 +161,7 @@ class TaItemDB : public ItemDB
void init() override;
- void readItemNode(xmlNodePtr node, const std::string &filename) override;
+ void readItemNode(XML::Node node, const std::string &filename) override;
void checkStatus() override;
@@ -193,7 +193,7 @@ class ManaServItemDB : public ItemDB
void init() override;
- void readItemNode(xmlNodePtr node, const std::string &filename) override;
+ void readItemNode(XML::Node node, const std::string &filename) override;
void checkStatus() override;
diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp
index 1b507eab..3279ba77 100644
--- a/src/resources/mapreader.cpp
+++ b/src/resources/mapreader.cpp
@@ -32,20 +32,19 @@
#include "utils/base64.h"
#include "utils/stringutils.h"
-#include "utils/xml.h"
#include "utils/zlib.h"
#include <iostream>
-static void readProperties(xmlNodePtr node, Properties* props);
+static void readProperties(XML::Node node, Properties* props);
-static void readLayer(xmlNodePtr node, Map *map);
+static void readLayer(XML::Node node, Map *map);
-static Tileset *readTileset(xmlNodePtr node,
+static Tileset *readTileset(XML::Node node,
const std::string &path,
Map *map);
-static void readTileAnimation(xmlNodePtr tileNode,
+static void readTileAnimation(XML::Node tileNode,
Tileset *set,
unsigned tileGID,
Map *map);
@@ -83,12 +82,12 @@ Map *MapReader::readMap(const std::string &filename)
XML::Document doc(filename);
- xmlNodePtr node = doc.rootNode();
+ XML::Node node = doc.rootNode();
// Parse the inflated map data
if (node)
{
- if (!xmlStrEqual(node->name, BAD_CAST "map"))
+ if (node.name() != "map")
{
logger->log("Error: Not a map file (%s)!", filename.c_str());
}
@@ -108,15 +107,15 @@ Map *MapReader::readMap(const std::string &filename)
return map;
}
-Map *MapReader::readMap(xmlNodePtr node, const std::string &path)
+Map *MapReader::readMap(XML::Node node, const std::string &path)
{
// Take the filename off the path
const std::string pathDir = path.substr(0, path.rfind("/") + 1);
- const int w = XML::getProperty(node, "width", 0);
- const int h = XML::getProperty(node, "height", 0);
- const int tilew = XML::getProperty(node, "tilewidth", -1);
- const int tileh = XML::getProperty(node, "tileheight", -1);
+ const int w = node.getProperty("width", 0);
+ const int h = node.getProperty("height", 0);
+ const int tilew = node.getProperty("tilewidth", -1);
+ const int tileh = node.getProperty("tileheight", -1);
if (tilew < 0 || tileh < 0)
{
@@ -128,9 +127,9 @@ Map *MapReader::readMap(xmlNodePtr node, const std::string &path)
Map *map = new Map(w, h, tilew, tileh);
- for (auto childNode : XML::Children(node))
+ for (auto childNode : node.children())
{
- if (xmlStrEqual(childNode->name, BAD_CAST "tileset"))
+ if (childNode.name() == "tileset")
{
Tileset *tileset = readTileset(childNode, pathDir, map);
if (tileset)
@@ -138,27 +137,27 @@ Map *MapReader::readMap(xmlNodePtr node, const std::string &path)
map->addTileset(tileset);
}
}
- else if (xmlStrEqual(childNode->name, BAD_CAST "layer"))
+ else if (childNode.name() == "layer")
{
readLayer(childNode, map);
}
- else if (xmlStrEqual(childNode->name, BAD_CAST "properties"))
+ else if (childNode.name() == "properties")
{
readProperties(childNode, map);
}
- else if (xmlStrEqual(childNode->name, BAD_CAST "objectgroup"))
+ else if (childNode.name() == "objectgroup")
{
// The object group offset is applied to each object individually
- const int tileOffsetX = XML::getProperty(childNode, "x", 0);
- const int tileOffsetY = XML::getProperty(childNode, "y", 0);
+ const int tileOffsetX = childNode.getProperty("x", 0);
+ const int tileOffsetY = childNode.getProperty("y", 0);
const int offsetX = tileOffsetX * tilew;
const int offsetY = tileOffsetY * tileh;
- for (auto objectNode : XML::Children(childNode))
+ for (auto objectNode : childNode.children())
{
- if (xmlStrEqual(objectNode->name, BAD_CAST "object"))
+ if (objectNode.name() == "object")
{
- std::string objType = XML::getProperty(objectNode, "type", "");
+ std::string objType = objectNode.getProperty("type", "");
objType = toUpper(objType);
if (objType == "NPC" ||
@@ -169,11 +168,11 @@ Map *MapReader::readMap(xmlNodePtr node, const std::string &path)
continue;
}
- const std::string objName = XML::getProperty(objectNode, "name", "");
- const int objX = XML::getProperty(objectNode, "x", 0);
- const int objY = XML::getProperty(objectNode, "y", 0);
- const int objW = XML::getProperty(objectNode, "width", 0);
- const int objH = XML::getProperty(objectNode, "height", 0);
+ const std::string objName = objectNode.getProperty("name", "");
+ const int objX = objectNode.getProperty("x", 0);
+ const int objY = objectNode.getProperty("y", 0);
+ const int objW = objectNode.getProperty("width", 0);
+ const int objH = objectNode.getProperty("height", 0);
logger->log("- Loading object name: %s type: %s at %d:%d",
objName.c_str(), objType.c_str(),
@@ -223,16 +222,16 @@ Map *MapReader::readMap(xmlNodePtr node, const std::string &path)
* @param props The Properties instance to which the properties will
* be assigned.
*/
-static void readProperties(xmlNodePtr node, Properties *props)
+static void readProperties(XML::Node node, Properties *props)
{
- for (auto childNode : XML::Children(node))
+ for (auto childNode : node.children())
{
- if (!xmlStrEqual(childNode->name, BAD_CAST "property"))
+ if (childNode.name() != "property")
continue;
// Example: <property name="name" value="value"/>
- const std::string name = XML::getProperty(childNode, "name", "");
- const std::string value = XML::getProperty(childNode, "value", "");
+ const std::string name = childNode.getProperty("name", "");
+ const std::string value = childNode.getProperty("value", "");
if (!name.empty() && !value.empty())
props->setProperty(name, value);
@@ -273,14 +272,14 @@ static void setTile(Map *map, MapLayer *layer, int x, int y, unsigned gid)
/**
* Reads a map layer and adds it to the given map.
*/
-static void readLayer(xmlNodePtr node, Map *map)
+static void readLayer(XML::Node node, Map *map)
{
// Layers are not necessarily the same size as the map
- const int w = XML::getProperty(node, "width", map->getWidth());
- const int h = XML::getProperty(node, "height", map->getHeight());
- const int offsetX = XML::getProperty(node, "x", 0);
- const int offsetY = XML::getProperty(node, "y", 0);
- std::string name = XML::getProperty(node, "name", "");
+ const int w = node.getProperty("width", map->getWidth());
+ const int h = node.getProperty("height", map->getHeight());
+ const int offsetX = node.getProperty("x", 0);
+ const int offsetY = node.getProperty("y", 0);
+ std::string name = node.getProperty("name", "");
name = toLower(name);
const bool isFringeLayer = (name.substr(0,6) == "fringe");
@@ -299,17 +298,17 @@ static void readLayer(xmlNodePtr node, Map *map)
int y = 0;
// Load the tile data
- for (auto childNode : XML::Children(node))
+ for (auto childNode : node.children())
{
- if (xmlStrEqual(childNode->name, BAD_CAST "properties"))
+ if (childNode.name() == "properties")
{
- for (auto prop : XML::Children(childNode))
+ for (auto prop : childNode.children())
{
- if (!xmlStrEqual(prop->name, BAD_CAST "property"))
+ if (prop.name() != "property")
continue;
- const std::string pname = XML::getProperty(prop, "name", "");
- const std::string value = XML::getProperty(prop, "value", "");
+ const std::string pname = prop.getProperty("name", "");
+ const std::string value = prop.getProperty("value", "");
// TODO: Consider supporting "Hidden", "Version" and "NotVersion"
@@ -321,13 +320,13 @@ static void readLayer(xmlNodePtr node, Map *map)
continue;
}
- if (!xmlStrEqual(childNode->name, BAD_CAST "data"))
+ if (childNode.name() != "data")
continue;
const std::string encoding =
- XML::getProperty(childNode, "encoding", "");
+ childNode.getProperty("encoding", "");
const std::string compression =
- XML::getProperty(childNode, "compression", "");
+ childNode.getProperty("compression", "");
if (encoding == "base64")
{
@@ -340,12 +339,12 @@ static void readLayer(xmlNodePtr node, Map *map)
}
// Read base64 encoded map file
- xmlNodePtr dataChild = childNode->children;
- if (!dataChild || !dataChild->content)
+ const auto data = childNode.textContent();
+ if (data.empty())
continue;
- auto *charStart = reinterpret_cast<const char*>(dataChild->content);
- auto *charData = new unsigned char[strlen(charStart) + 1];
+ auto *charStart = data.data();
+ auto *charData = new unsigned char[data.length() + 1];
unsigned char *charIndex = charData;
while (*charStart)
@@ -364,7 +363,7 @@ static void readLayer(xmlNodePtr node, Map *map)
int binLen;
unsigned char *binData =
php3_base64_decode(charData,
- strlen(reinterpret_cast<const char*>(charData)),
+ charIndex - charData,
&binLen);
delete[] charData;
@@ -413,14 +412,14 @@ static void readLayer(xmlNodePtr node, Map *map)
}
else if (encoding == "csv")
{
- if (!childNode->children || !childNode->children->content)
+ const auto data = childNode.textContent();
+ if (data.empty())
{
logger->log("Error: CSV layer data is empty!");
continue;
}
- xmlChar *data = childNode->children->content;
- auto *pos = reinterpret_cast<const char*>(data);
+ auto *pos = data.data();
for (;;)
{
@@ -462,12 +461,12 @@ static void readLayer(xmlNodePtr node, Map *map)
else
{
// Read plain XML map file
- for (auto childNode2 : XML::Children(childNode))
+ for (auto childNode2 : childNode.children())
{
- if (!xmlStrEqual(childNode2->name, BAD_CAST "tile"))
+ if (childNode2.name() != "tile")
continue;
- unsigned gid = XML::getProperty(childNode2, "gid", 0);
+ unsigned gid = childNode2.getProperty("gid", 0);
setTile(map, layer, x, y, gid);
x++;
@@ -493,19 +492,19 @@ static void readLayer(xmlNodePtr node, Map *map)
/**
* Reads a tile set.
*/
-static Tileset *readTileset(xmlNodePtr node, const std::string &path,
+static Tileset *readTileset(XML::Node node, const std::string &path,
Map *map)
{
- unsigned firstGid = XML::getProperty(node, "firstgid", 0);
- int margin = XML::getProperty(node, "margin", 0);
- int spacing = XML::getProperty(node, "spacing", 0);
+ const unsigned firstGid = node.getProperty("firstgid", 0);
+ const int margin = node.getProperty("margin", 0);
+ const int spacing = node.getProperty("spacing", 0);
XML::Document *doc = nullptr;
Tileset *set = nullptr;
std::string pathDir(path);
- if (xmlHasProp(node, BAD_CAST "source"))
+ if (node.hasProperty("source"))
{
- std::string filename = XML::getProperty(node, "source", "");
+ std::string filename = node.getProperty("source", std::string());
filename = resolveRelativePath(path, filename);
doc = new XML::Document(filename);
@@ -515,15 +514,14 @@ static Tileset *readTileset(xmlNodePtr node, const std::string &path,
pathDir = filename.substr(0, filename.rfind("/") + 1);
}
- const int tw = XML::getProperty(node, "tilewidth", map->getTileWidth());
- const int th = XML::getProperty(node, "tileheight", map->getTileHeight());
+ const int tw = node.getProperty("tilewidth", map->getTileWidth());
+ const int th = node.getProperty("tileheight", map->getTileHeight());
- for (auto childNode : XML::Children(node))
+ for (auto childNode : node.children())
{
- if (xmlStrEqual(childNode->name, BAD_CAST "image"))
+ if (childNode.name() == "image")
{
- const std::string source = XML::getProperty(childNode, "source", "");
-
+ const auto source = childNode.getProperty("source", std::string());
if (!source.empty())
{
std::string sourceStr = resolveRelativePath(pathDir, source);
@@ -543,13 +541,13 @@ static Tileset *readTileset(xmlNodePtr node, const std::string &path,
}
}
}
- else if (set && xmlStrEqual(childNode->name, BAD_CAST "tile"))
+ else if (set && childNode.name() == "tile")
{
- const int tileGID = firstGid + XML::getProperty(childNode, "id", 0);
+ const int tileGID = firstGid + childNode.getProperty("id", 0);
- for (auto tileNode : XML::Children(childNode))
+ for (auto tileNode : childNode.children())
{
- if (xmlStrEqual(tileNode->name, BAD_CAST "animation"))
+ if (tileNode.name() == "animation")
readTileAnimation(tileNode, set, tileGID, map);
}
}
@@ -560,18 +558,18 @@ static Tileset *readTileset(xmlNodePtr node, const std::string &path,
return set;
}
-static void readTileAnimation(xmlNodePtr tileNode,
+static void readTileAnimation(XML::Node tileNode,
Tileset *set,
unsigned tileGID,
Map *map)
{
Animation ani;
- for (auto frameNode : XML::Children(tileNode))
+ for (auto frameNode : tileNode.children())
{
- if (xmlStrEqual(frameNode->name, BAD_CAST "frame"))
+ if (frameNode.name() == "frame")
{
- const int tileId = XML::getProperty(frameNode, "tileid", 0);
- const int duration = XML::getProperty(frameNode, "duration", 0);
+ const int tileId = frameNode.getProperty("tileid", 0);
+ const int duration = frameNode.getProperty("duration", 0);
ani.addFrame(set->get(tileId), duration, 0, 0);
}
}
diff --git a/src/resources/mapreader.h b/src/resources/mapreader.h
index 9244da73..105c5d1d 100644
--- a/src/resources/mapreader.h
+++ b/src/resources/mapreader.h
@@ -22,7 +22,7 @@
#ifndef MAPREADER_H
#define MAPREADER_H
-#include <libxml/tree.h>
+#include "utils/xml.h"
#include <string>
@@ -43,7 +43,7 @@ public:
* Read an XML map from a parsed XML tree. The path is used to find the
* location of referenced tileset images.
*/
- static Map *readMap(xmlNodePtr node, const std::string &path);
+ static Map *readMap(XML::Node node, const std::string &path);
};
#endif // MAPREADER_H
diff --git a/src/resources/monsterdb.cpp b/src/resources/monsterdb.cpp
index 38806f13..215ca2f8 100644
--- a/src/resources/monsterdb.cpp
+++ b/src/resources/monsterdb.cpp
@@ -65,36 +65,33 @@ void MonsterDB::setMonsterIdOffset(int offset)
/**
* Read <monster> node from settings.
*/
-void MonsterDB::readMonsterNode(xmlNodePtr node, const std::string &filename)
+void MonsterDB::readMonsterNode(XML::Node node, const std::string &filename)
{
auto *currentInfo = new BeingInfo;
currentInfo->blockType = Map::BLOCKTYPE_MONSTER;
- currentInfo->name = XML::getProperty(node, "name", _("unnamed"));
+ currentInfo->name = node.getProperty("name", _("unnamed"));
- currentInfo->setTargetCursorSize(XML::getProperty(node,
- "targetCursor", "medium"));
+ currentInfo->setTargetCursorSize(node.getProperty("targetCursor", "medium"));
+ currentInfo->setHoverCursor(node.getProperty("hoverCursor", "attack"));
- currentInfo->setHoverCursor(XML::getProperty(node, "hoverCursor", "attack"));
-
- currentInfo->targetSelection = XML::getProperty(
- node, "targetSelection", true);
+ currentInfo->targetSelection = node.getProperty("targetSelection", true);
SpriteDisplay &display = currentInfo->display;
- for (auto spriteNode : XML::Children(node))
+ for (auto spriteNode : node.children())
{
- if (xmlStrEqual(spriteNode->name, BAD_CAST "sprite"))
+ if (spriteNode.name() == "sprite")
{
SpriteReference &currentSprite = display.sprites.emplace_back();
- currentSprite.sprite = (const char*)spriteNode->children->content;
- currentSprite.variant = XML::getProperty(spriteNode, "variant", 0);
+ currentSprite.sprite = spriteNode.textContent();
+ currentSprite.variant = spriteNode.getProperty("variant", 0);
}
- else if (xmlStrEqual(spriteNode->name, BAD_CAST "sound"))
+ else if (spriteNode.name() == "sound")
{
- std::string event = XML::getProperty(spriteNode, "event", std::string());
- const char *soundFile = (const char*) spriteNode->children->content;
+ std::string event = spriteNode.getProperty("event", std::string());
+ const std::string soundFile { spriteNode.textContent() };
if (event == "hit")
{
@@ -116,38 +113,37 @@ void MonsterDB::readMonsterNode(xmlNodePtr node, const std::string &filename)
{
logger->log("MonsterDB: Warning, sound effect %s for "
"unknown event %s of monster %s in %s",
- soundFile, event.c_str(),
+ soundFile.c_str(), event.c_str(),
currentInfo->name.c_str(),
filename.c_str());
}
}
- else if (xmlStrEqual(spriteNode->name, BAD_CAST "attack"))
+ else if (spriteNode.name() == "attack")
{
Attack attack;
- const int id = XML::getProperty(spriteNode, "id", 0);
+ const int id = spriteNode.getProperty("id", 0);
- attack.effectId = XML::getProperty(spriteNode, "effect-id", -1);
+ attack.effectId = spriteNode.getProperty("effect-id", -1);
attack.hitEffectId =
- XML::getProperty(spriteNode, "hit-effect-id",
+ spriteNode.getProperty("hit-effect-id",
paths.getIntValue("hitEffectId"));
attack.criticalHitEffectId =
- XML::getProperty(spriteNode, "critical-hit-effect-id",
+ spriteNode.getProperty("critical-hit-effect-id",
paths.getIntValue("criticalHitEffectId"));
attack.missileParticleFilename =
- XML::getProperty(spriteNode, "missile-particle", "");
+ spriteNode.getProperty("missile-particle", "");
- attack.action = XML::getProperty(spriteNode, "action", "attack");
+ attack.action = spriteNode.getProperty("action", "attack");
currentInfo->addAttack(id, std::move(attack));
}
- else if (xmlStrEqual(spriteNode->name, BAD_CAST "particlefx"))
+ else if (spriteNode.name() == "particlefx")
{
- display.particles.emplace_back(
- (const char*) spriteNode->children->content);
+ display.particles.emplace_back(spriteNode.textContent());
}
}
- mMonsterInfos[XML::getProperty(node, "id", 0) + mMonsterIdOffset] = currentInfo;
+ mMonsterInfos[node.getProperty("id", 0) + mMonsterIdOffset] = currentInfo;
}
/**
diff --git a/src/resources/monsterdb.h b/src/resources/monsterdb.h
index dc8b50cb..ff709486 100644
--- a/src/resources/monsterdb.h
+++ b/src/resources/monsterdb.h
@@ -35,7 +35,7 @@ namespace MonsterDB
void setMonsterIdOffset(int offset);
- void readMonsterNode(xmlNodePtr node, const std::string &filename);
+ void readMonsterNode(XML::Node node, const std::string &filename);
void checkStatus();
diff --git a/src/resources/npcdb.cpp b/src/resources/npcdb.cpp
index a8d0f60f..6b1c3150 100644
--- a/src/resources/npcdb.cpp
+++ b/src/resources/npcdb.cpp
@@ -41,9 +41,9 @@ void NPCDB::init()
unload();
}
-void NPCDB::readNPCNode(xmlNodePtr node, const std::string &filename)
+void NPCDB::readNPCNode(XML::Node node, const std::string &filename)
{
- int id = XML::getProperty(node, "id", 0);
+ int id = node.getProperty("id", 0);
if (id == 0)
{
logger->log("NPC Database: NPC with missing ID in %s", filename.c_str());
@@ -52,27 +52,23 @@ void NPCDB::readNPCNode(xmlNodePtr node, const std::string &filename)
auto *currentInfo = new BeingInfo;
- currentInfo->setTargetCursorSize(XML::getProperty(node,
- "targetCursor", "medium"));
+ currentInfo->setTargetCursorSize(node.getProperty("targetCursor", "medium"));
+ currentInfo->setHoverCursor(node.getProperty("hoverCursor", "talk"));
- currentInfo->setHoverCursor(XML::getProperty(node, "hoverCursor", "talk"));
-
- currentInfo->targetSelection = XML::getProperty(
- node, "targetSelection", true);
+ currentInfo->targetSelection = node.getProperty("targetSelection", true);
SpriteDisplay &display = currentInfo->display;
- for (auto spriteNode : XML::Children(node))
+ for (auto spriteNode : node.children())
{
- if (xmlStrEqual(spriteNode->name, BAD_CAST "sprite"))
+ if (spriteNode.name() == "sprite")
{
SpriteReference &currentSprite = display.sprites.emplace_back();
- currentSprite.sprite = (const char*)spriteNode->children->content;
- currentSprite.variant = XML::getProperty(spriteNode, "variant", 0);
+ currentSprite.sprite = spriteNode.textContent();
+ currentSprite.variant = spriteNode.getProperty("variant", 0);
}
- else if (xmlStrEqual(spriteNode->name, BAD_CAST "particlefx"))
+ else if (spriteNode.name() == "particlefx")
{
- display.particles.emplace_back(
- (const char*)spriteNode->children->content);
+ display.particles.emplace_back(spriteNode.textContent());
}
}
diff --git a/src/resources/npcdb.h b/src/resources/npcdb.h
index a3718a7b..306167de 100644
--- a/src/resources/npcdb.h
+++ b/src/resources/npcdb.h
@@ -34,7 +34,7 @@ namespace NPCDB
{
void init();
- void readNPCNode(xmlNodePtr node, const std::string &filename);
+ void readNPCNode(XML::Node node, const std::string &filename);
void checkStatus();
diff --git a/src/resources/settingsmanager.cpp b/src/resources/settingsmanager.cpp
index 56393546..a289c6c1 100644
--- a/src/resources/settingsmanager.cpp
+++ b/src/resources/settingsmanager.cpp
@@ -109,36 +109,33 @@ namespace SettingsManager
logger->log("Loading game settings from %s", filename.c_str());
XML::Document doc(filename);
- xmlNodePtr node = doc.rootNode();
+ XML::Node node = doc.rootNode();
// add file to include set
mIncludedFiles.insert(filename);
// FIXME: check root node's name when bjorn decides it's time
- if (!node /*|| !xmlStrEqual(node->name, BAD_CAST "settings") */)
+ if (!node /*|| node.name() != "settings" */)
{
logger->log("Settings Manager: %s is not a valid settings file!", filename.c_str());
return false;
}
- if (xmlStrEqual(node->name, BAD_CAST "monsters"))
+ if (node.name() == "monsters")
{
- if (XML::hasProperty(node, "offset"))
+ if (node.hasProperty("offset"))
{
- MonsterDB::setMonsterIdOffset(XML::getProperty(node, "offset", 0));
+ MonsterDB::setMonsterIdOffset(node.getProperty("offset", 0));
}
}
// go through every node
- for (auto childNode : XML::Children(node))
+ for (auto childNode : node.children())
{
- if (childNode->type != XML_ELEMENT_NODE)
- continue;
-
- if (xmlStrEqual(childNode->name, BAD_CAST "include"))
+ if (childNode.name() == "include")
{
// include an other file
- std::string includeFile = XML::getProperty(childNode, "file", std::string());
+ std::string includeFile = childNode.getProperty("file", std::string());
if (!includeFile.empty())
{
@@ -149,7 +146,7 @@ namespace SettingsManager
else
{
// try to get name property, which has an absolute value
- includeFile = XML::getProperty(childNode, "name", std::string());
+ includeFile = childNode.getProperty("name", std::string());
}
// check if file property was given
@@ -170,76 +167,76 @@ namespace SettingsManager
logger->log("Warning: <include> element without 'file' or 'name' attribute in %s", filename.c_str());
}
}
- else if (xmlStrEqual(childNode->name, BAD_CAST "option"))
+ else if (childNode.name() == "option")
{
// options from paths.xml
- std::string name = XML::getProperty(childNode, "name", std::string());
- std::string value = XML::getProperty(childNode, "value", std::string());
+ std::string name = childNode.getProperty("name", std::string());
+ std::string value = childNode.getProperty("value", std::string());
if (!name.empty())
paths.setValue(name, value);
else
logger->log("Warning: option without a name found in %s", filename.c_str());
}
- else if (xmlStrEqual(childNode->name, BAD_CAST "attribute"))
+ else if (childNode.name() == "attribute")
{
// map config
Attributes::readAttributeNode(childNode, filename);
}
- else if (xmlStrEqual(childNode->name, BAD_CAST "points"))
+ else if (childNode.name() == "points")
{
Attributes::readPointsNode(childNode, filename);
}
- else if (xmlStrEqual(childNode->name, BAD_CAST "color"))
+ else if (childNode.name() == "color")
{
hairDB.readHairColorNode(childNode, filename);
}
- else if (xmlStrEqual(childNode->name, BAD_CAST "list"))
+ else if (childNode.name() == "list")
{
// todo: consider if we need a "color DB", but in tmwa clientdata
// I only see hair colors in the itemcolors.xml file.
- const std::string name = XML::getProperty(childNode, "name", std::string());
+ const std::string name = childNode.getProperty("name", std::string());
if (name == "hair")
{
- for (auto hairColorNode : XML::Children(childNode))
+ for (auto hairColorNode : childNode.children())
{
- if (xmlStrEqual(hairColorNode->name, BAD_CAST "color"))
+ if (hairColorNode.name() == "color")
hairDB.readHairColorNode(hairColorNode, filename);
}
}
}
- else if (xmlStrEqual(childNode->name, BAD_CAST "item"))
+ else if (childNode.name() == "item")
{
itemDb->readItemNode(childNode, filename);
}
- else if (xmlStrEqual(childNode->name, BAD_CAST "monster"))
+ else if (childNode.name() == "monster")
{
MonsterDB::readMonsterNode(childNode, filename);
}
- else if (xmlStrEqual(childNode->name, BAD_CAST "special-set"))
+ else if (childNode.name() == "special-set")
{
SpecialDB::readSpecialSetNode(childNode, filename);
}
- else if (xmlStrEqual(childNode->name, BAD_CAST "npc"))
+ else if (childNode.name() == "npc")
{
NPCDB::readNPCNode(childNode, filename);
}
- else if (xmlStrEqual(childNode->name, BAD_CAST "emote"))
+ else if (childNode.name() == "emote")
{
EmoteDB::readEmoteNode(childNode, filename);
}
- else if (xmlStrEqual(childNode->name, BAD_CAST "status-effect") || xmlStrEqual(childNode->name, BAD_CAST "stun-effect"))
+ else if (childNode.name() == "status-effect" || childNode.name() == "stun-effect")
{
StatusEffect::readStatusEffectNode(childNode, filename);
}
- else if (xmlStrEqual(childNode->name, BAD_CAST "unit"))
+ else if (childNode.name() == "unit")
{
Units::readUnitNode(childNode, filename);
}
else
{
// compatibility stuff with older configs/games
- if (xmlStrEqual(node->name, BAD_CAST "specials") && xmlStrEqual(childNode->name, BAD_CAST "set"))
+ if (node.name() == "specials" && childNode.name() == "set")
{
// specials.xml:/specials/set
SpecialDB::readSpecialSetNode(childNode, filename);
diff --git a/src/resources/specialdb.cpp b/src/resources/specialdb.cpp
index a6f6bac0..ec0b3f2f 100644
--- a/src/resources/specialdb.cpp
+++ b/src/resources/specialdb.cpp
@@ -50,24 +50,24 @@ void SpecialDB::init()
unload();
}
-void SpecialDB::readSpecialSetNode(xmlNodePtr node, const std::string &filename)
+void SpecialDB::readSpecialSetNode(XML::Node node, const std::string &filename)
{
- std::string setName = XML::getProperty(node, "name", "Actions");
+ std::string setName = node.getProperty("name", "Actions");
- for (auto special : XML::Children(node))
+ for (auto special : node.children())
{
- if (xmlStrEqual(special->name, BAD_CAST "special"))
+ if (special.name() == "special")
{
auto *info = new SpecialInfo();
- int id = XML::getProperty(special, "id", 0);
+ int id = special.getProperty("id", 0);
info->id = id;
info->set = setName;
- info->name = XML::getProperty(special, "name", "");
- info->icon = XML::getProperty(special, "icon", "");
+ info->name = special.getProperty("name", "");
+ info->icon = special.getProperty("icon", "");
- info->targetMode = targetModeFromString(XML::getProperty(special, "target", "being"));
+ info->targetMode = targetModeFromString(special.getProperty("target", "being"));
- info->rechargeable = XML::getBoolProperty(special, "rechargeable", true);
+ info->rechargeable = special.getBoolProperty("rechargeable", true);
info->rechargeNeeded = 0;
info->rechargeCurrent = 0;
diff --git a/src/resources/specialdb.h b/src/resources/specialdb.h
index 50aebf1f..20ba0075 100644
--- a/src/resources/specialdb.h
+++ b/src/resources/specialdb.h
@@ -50,7 +50,7 @@ namespace SpecialDB
{
void init();
- void readSpecialSetNode(xmlNodePtr node, const std::string &filename);
+ void readSpecialSetNode(XML::Node node, const std::string &filename);
void checkStatus();
diff --git a/src/resources/spritedef.cpp b/src/resources/spritedef.cpp
index 54f28fe9..f42e623e 100644
--- a/src/resources/spritedef.cpp
+++ b/src/resources/spritedef.cpp
@@ -63,9 +63,9 @@ SpriteDef *SpriteDef::load(const std::string &animationFile, int variant)
processedFiles.insert(animationFile);
XML::Document doc(animationFile.substr(0, pos));
- xmlNodePtr rootNode = doc.rootNode();
+ XML::Node rootNode = doc.rootNode();
- if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "sprite"))
+ if (!rootNode || rootNode.name() != "sprite")
{
logger->log("Error, failed to parse %s", animationFile.c_str());
@@ -110,48 +110,48 @@ void SpriteDef::substituteActions()
substituteAction(SpriteAction::DEAD, SpriteAction::HURT);
}
-void SpriteDef::loadSprite(xmlNodePtr spriteNode, int variant,
+void SpriteDef::loadSprite(XML::Node spriteNode, int variant,
const std::string &palettes)
{
// Get the variant
- const int variantCount = XML::getProperty(spriteNode, "variants", 0);
+ const int variantCount = spriteNode.getProperty("variants", 0);
int variant_offset = 0;
if (variantCount > 0 && variant < variantCount)
{
variant_offset =
- variant * XML::getProperty(spriteNode, "variant_offset", 0);
+ variant * spriteNode.getProperty("variant_offset", 0);
}
- for (auto node : XML::Children(spriteNode))
+ for (auto node : spriteNode.children())
{
- if (xmlStrEqual(node->name, BAD_CAST "imageset"))
+ if (node.name() == "imageset")
{
loadImageSet(node, palettes);
}
- else if (xmlStrEqual(node->name, BAD_CAST "action"))
+ else if (node.name() == "action")
{
loadAction(node, variant_offset);
}
- else if (xmlStrEqual(node->name, BAD_CAST "include"))
+ else if (node.name() == "include")
{
includeSprite(node);
}
}
}
-void SpriteDef::loadImageSet(xmlNodePtr node, const std::string &palettes)
+void SpriteDef::loadImageSet(XML::Node node, const std::string &palettes)
{
- const std::string name = XML::getProperty(node, "name", "");
+ const std::string name = node.getProperty("name", "");
// We don't allow redefining image sets. This way, an included sprite
// definition will use the already loaded image set with the same name.
if (mImageSets.find(name) != mImageSets.end())
return;
- const int width = XML::getProperty(node, "width", 0);
- const int height = XML::getProperty(node, "height", 0);
- std::string imageSrc = XML::getProperty(node, "src", "");
+ const int width = node.getProperty("width", 0);
+ const int height = node.getProperty("height", 0);
+ std::string imageSrc = node.getProperty("src", "");
Dye::instantiate(imageSrc, palettes);
ResourceManager *resman = ResourceManager::getInstance();
@@ -163,15 +163,15 @@ void SpriteDef::loadImageSet(xmlNodePtr node, const std::string &palettes)
imageSrc.c_str()));
}
- imageSet->setOffsetX(XML::getProperty(node, "offsetX", 0));
- imageSet->setOffsetY(XML::getProperty(node, "offsetY", 0));
+ imageSet->setOffsetX(node.getProperty("offsetX", 0));
+ imageSet->setOffsetY(node.getProperty("offsetY", 0));
mImageSets[name] = imageSet;
}
-void SpriteDef::loadAction(xmlNodePtr node, int variant_offset)
+void SpriteDef::loadAction(XML::Node node, int variant_offset)
{
- const std::string actionName = XML::getProperty(node, "name", "");
- const std::string imageSetName = XML::getProperty(node, "imageset", "");
+ const std::string actionName = node.getProperty("name", "");
+ const std::string imageSetName = node.getProperty("imageset", "");
auto si = mImageSets.find(imageSetName);
if (si == mImageSets.end())
@@ -198,21 +198,21 @@ void SpriteDef::loadAction(xmlNodePtr node, int variant_offset)
}
// Load animations
- for (auto animationNode : XML::Children(node))
+ for (auto animationNode : node.children())
{
- if (xmlStrEqual(animationNode->name, BAD_CAST "animation"))
+ if (animationNode.name() == "animation")
{
loadAnimation(animationNode, action, imageSet, variant_offset);
}
}
}
-void SpriteDef::loadAnimation(xmlNodePtr animationNode,
+void SpriteDef::loadAnimation(XML::Node animationNode,
Action *action, ImageSet *imageSet,
int variant_offset)
{
const std::string directionName =
- XML::getProperty(animationNode, "direction", "");
+ animationNode.getProperty("direction", "");
const SpriteDirection directionType = makeSpriteDirection(directionName);
if (directionType == DIRECTION_INVALID)
@@ -226,18 +226,18 @@ void SpriteDef::loadAnimation(xmlNodePtr animationNode,
action->setAnimation(directionType, animation);
// Get animation frames
- for (auto frameNode : XML::Children(animationNode))
+ for (auto frameNode : animationNode.children())
{
- const int delay = XML::getProperty(frameNode, "delay",
+ const int delay = frameNode.getProperty("delay",
DEFAULT_FRAME_DELAY);
- int offsetX = XML::getProperty(frameNode, "offsetX", 0) +
+ int offsetX = frameNode.getProperty("offsetX", 0) +
imageSet->getOffsetX();
- int offsetY = XML::getProperty(frameNode, "offsetY", 0) +
+ int offsetY = frameNode.getProperty("offsetY", 0) +
imageSet->getOffsetY();
- if (xmlStrEqual(frameNode->name, BAD_CAST "frame"))
+ if (frameNode.name() == "frame")
{
- const int index = XML::getProperty(frameNode, "index", -1);
+ const int index = frameNode.getProperty("index", -1);
if (index < 0)
{
@@ -255,10 +255,10 @@ void SpriteDef::loadAnimation(xmlNodePtr animationNode,
animation->addFrame(img, delay, offsetX, offsetY);
}
- else if (xmlStrEqual(frameNode->name, BAD_CAST "sequence"))
+ else if (frameNode.name() == "sequence")
{
- int start = XML::getProperty(frameNode, "start", -1);
- const int end = XML::getProperty(frameNode, "end", -1);
+ int start = frameNode.getProperty("start", -1);
+ const int end = frameNode.getProperty("end", -1);
if (start < 0 || end < 0)
{
@@ -280,16 +280,16 @@ void SpriteDef::loadAnimation(xmlNodePtr animationNode,
start++;
}
}
- else if (xmlStrEqual(frameNode->name, BAD_CAST "end"))
+ else if (frameNode.name() == "end")
{
animation->addTerminator();
}
} // for frameNode
}
-void SpriteDef::includeSprite(xmlNodePtr includeNode)
+void SpriteDef::includeSprite(XML::Node includeNode)
{
- std::string filename = XML::getProperty(includeNode, "file", "");
+ std::string filename = includeNode.getProperty("file", "");
if (filename.empty())
return;
@@ -304,9 +304,9 @@ void SpriteDef::includeSprite(xmlNodePtr includeNode)
processedFiles.insert(filename);
XML::Document doc(filename);
- xmlNodePtr rootNode = doc.rootNode();
+ XML::Node rootNode = doc.rootNode();
- if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "sprite"))
+ if (!rootNode || rootNode.name() != "sprite")
{
logger->log("Error, no sprite root node in %s", filename.c_str());
return;
diff --git a/src/resources/spritedef.h b/src/resources/spritedef.h
index ec5e8927..fa44deea 100644
--- a/src/resources/spritedef.h
+++ b/src/resources/spritedef.h
@@ -24,7 +24,7 @@
#include "resources/resource.h"
-#include <libxml/tree.h>
+#include "utils/xml.h"
#include <map>
#include <string>
@@ -111,30 +111,30 @@ class SpriteDef : public Resource
/**
* Loads a sprite element.
*/
- void loadSprite(xmlNodePtr spriteNode, int variant,
+ void loadSprite(XML::Node spriteNode, int variant,
const std::string &palettes = std::string());
/**
* Loads an imageset element.
*/
- void loadImageSet(xmlNodePtr node, const std::string &palettes);
+ void loadImageSet(XML::Node node, const std::string &palettes);
/**
* Loads an action element.
*/
- void loadAction(xmlNodePtr node, int variant_offset);
+ void loadAction(XML::Node node, int variant_offset);
/**
* Loads an animation element.
*/
- void loadAnimation(xmlNodePtr animationNode,
+ void loadAnimation(XML::Node animationNode,
Action *action, ImageSet *imageSet,
int variant_offset);
/**
* Include another sprite into this one.
*/
- void includeSprite(xmlNodePtr includeNode);
+ void includeSprite(XML::Node includeNode);
/**
* Complete missing actions by copying existing ones.
diff --git a/src/resources/theme.cpp b/src/resources/theme.cpp
index 725fcc1c..29157240 100644
--- a/src/resources/theme.cpp
+++ b/src/resources/theme.cpp
@@ -219,12 +219,12 @@ Skin *Theme::readSkin(const std::string &filename)
logger->log("Loading skin '%s'.", filename.c_str());
XML::Document doc(resolveThemePath(filename));
- xmlNodePtr rootNode = doc.rootNode();
+ XML::Node rootNode = doc.rootNode();
- if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "skinset"))
+ if (!rootNode || rootNode.name() != "skinset")
return nullptr;
- const std::string skinSetImage = XML::getProperty(rootNode, "image", "");
+ const std::string skinSetImage = rootNode.getProperty("image", "");
if (skinSetImage.empty())
{
@@ -240,31 +240,31 @@ Skin *Theme::readSkin(const std::string &filename)
memset(&border, 0, sizeof(ImageRect));
// iterate <widget>'s
- for (auto widgetNode : XML::Children(rootNode))
+ for (auto widgetNode : rootNode.children())
{
- if (!xmlStrEqual(widgetNode->name, BAD_CAST "widget"))
+ if (widgetNode.name() != "widget")
continue;
const std::string widgetType =
- XML::getProperty(widgetNode, "type", "unknown");
+ widgetNode.getProperty("type", "unknown");
if (widgetType == "Window")
{
// Iterate through <part>'s
// LEEOR / TODO:
// We need to make provisions to load in a CloseButton image. For
// now it can just be hard-coded.
- for (auto partNode : XML::Children(widgetNode))
+ for (auto partNode : widgetNode.children())
{
- if (!xmlStrEqual(partNode->name, BAD_CAST "part"))
+ if (partNode.name() != "part")
continue;
const std::string partType =
- XML::getProperty(partNode, "type", "unknown");
+ partNode.getProperty("type", "unknown");
// TOP ROW
- const int xPos = XML::getProperty(partNode, "xpos", 0);
- const int yPos = XML::getProperty(partNode, "ypos", 0);
- const int width = XML::getProperty(partNode, "width", 1);
- const int height = XML::getProperty(partNode, "height", 1);
+ const int xPos = partNode.getProperty("xpos", 0);
+ const int yPos = partNode.getProperty("ypos", 0);
+ const int width = partNode.getProperty("width", 1);
+ const int height = partNode.getProperty("height", 1);
if (partType == "top-left-corner")
border.grid[0] = dBorders->getSubImage(xPos, yPos, width, height);
@@ -531,9 +531,9 @@ void Theme::loadColors(std::string file)
file += "/colors.xml";
XML::Document doc(file);
- xmlNodePtr root = doc.rootNode();
+ XML::Node root = doc.rootNode();
- if (!root || !xmlStrEqual(root->name, BAD_CAST "colors"))
+ if (!root || root.name() != "colors")
{
logger->log("Error loading colors file: %s", file.c_str());
return;
@@ -544,31 +544,30 @@ void Theme::loadColors(std::string file)
gcn::Color color;
GradientType grad;
- for (auto node : XML::Children(root))
+ for (auto node : root.children())
{
- if (xmlStrEqual(node->name, BAD_CAST "color"))
+ if (node.name() == "color")
{
- type = readColorType(XML::getProperty(node, "id", ""));
+ type = readColorType(node.getProperty("id", ""));
if (type < 0) // invalid or no type given
continue;
- temp = XML::getProperty(node, "color", "");
+ temp = node.getProperty("color", "");
if (temp.empty()) // no color set, so move on
continue;
color = readColor(temp);
- grad = readColorGradient(XML::getProperty(node, "effect", ""));
+ grad = readColorGradient(node.getProperty("effect", ""));
mColors[type].set(type, color, grad, 10);
}
- else if (xmlStrEqual(node->name, BAD_CAST "progressbar"))
+ else if (node.name() == "progressbar")
{
- type = readProgressType(XML::getProperty(node, "id", ""));
+ type = readProgressType(node.getProperty("id", ""));
if (type < 0) // invalid or no type given
continue;
- mProgressColors[type] = new DyePalette(XML::getProperty(node,
- "color", ""));
+ mProgressColors[type] = new DyePalette(node.getProperty( "color", ""));
}
}
}
diff --git a/src/rotationalparticle.cpp b/src/rotationalparticle.cpp
index 47aa8f78..bcdb9bad 100644
--- a/src/rotationalparticle.cpp
+++ b/src/rotationalparticle.cpp
@@ -29,7 +29,7 @@ RotationalParticle::RotationalParticle(Map *map, Animation animation):
mAnimation(std::move(animation))
{}
-RotationalParticle::RotationalParticle(Map *map, xmlNodePtr animationNode,
+RotationalParticle::RotationalParticle(Map *map, XML::Node animationNode,
const std::string &dyePalettes):
ImageParticle(map, nullptr),
mAnimation(animationNode, dyePalettes)
diff --git a/src/rotationalparticle.h b/src/rotationalparticle.h
index cf068835..4ddfa7a9 100644
--- a/src/rotationalparticle.h
+++ b/src/rotationalparticle.h
@@ -25,7 +25,7 @@
#include "imageparticle.h"
#include "simpleanimation.h"
-#include <libxml/tree.h>
+#include "utils/xml.h"
class Animation;
class Map;
@@ -36,7 +36,7 @@ class RotationalParticle : public ImageParticle
public:
RotationalParticle(Map *map, Animation animation);
- RotationalParticle(Map *map, xmlNodePtr animationNode,
+ RotationalParticle(Map *map, XML::Node animationNode,
const std::string &dyePalettes = std::string());
~RotationalParticle() override;
diff --git a/src/simpleanimation.cpp b/src/simpleanimation.cpp
index 161b50c9..506714d2 100644
--- a/src/simpleanimation.cpp
+++ b/src/simpleanimation.cpp
@@ -38,7 +38,7 @@ SimpleAnimation::SimpleAnimation(Animation animation):
{
}
-SimpleAnimation::SimpleAnimation(xmlNodePtr animationNode,
+SimpleAnimation::SimpleAnimation(XML::Node animationNode,
const std::string &dyePalettes)
{
initializeAnimation(animationNode, dyePalettes);
@@ -102,34 +102,33 @@ Image *SimpleAnimation::getCurrentImage() const
return nullptr;
}
-void SimpleAnimation::initializeAnimation(xmlNodePtr animationNode,
+void SimpleAnimation::initializeAnimation(XML::Node animationNode,
const std::string& dyePalettes)
{
if (!animationNode)
return;
- std::string imagePath = XML::getProperty(animationNode,
- "imageset", "");
+ std::string imagePath = animationNode.getProperty( "imageset", "");
// Instanciate the dye coloration.
if (!imagePath.empty() && !dyePalettes.empty())
Dye::instantiate(imagePath, dyePalettes);
ImageSet *imageset = ResourceManager::getInstance()->getImageSet(
- XML::getProperty(animationNode, "imageset", ""),
- XML::getProperty(animationNode, "width", 0),
- XML::getProperty(animationNode, "height", 0)
+ animationNode.getProperty("imageset", ""),
+ animationNode.getProperty("width", 0),
+ animationNode.getProperty("height", 0)
);
if (!imageset)
return;
// Get animation frames
- for (auto frameNode : XML::Children(animationNode))
+ for (auto frameNode : animationNode.children())
{
- int delay = XML::getProperty(frameNode, "delay", 0);
- int offsetX = XML::getProperty(frameNode, "offsetX", 0);
- int offsetY = XML::getProperty(frameNode, "offsetY", 0);
+ int delay = frameNode.getProperty("delay", 0);
+ int offsetX = frameNode.getProperty("offsetX", 0);
+ int offsetY = frameNode.getProperty("offsetY", 0);
Game *game = Game::instance();
if (game)
{
@@ -138,9 +137,9 @@ void SimpleAnimation::initializeAnimation(xmlNodePtr animationNode,
offsetY -= imageset->getHeight() - game->getCurrentTileHeight();
}
- if (xmlStrEqual(frameNode->name, BAD_CAST "frame"))
+ if (frameNode.name() == "frame")
{
- int index = XML::getProperty(frameNode, "index", -1);
+ int index = frameNode.getProperty("index", -1);
if (index < 0)
{
@@ -158,10 +157,10 @@ void SimpleAnimation::initializeAnimation(xmlNodePtr animationNode,
mAnimation.addFrame(img, delay, offsetX, offsetY);
}
- else if (xmlStrEqual(frameNode->name, BAD_CAST "sequence"))
+ else if (frameNode.name() == "sequence")
{
- int start = XML::getProperty(frameNode, "start", -1);
- int end = XML::getProperty(frameNode, "end", -1);
+ int start = frameNode.getProperty("start", -1);
+ int end = frameNode.getProperty("end", -1);
if (start < 0 || end < 0)
{
@@ -183,7 +182,7 @@ void SimpleAnimation::initializeAnimation(xmlNodePtr animationNode,
start++;
}
}
- else if (xmlStrEqual(frameNode->name, BAD_CAST "end"))
+ else if (frameNode.name() == "end")
{
mAnimation.addTerminator();
}
diff --git a/src/simpleanimation.h b/src/simpleanimation.h
index 6a7f899e..33168fd9 100644
--- a/src/simpleanimation.h
+++ b/src/simpleanimation.h
@@ -44,7 +44,7 @@ class SimpleAnimation final
/**
* Creates a simple animation that creates its animation from XML Data.
*/
- SimpleAnimation(xmlNodePtr animationNode,
+ SimpleAnimation(XML::Node animationNode,
const std::string &dyePalettes = std::string());
void setFrame(int frame);
@@ -63,7 +63,7 @@ class SimpleAnimation final
Image *getCurrentImage() const;
private:
- void initializeAnimation(xmlNodePtr animationNode,
+ void initializeAnimation(XML::Node animationNode,
const std::string& dyePalettes = std::string());
/** The hosted animation. */
diff --git a/src/statuseffect.cpp b/src/statuseffect.cpp
index e4f18c12..f06ab827 100644
--- a/src/statuseffect.cpp
+++ b/src/statuseffect.cpp
@@ -109,19 +109,19 @@ void StatusEffect::init()
unload();
}
-void StatusEffect::readStatusEffectNode(xmlNodePtr node, const std::string &filename)
+void StatusEffect::readStatusEffectNode(XML::Node node, const std::string &filename)
{
status_effect_map *the_map = nullptr;
- int index = atoi(XML::getProperty(node, "id", "-1").c_str());
- if (xmlStrEqual(node->name, BAD_CAST "status-effect"))
+ int index = atoi(node.getProperty("id", "-1").c_str());
+ if (node.name() == "status-effect")
{
the_map = &statusEffects;
- int block_index = atoi(XML::getProperty(node, "block-id", "-1").c_str());
+ int block_index = atoi(node.getProperty("block-id", "-1").c_str());
if (index >= 0 && block_index >= 0)
blockEffectIndexMap[block_index] = index;
}
- else if (xmlStrEqual(node->name, BAD_CAST "stun-effect"))
+ else if (node.name() == "stun-effect")
the_map = &stunEffects;
if (the_map)
@@ -129,16 +129,16 @@ void StatusEffect::readStatusEffectNode(xmlNodePtr node, const std::string &file
auto *startEffect = new StatusEffect;
auto *endEffect = new StatusEffect;
- startEffect->mMessage = XML::getProperty(node, "start-message", "");
- startEffect->mSFXEffect = XML::getProperty(node, "start-audio", "");
- startEffect->mParticleEffect = XML::getProperty(node, "start-particle", "");
- startEffect->mIcon = XML::getProperty(node, "icon", "");
- startEffect->mAction = XML::getProperty(node, "action", "");
- startEffect->mPersistentParticleEffect = (XML::getProperty(node, "persistent-particle-effect", "no")) != "no";
+ startEffect->mMessage = node.getProperty("start-message", "");
+ startEffect->mSFXEffect = node.getProperty("start-audio", "");
+ startEffect->mParticleEffect = node.getProperty("start-particle", "");
+ startEffect->mIcon = node.getProperty("icon", "");
+ startEffect->mAction = node.getProperty("action", "");
+ startEffect->mPersistentParticleEffect = (node.getProperty("persistent-particle-effect", "no")) != "no";
- endEffect->mMessage = XML::getProperty(node, "end-message", "");
- endEffect->mSFXEffect = XML::getProperty(node, "end-audio", "");
- endEffect->mParticleEffect = XML::getProperty(node, "end-particle", "");
+ endEffect->mMessage = node.getProperty("end-message", "");
+ endEffect->mSFXEffect = node.getProperty("end-audio", "");
+ endEffect->mParticleEffect = node.getProperty("end-particle", "");
(*the_map)[1][index] = startEffect;
(*the_map)[0][index] = endEffect;
diff --git a/src/statuseffect.h b/src/statuseffect.h
index 20e106a2..05b80e6b 100644
--- a/src/statuseffect.h
+++ b/src/statuseffect.h
@@ -96,7 +96,7 @@ public:
static void init();
- static void readStatusEffectNode(xmlNodePtr node, const std::string &filename);
+ static void readStatusEffectNode(XML::Node node, const std::string &filename);
static void checkStatus();
diff --git a/src/units.cpp b/src/units.cpp
index b623b4bd..fd01afd8 100644
--- a/src/units.cpp
+++ b/src/units.cpp
@@ -92,30 +92,30 @@ void Units::init()
}
}
-void Units::readUnitNode(xmlNodePtr node, const std::string &filename)
+void Units::readUnitNode(XML::Node node, const std::string &filename)
{
UnitDescription ud;
int level = 1;
- const std::string type = XML::getProperty(node, "type", "");
- ud.conversion = XML::getProperty(node, "conversion", 1);
- ud.mix = XML::getProperty(node, "mix", "no") == "yes";
+ const std::string type = node.getProperty("type", "");
+ ud.conversion = node.getProperty("conversion", 1);
+ ud.mix = node.getProperty("mix", "no") == "yes";
UnitLevel bu;
- bu.symbol = XML::getProperty(node, "base", "¤");
+ bu.symbol = node.getProperty("base", "¤");
bu.count = 1;
- bu.round = XML::getProperty(node, "round", 2);
+ bu.round = node.getProperty("round", 2);
ud.levels.push_back(bu);
- for (auto uLevel : XML::Children(node))
+ for (auto uLevel : node.children())
{
- if (xmlStrEqual(uLevel->name, BAD_CAST "level"))
+ if (uLevel.name() == "level")
{
UnitLevel ul;
- ul.symbol = XML::getProperty(uLevel, "symbol",
+ ul.symbol = uLevel.getProperty("symbol",
strprintf("¤%d",level));
- ul.count = XML::getProperty(uLevel, "count", -1);
- ul.round = XML::getProperty(uLevel, "round", bu.round);
+ ul.count = uLevel.getProperty("count", -1);
+ ul.round = uLevel.getProperty("round", bu.round);
if (ul.count > 0)
{
diff --git a/src/units.h b/src/units.h
index 96953b30..eb6b6712 100644
--- a/src/units.h
+++ b/src/units.h
@@ -30,7 +30,7 @@ class Units
public:
static void init();
- static void readUnitNode(xmlNodePtr node, const std::string &filename);
+ static void readUnitNode(XML::Node node, const std::string &filename);
static void checkStatus();
diff --git a/src/utils/xml.cpp b/src/utils/xml.cpp
index a1b1fa75..7ea5b9d6 100644
--- a/src/utils/xml.cpp
+++ b/src/utils/xml.cpp
@@ -21,14 +21,12 @@
#include "utils/xml.h"
-#include <libxml/parser.h>
#include <libxml/xmlerror.h>
#include "log.h"
#include "resources/resourcemanager.h"
-#include "utils/stringutils.h"
#include "utils/zlib.h"
namespace XML
@@ -102,76 +100,6 @@ namespace XML
xmlFreeDoc(mDoc);
}
- xmlNodePtr Document::rootNode()
- {
- return mDoc ? xmlDocGetRootElement(mDoc) : nullptr;
- }
-
- bool hasProperty(xmlNodePtr node, const char *name)
- {
- return xmlHasProp(node, BAD_CAST name) != nullptr;
- }
-
- int getProperty(xmlNodePtr node, const char* name, int def)
- {
- int &ret = def;
-
- if (xmlChar *prop = xmlGetProp(node, BAD_CAST name))
- {
- ret = atol((char*)prop);
- xmlFree(prop);
- }
-
- return ret;
- }
-
- double getFloatProperty(xmlNodePtr node, const char* name, double def)
- {
- double &ret = def;
-
- if (xmlChar *prop = xmlGetProp(node, BAD_CAST name))
- {
- ret = atof((char*)prop);
- xmlFree(prop);
- }
-
- return ret;
- }
-
- std::string getProperty(xmlNodePtr node, const char *name,
- const std::string &def)
- {
- if (xmlChar *prop = xmlGetProp(node, BAD_CAST name))
- {
- std::string val = (char*)prop;
- xmlFree(prop);
- return val;
- }
-
- return def;
- }
-
- bool getBoolProperty(xmlNodePtr node, const char* name, bool def)
- {
- bool ret = def;
-
- if (xmlChar *prop = xmlGetProp(node, BAD_CAST name))
- {
- ret = getBoolFromString((char*) prop, def);
- xmlFree(prop);
- }
- return ret;
- }
-
- xmlNodePtr findFirstChildByName(xmlNodePtr parent, const char *name)
- {
- for (auto child : XML::Children(parent))
- if (xmlStrEqual(child->name, BAD_CAST name))
- return child;
-
- return nullptr;
- }
-
void init()
{
// Initialize libxml2 and check for potential ABI mismatches between
diff --git a/src/utils/xml.h b/src/utils/xml.h
index 6878397a..95f7be99 100644
--- a/src/utils/xml.h
+++ b/src/utils/xml.h
@@ -28,106 +28,178 @@
#include <libxml/tree.h>
#include <libxml/xmlwriter.h>
-#include <string>
+#include <string_view>
/**
* XML helper functions.
*/
namespace XML
{
- /**
- * A helper class for parsing an XML document, which also cleans it up
- * again (RAII).
- */
- class Document
+ class Node
{
+ public:
+ Node(xmlNodePtr node = nullptr)
+ : node(node)
+ {}
+
+ operator bool() const { return node != nullptr; }
+
+ std::string_view name() const { return (const char *) node->name; }
+ std::string_view textContent() const;
+
+ bool hasProperty(const char *name) const;
+ int getProperty(const char *name, int def) const;
+ double getFloatProperty(const char *name, double def) const;
+ std::string getProperty(const char *name, const std::string &def) const;
+ bool getBoolProperty(const char *name, bool def) const;
+ Node findFirstChildByName(const char *name) const;
+
+ /**
+ * Helper class to iterate over the children of a node. Enables
+ * range-based for loops.
+ */
+ class Children
+ {
public:
- /**
- * Constructor that attempts to load the given file through the
- * resource manager. Logs errors.
- */
- Document(const std::string &filename, bool useResman = true);
-
- /**
- * Destructor. Frees the loaded XML file.
- */
- ~Document();
-
- /**
- * Returns the root node of the document (or NULL if there was a
- * load error).
- */
- xmlNodePtr rootNode();
+ class Iterator
+ {
+ public:
+ explicit Iterator(xmlNodePtr node) : mNode(node) {}
+
+ bool operator!=(const Iterator &other) const { return mNode != other.mNode; }
+ void operator++() { mNode = mNode->next; }
+ Node operator*() const { return mNode; }
+
+ private:
+ xmlNodePtr mNode;
+ };
+
+ explicit Children(xmlNodePtr node) : mNode(node) {}
+
+ Iterator begin() const { return Iterator(mNode->children); }
+ Iterator end() const { return Iterator(nullptr); }
private:
- xmlDocPtr mDoc;
+ xmlNodePtr mNode;
+ };
+
+ Children children() const { return Children(node); }
+
+ private:
+ const char *attribute(const char *name) const;
+
+ xmlNodePtr node;
};
- /**
- * Returns whether a certain property is present.
- */
- bool hasProperty(xmlNodePtr node, const char *name);
+ inline std::string_view Node::textContent() const
+ {
+ if (node->children && node->children->type == XML_TEXT_NODE)
+ return (const char *) node->children->content;
+ return {};
+ }
- /**
- * Gets an integer property from an xmlNodePtr.
- */
- int getProperty(xmlNodePtr node, const char *name, int def);
+ inline bool Node::hasProperty(const char *name) const
+ {
+ return xmlHasProp(node, BAD_CAST name) != nullptr;
+ }
- /**
- * Gets an floating point property from an xmlNodePtr.
- */
- double getFloatProperty(xmlNodePtr node, const char *name, double def);
+ inline int Node::getProperty(const char *name, int def) const
+ {
+ int ret = def;
- /**
- * Gets a string property from an xmlNodePtr.
- */
- std::string getProperty(xmlNodePtr node, const char *name,
- const std::string &def);
+ if (xmlChar *prop = xmlGetProp(node, BAD_CAST name))
+ {
+ ret = atol((char*)prop);
+ xmlFree(prop);
+ }
- /**
- * Gets a boolean property from an xmlNodePtr.
- */
- bool getBoolProperty(xmlNodePtr node, const char *name, bool def);
+ return ret;
+ }
- /**
- * Finds the first child node with the given name
- */
- xmlNodePtr findFirstChildByName(xmlNodePtr parent, const char *name);
+ inline double Node::getFloatProperty(const char *name, double def) const
+ {
+ double ret = def;
- /**
- * Initializes the XML engine.
- */
- void init();
+ if (xmlChar *prop = xmlGetProp(node, BAD_CAST name))
+ {
+ ret = atof((char*)prop);
+ xmlFree(prop);
+ }
- /**
- * Helper class to iterate over the children of a node. Enables range-based
- * for loops.
- */
- class Children
+ return ret;
+ }
+
+ inline std::string Node::getProperty(const char *name, const std::string &def) const
{
- public:
- class Iterator
+ if (xmlChar *prop = xmlGetProp(node, BAD_CAST name))
{
- public:
- explicit Iterator(xmlNodePtr node) : mNode(node) {}
+ std::string val = (char*)prop;
+ xmlFree(prop);
+ return val;
+ }
- bool operator!=(const Iterator &other) const { return mNode != other.mNode; }
- void operator++() { mNode = mNode->next; }
- xmlNodePtr operator*() const { return mNode; }
+ return def;
+ }
- private:
- xmlNodePtr mNode;
- };
+ inline bool Node::getBoolProperty(const char *name, bool def) const
+ {
+ bool ret = def;
- explicit Children(xmlNodePtr node) : mNode(node) {}
+ if (xmlChar *prop = xmlGetProp(node, BAD_CAST name))
+ {
+ ret = getBoolFromString((char*) prop, def);
+ xmlFree(prop);
+ }
+ return ret;
+ }
- Iterator begin() const { return Iterator(mNode->children); }
- Iterator end() const { return Iterator(nullptr); }
+ inline Node Node::findFirstChildByName(const char *name) const
+ {
+ for (auto child : children())
+ if (child.name() == name)
+ return child;
+
+ return nullptr;
+ }
+
+ /**
+ * A helper class for parsing an XML document, which also cleans it up
+ * again (RAII).
+ */
+ class Document
+ {
+ public:
+ /**
+ * Constructor that attempts to load the given file through the
+ * resource manager. Logs errors.
+ */
+ Document(const std::string &filename, bool useResman = true);
+
+ /**
+ * Destructor. Frees the loaded XML file.
+ */
+ ~Document();
+
+ /**
+ * Returns the root node of the document (or NULL if there was a
+ * load error).
+ */
+ Node rootNode();
private:
- xmlNodePtr mNode;
+ xmlDocPtr mDoc;
};
+ inline Node Document::rootNode()
+ {
+ return mDoc ? xmlDocGetRootElement(mDoc) : nullptr;
+ }
+
+ /**
+ * Initializes the XML engine.
+ */
+ void init();
+
/**
* Helper class for writing out XML data.
*
@@ -210,7 +282,6 @@ namespace XML
{
xmlTextWriterWriteString(mWriter, BAD_CAST text.c_str());
}
-
}
#endif // XML_H