1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
#include <string>
#include <fstream>
#include <sstream>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/xml_parser.hpp>
#include "fileManager.hpp"
using boost::property_tree::ptree;
void filesystem::exportItem(loadedItem itemData, int itemID){
std::ostringstream convert;
ptree pt;
//convert the itemID into a string as a filename, for example, 1.item
std::string filename;
convert << itemID;
filename = convert.str();
filename.append(".item");
pt.put("item.name", itemData.name.c_str());
pt.put("item.description", itemData.description.c_str());
pt.put("item.iconFilename", itemData.icon.c_str());
pt.put("item.equipmentSlot", itemData.equipment_slot);
pt.put("item.armorRating", itemData.armor_rating);
pt.put("item.minDmg", itemData.min_damage);
pt.put("item.maxDmg", itemData.max_damage);
pt.put("item.specialUse", itemData.special_use);
pt.put("item.addToHealth", itemData.addToHealth);
pt.put("item.addToMana", itemData.addToMana);
write_xml (filename.c_str(), pt);
}
void filesystem::importItem(int itemID){
std::ostringstream convert;
//convert the itemID into a string as a filename, for example, 1.item
std::string filename;
convert << itemID;
filename = convert.str();
filename.append(".item");
ptree pt;
read_xml(filename.c_str(), pt);
itemBuffer.name = pt.get<std::string> ("item.name");
itemBuffer.description = pt.get<std::string> ("item.description");
itemBuffer.icon = pt.get<std::string> ("item.iconFilename");
itemBuffer.equipment_slot = pt.get<int> ("item.equipmentSlot");
itemBuffer.armor_rating = pt.get<int> ("item.armorRating");
itemBuffer.min_damage = pt.get<int> ("item.minDmg");
itemBuffer.max_damage = pt.get<int> ("item.maxDmg");
itemBuffer.special_use = pt.get<bool> ("item.specialUse");
itemBuffer.addToHealth = pt.get<int> ("item.addToHealth");
itemBuffer.addToMana = pt.get<int> ("item.addToMana");
}
void filesystem::clearItemBuffer(){
itemBuffer.name = "";
itemBuffer.description = "";
itemBuffer.icon = "";
itemBuffer.equipment_slot = 0;
itemBuffer.armor_rating = 0;
itemBuffer.min_damage = 0;
itemBuffer.max_damage = 0;
itemBuffer.special_use = 0;
itemBuffer.addToHealth = 0;
itemBuffer.addToMana = 0;
}
|