61 lines
1.5 KiB
C++
61 lines
1.5 KiB
C++
#pragma once
|
|
|
|
#include <string>
|
|
#include <vector>
|
|
#include <unordered_map>
|
|
|
|
#include <tinyxml2.h>
|
|
|
|
#include "constants.h"
|
|
|
|
namespace cursebreaker {
|
|
|
|
struct ShopItem
|
|
{
|
|
uint16_t itemId{};
|
|
uint16_t price{};
|
|
uint16_t stock{}; // -1 for unlimited
|
|
uint16_t levelRequired{};
|
|
};
|
|
|
|
struct Shop
|
|
{
|
|
uint16_t id{};
|
|
std::string name;
|
|
std::string description;
|
|
std::string location;
|
|
|
|
std::vector<ShopItem> inventory;
|
|
|
|
Shop() = default;
|
|
};
|
|
|
|
// Shops configuration manager
|
|
class ShopsConfig {
|
|
public:
|
|
static ShopsConfig& getInstance() {
|
|
static ShopsConfig instance;
|
|
return instance;
|
|
}
|
|
|
|
bool loadFromXML(const std::string& filepath);
|
|
const Shop* getShopById(int id) const;
|
|
const std::unordered_map<int, Shop>& getAllShops() const { return m_shops; }
|
|
|
|
private:
|
|
ShopsConfig() = default;
|
|
~ShopsConfig() = default;
|
|
ShopsConfig(const ShopsConfig&) = delete;
|
|
ShopsConfig& operator=(const ShopsConfig&) = delete;
|
|
|
|
std::unordered_map<int, Shop> m_shops;
|
|
|
|
// Helper methods for parsing
|
|
void parseShop(tinyxml2::XMLElement* shopElement);
|
|
void parseInventory(tinyxml2::XMLElement* shopElement, Shop& shop);
|
|
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
|