bool Items::loadFromXml() { pugi::xml_document doc; pugi::xml_parse_result result = doc.load_file("data/items/items.xml"); if (!result) { std::cout << "[Error - Items::loadFromXml] Failed to load data/items/items.xml: " << result.description() << std::endl; return false; } for (pugi::xml_node itemNode = doc.child("items").first_child(); itemNode; itemNode = itemNode.next_sibling()) { pugi::xml_attribute idAttribute = itemNode.attribute("id"); if (idAttribute) { parseItemNode(itemNode, pugi::cast<uint32_t>(idAttribute.value())); } else { pugi::xml_attribute fromIdAttribute = itemNode.attribute("fromid"); if (fromIdAttribute) { pugi::xml_attribute toIdAttribute = itemNode.attribute("toid"); if (toIdAttribute) { uint16_t id = pugi::cast<uint16_t>(fromIdAttribute.value()); uint16_t toId = pugi::cast<uint16_t>(toIdAttribute.value()); while (id <= toId) { parseItemNode(itemNode, id++); } } else { std::cout << "[Warning - Items::loadFromXml] fromid (" << fromIdAttribute.value() << ") without toid" << std::endl; } } else { std::cout << "[Warning - Items::loadFromXml] No itemid found" << std::endl; } } } return true; }
bool Items::loadFromXml() { pugi::xml_document doc; pugi::xml_parse_result result = doc.load_file("data/items/items.xml"); if (!result) { printXMLError("Error - Items::loadFromXml", "data/items/items.xml", result); return false; } for (auto itemNode : doc.child("items").children()) { pugi::xml_attribute idAttribute = itemNode.attribute("id"); if (idAttribute) { parseItemNode(itemNode, pugi::cast<uint16_t>(idAttribute.value())); continue; } pugi::xml_attribute fromIdAttribute = itemNode.attribute("fromid"); if (!fromIdAttribute) { std::cout << "[Warning - Items::loadFromXml] No item id found" << std::endl; continue; } pugi::xml_attribute toIdAttribute = itemNode.attribute("toid"); if (!toIdAttribute) { std::cout << "[Warning - Items::loadFromXml] fromid (" << fromIdAttribute.value() << ") without toid" << std::endl; continue; } uint16_t id = pugi::cast<uint16_t>(fromIdAttribute.value()); uint16_t toId = pugi::cast<uint16_t>(toIdAttribute.value()); while (id <= toId) { parseItemNode(itemNode, id++); } } buildInventoryList(); return true; }