Files
cursebreaker-parser/include/configs/items.hpp
cdemeyer-teachx 998313be3c initial commit
2025-11-12 06:29:59 +09:00

104 lines
2.8 KiB
C++

#pragma once
#include <string>
#include <vector>
#include <unordered_map>
#include <tinyxml2.h>
#include "constants.h"
namespace cursebreaker {
struct CraftingItemEntry
{
uint16_t itemId{};
uint16_t amount{};
};
// Struct for item crafting requirements
struct ItemCrafting
{
WorkbenchType workbench;
SkillType craftingskill;
std::vector<CraftingItemEntry> craftingitems;
std::string checks;
ItemCrafting() = default;
};
// Main item struct
struct Item {
uint16_t id = 0;
uint16_t price = 0;
uint16_t abilityid = 0;
uint16_t learnabilityid = 0;
SkillType skill = SkillType::none;
ItemCategory category = ItemCategory::none;
ItemType slot = ItemType::resource;
Tool tool = Tool::none;
GenstatType generation = GenstatType::none;
uint8_t level = 0;
uint8_t foodlevel = 0;
uint8_t foodamount = 0;
uint8_t foodfrequency = 0;
uint8_t foodtime = 0;
uint8_t maxstack = 0;
uint8_t book = 0;
bool stackable : 1;
bool twohanded : 1;
bool undroppable : 1;
bool hidemilestone : 1;
std::string name;
std::string description;
std::string comment;
std::vector<StatValue> stats;
std::vector<ItemCrafting> craftings;
Item() = default;
};
// Helper functions for enum conversions
StatType stringToStatType(const std::string& str);
ItemCategory stringToItemCategory(const std::string& str);
ItemType stringToItemType(const std::string& str);
Tool stringToTool(const std::string& str);
SkillType stringToSkillType(const std::string& str);
WorkbenchType stringToWorkbenchType(const std::string& str);
GenstatType stringToGenstatType(const std::string& str);
// Items configuration manager
class ItemsConfig {
public:
static ItemsConfig& getInstance() {
static ItemsConfig instance;
return instance;
}
bool loadFromXML(const std::string& filepath);
const Item* getItemById(int id) const;
const std::unordered_map<int, Item>& getAllItems() const { return m_items; }
private:
ItemsConfig() = default;
~ItemsConfig() = default;
ItemsConfig(const ItemsConfig&) = delete;
ItemsConfig& operator=(const ItemsConfig&) = delete;
std::unordered_map<int, Item> m_items;
// Helper methods for parsing
void parseItem(tinyxml2::XMLElement* itemElement);
void parseStats(tinyxml2::XMLElement* itemElement, Item& item);
void parseCraftings(tinyxml2::XMLElement* itemElement, Item& item);
std::string getAttributeValue(tinyxml2::XMLElement* element, const char* attribute, const std::string& defaultValue = "");
int getAttributeValueInt(tinyxml2::XMLElement* element, const char* attribute, int defaultValue = 0);
bool getAttributeValueBool(tinyxml2::XMLElement* element, const char* attribute, bool defaultValue = false);
};
} // namespace cursebreaker