refactor
This commit is contained in:
@@ -33,35 +33,9 @@ struct Achievement
|
||||
Achievement() = default;
|
||||
};
|
||||
|
||||
// Achievements configuration manager
|
||||
class AchievementsConfig {
|
||||
public:
|
||||
static AchievementsConfig& getInstance() {
|
||||
static AchievementsConfig instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
bool loadFromXML(const std::string& filepath);
|
||||
const Achievement* getAchievementById(int id) const;
|
||||
const std::unordered_map<int, Achievement>& getAllAchievements() const { return m_achievements; }
|
||||
|
||||
private:
|
||||
AchievementsConfig() = default;
|
||||
~AchievementsConfig() = default;
|
||||
AchievementsConfig(const AchievementsConfig&) = delete;
|
||||
AchievementsConfig& operator=(const AchievementsConfig&) = delete;
|
||||
|
||||
std::unordered_map<int, Achievement> m_achievements;
|
||||
|
||||
// Helper methods for parsing
|
||||
void parseAchievement(tinyxml2::XMLElement* achievementElement);
|
||||
void parseRequirements(tinyxml2::XMLElement* achievementElement, Achievement& achievement);
|
||||
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);
|
||||
};
|
||||
|
||||
// Helper functions for enum conversions
|
||||
ActionType stringToActionType(const std::string& str);
|
||||
// Achievements configuration functions
|
||||
bool loadAchievementsFromXML(const std::string& filepath);
|
||||
const Achievement* getAchievementById(uint16_t id);
|
||||
const std::unordered_map<uint16_t, Achievement>& getAllAchievements();
|
||||
|
||||
} // namespace cursebreaker
|
||||
@@ -7,7 +7,6 @@
|
||||
#include <tinyxml2.h>
|
||||
|
||||
#include "constants.h"
|
||||
#include "items.hpp" // for stringToSkillType
|
||||
|
||||
namespace cursebreaker {
|
||||
|
||||
@@ -34,32 +33,9 @@ struct Harvestable
|
||||
Harvestable() = default;
|
||||
};
|
||||
|
||||
// Harvestables configuration manager
|
||||
class HarvestablesConfig {
|
||||
public:
|
||||
static HarvestablesConfig& getInstance() {
|
||||
static HarvestablesConfig instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
bool loadFromXML(const std::string& filepath);
|
||||
const Harvestable* getHarvestableById(int id) const;
|
||||
const std::unordered_map<int, Harvestable>& getAllHarvestables() const { return m_harvestables; }
|
||||
|
||||
private:
|
||||
HarvestablesConfig() = default;
|
||||
~HarvestablesConfig() = default;
|
||||
HarvestablesConfig(const HarvestablesConfig&) = delete;
|
||||
HarvestablesConfig& operator=(const HarvestablesConfig&) = delete;
|
||||
|
||||
std::unordered_map<int, Harvestable> m_harvestables;
|
||||
|
||||
// Helper methods for parsing
|
||||
void parseHarvestable(tinyxml2::XMLElement* harvestableElement);
|
||||
void parseLoot(tinyxml2::XMLElement* harvestableElement, Harvestable& harvestable);
|
||||
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);
|
||||
};
|
||||
// Harvestables configuration functions
|
||||
bool loadHarvestablesFromXML(const std::string& filepath);
|
||||
const Harvestable* getHarvestableById(uint16_t id);
|
||||
const std::unordered_map<uint16_t, Harvestable>& getAllHarvestables();
|
||||
|
||||
} // namespace cursebreaker
|
||||
@@ -62,42 +62,9 @@ struct Item {
|
||||
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);
|
||||
};
|
||||
// Items configuration functions
|
||||
bool loadItemsFromXML(const std::string& filepath);
|
||||
const Item* getItemById(uint16_t id);
|
||||
const std::unordered_map<uint16_t, Item>& getAllItems();
|
||||
|
||||
} // namespace cursebreaker
|
||||
|
||||
@@ -30,32 +30,9 @@ struct LootTable
|
||||
LootTable() = default;
|
||||
};
|
||||
|
||||
// Loot configuration manager
|
||||
class LootConfig {
|
||||
public:
|
||||
static LootConfig& getInstance() {
|
||||
static LootConfig instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
bool loadFromXML(const std::string& filepath);
|
||||
const LootTable* getLootTableById(int id) const;
|
||||
const std::unordered_map<int, LootTable>& getAllLootTables() const { return m_lootTables; }
|
||||
|
||||
private:
|
||||
LootConfig() = default;
|
||||
~LootConfig() = default;
|
||||
LootConfig(const LootConfig&) = delete;
|
||||
LootConfig& operator=(const LootConfig&) = delete;
|
||||
|
||||
std::unordered_map<int, LootTable> m_lootTables;
|
||||
|
||||
// Helper methods for parsing
|
||||
void parseLootTable(tinyxml2::XMLElement* lootTableElement);
|
||||
void parseEntries(tinyxml2::XMLElement* lootTableElement, LootTable& lootTable);
|
||||
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);
|
||||
};
|
||||
// Loot configuration functions
|
||||
bool loadLootTablesFromXML(const std::string& filepath);
|
||||
const LootTable* getLootTableById(uint16_t id);
|
||||
const std::unordered_map<uint16_t, LootTable>& getAllLootTables();
|
||||
|
||||
} // namespace cursebreaker
|
||||
@@ -7,7 +7,6 @@
|
||||
#include <tinyxml2.h>
|
||||
|
||||
#include "constants.h"
|
||||
#include "items.hpp" // for stringToStatType
|
||||
|
||||
namespace cursebreaker {
|
||||
|
||||
@@ -36,33 +35,9 @@ struct NPC
|
||||
NPC() = default;
|
||||
};
|
||||
|
||||
// NPCs configuration manager
|
||||
class NPCsConfig {
|
||||
public:
|
||||
static NPCsConfig& getInstance() {
|
||||
static NPCsConfig instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
bool loadFromXML(const std::string& filepath);
|
||||
const NPC* getNPCById(int id) const;
|
||||
const std::unordered_map<int, NPC>& getAllNPCs() const { return m_npcs; }
|
||||
|
||||
private:
|
||||
NPCsConfig() = default;
|
||||
~NPCsConfig() = default;
|
||||
NPCsConfig(const NPCsConfig&) = delete;
|
||||
NPCsConfig& operator=(const NPCsConfig&) = delete;
|
||||
|
||||
std::unordered_map<int, NPC> m_npcs;
|
||||
|
||||
// Helper methods for parsing
|
||||
void parseNPC(tinyxml2::XMLElement* npcElement);
|
||||
void parseStats(tinyxml2::XMLElement* npcElement, NPC& npc);
|
||||
void parseLoot(tinyxml2::XMLElement* npcElement, NPC& npc);
|
||||
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);
|
||||
};
|
||||
// NPCs configuration functions
|
||||
bool loadNPCsFromXML(const std::string& filepath);
|
||||
const NPC* getNPCById(uint16_t id);
|
||||
const std::unordered_map<uint16_t, NPC>& getAllNPCs();
|
||||
|
||||
} // namespace cursebreaker
|
||||
@@ -30,32 +30,9 @@ struct Shop
|
||||
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);
|
||||
};
|
||||
// Shops configuration functions
|
||||
bool loadShopsFromXML(const std::string& filepath);
|
||||
const Shop* getShopById(uint16_t id);
|
||||
const std::unordered_map<uint16_t, Shop>& getAllShops();
|
||||
|
||||
} // namespace cursebreaker
|
||||
20
include/helpers.hpp
Normal file
20
include/helpers.hpp
Normal file
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "configs/constants.h"
|
||||
|
||||
namespace cursebreaker {
|
||||
|
||||
// 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);
|
||||
ActionType stringToActionType(const std::string& str);
|
||||
|
||||
} // namespace cursebreaker
|
||||
@@ -8,6 +8,12 @@
|
||||
|
||||
#include "assets/asset_base.hpp"
|
||||
#include "assets/scene.hpp"
|
||||
#include "configs/items.hpp"
|
||||
#include "configs/loot.hpp"
|
||||
#include "configs/harvestables.hpp"
|
||||
#include "configs/npcs.hpp"
|
||||
#include "configs/shops.hpp"
|
||||
#include "configs/achievements.hpp"
|
||||
|
||||
struct AssetPath
|
||||
{
|
||||
@@ -15,6 +21,8 @@ struct AssetPath
|
||||
AssetGUID GUID{};
|
||||
};
|
||||
|
||||
namespace cursebreaker {
|
||||
|
||||
struct ParsedProject
|
||||
{
|
||||
std::filesystem::path m_projectRoot;
|
||||
@@ -31,8 +39,16 @@ struct ParsedProject
|
||||
std::unordered_map<AssetGUID, PrefabAsset*> m_prefabsMap;
|
||||
std::unordered_map<AssetGUID, uint32_t> m_scriptToClassHash;
|
||||
|
||||
std::unordered_map<uint16_t, Item> m_items;
|
||||
std::unordered_map<uint16_t, LootTable> m_lootTables;
|
||||
std::unordered_map<uint16_t, Harvestable> m_harvestables;
|
||||
std::unordered_map<uint16_t, NPC> m_npcs;
|
||||
std::unordered_map<uint16_t, Shop> m_shops;
|
||||
std::unordered_map<uint16_t, Achievement> m_achievements;
|
||||
};
|
||||
|
||||
void ParseProject(const std::filesystem::path& projectRoot);
|
||||
|
||||
extern ParsedProject g_parsedProject;
|
||||
|
||||
} // namespace cursebreaker
|
||||
@@ -1,41 +1,18 @@
|
||||
#include "configs/achievements.hpp"
|
||||
#include "project_parser.h"
|
||||
#include "helpers.hpp"
|
||||
#include <iostream>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace cursebreaker {
|
||||
|
||||
ActionType stringToActionType(const std::string& str) {
|
||||
static const std::unordered_map<std::string, ActionType> actionMap = {
|
||||
{"NpcDeath", ActionType::NpcDeath},
|
||||
{"PlayerDeath", ActionType::PlayerDeath},
|
||||
{"PlayerRespawn", ActionType::PlayerRespawn},
|
||||
{"NpcInteract", ActionType::NpcInteract},
|
||||
{"QuestUpdate", ActionType::QuestUpdate},
|
||||
{"QuestTimerEnd", ActionType::QuestTimerEnd},
|
||||
{"UseItemOnItem", ActionType::UseItemOnItem},
|
||||
{"UseItemOnNpc", ActionType::UseItemOnNpc},
|
||||
{"ConsumeItem", ActionType::ConsumeItem},
|
||||
{"NpcCombatInteract", ActionType::NpcCombatInteract},
|
||||
{"NpcKilledByPlayer", ActionType::NpcKilledByPlayer},
|
||||
{"EnterMap", ActionType::EnterMap},
|
||||
{"VarUpdated", ActionType::VarUpdated},
|
||||
{"GrantAchievement", ActionType::GrantAchievement},
|
||||
{"PlayerKilledByNpc", ActionType::PlayerKilledByNpc},
|
||||
{"UseItem", ActionType::UseItem},
|
||||
{"CraftItem", ActionType::CraftItem},
|
||||
{"HarvestItem", ActionType::HarvestItem},
|
||||
{"BuyItem", ActionType::BuyItem},
|
||||
{"NpcTagKilledByPlayer", ActionType::NpcTagKilledByPlayer},
|
||||
{"UseAbility", ActionType::UseAbility},
|
||||
{"LootItem", ActionType::LootItem},
|
||||
{"UseItemCategoryOnItem", ActionType::UseItemCategoryOnItem}
|
||||
};
|
||||
// Static helper functions
|
||||
static std::string getAttributeValue(tinyxml2::XMLElement* element, const char* attribute, const std::string& defaultValue = "");
|
||||
static int getAttributeValueInt(tinyxml2::XMLElement* element, const char* attribute, int defaultValue = 0);
|
||||
static bool getAttributeValueBool(tinyxml2::XMLElement* element, const char* attribute, bool defaultValue = false);
|
||||
static void parseAchievement(tinyxml2::XMLElement* achievementElement);
|
||||
static void parseRequirements(tinyxml2::XMLElement* achievementElement, Achievement& achievement);
|
||||
|
||||
auto it = actionMap.find(str);
|
||||
return (it != actionMap.end()) ? it->second : ActionType::none;
|
||||
}
|
||||
|
||||
bool AchievementsConfig::loadFromXML(const std::string& filepath) {
|
||||
bool loadAchievementsFromXML(const std::string& filepath) {
|
||||
tinyxml2::XMLDocument doc;
|
||||
tinyxml2::XMLError result = doc.LoadFile(filepath.c_str());
|
||||
|
||||
@@ -50,7 +27,7 @@ bool AchievementsConfig::loadFromXML(const std::string& filepath) {
|
||||
return false;
|
||||
}
|
||||
|
||||
m_achievements.clear();
|
||||
g_parsedProject.m_achievements.clear();
|
||||
|
||||
// Parse all achievements
|
||||
for (tinyxml2::XMLElement* achievementElement = root->FirstChildElement("achievement");
|
||||
@@ -59,11 +36,11 @@ bool AchievementsConfig::loadFromXML(const std::string& filepath) {
|
||||
parseAchievement(achievementElement);
|
||||
}
|
||||
|
||||
std::cout << "Loaded " << m_achievements.size() << " achievements from XML" << std::endl;
|
||||
std::cout << "Loaded " << g_parsedProject.m_achievements.size() << " achievements from XML" << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
void AchievementsConfig::parseAchievement(tinyxml2::XMLElement* achievementElement) {
|
||||
void parseAchievement(tinyxml2::XMLElement* achievementElement) {
|
||||
Achievement achievement;
|
||||
|
||||
// Parse basic attributes
|
||||
@@ -79,10 +56,10 @@ void AchievementsConfig::parseAchievement(tinyxml2::XMLElement* achievementEleme
|
||||
// Parse child elements
|
||||
parseRequirements(achievementElement, achievement);
|
||||
|
||||
m_achievements[achievement.id] = std::move(achievement);
|
||||
g_parsedProject.m_achievements[achievement.id] = std::move(achievement);
|
||||
}
|
||||
|
||||
void AchievementsConfig::parseRequirements(tinyxml2::XMLElement* achievementElement, Achievement& achievement) {
|
||||
void parseRequirements(tinyxml2::XMLElement* achievementElement, Achievement& achievement) {
|
||||
for (tinyxml2::XMLElement* reqElement = achievementElement->FirstChildElement("requirement");
|
||||
reqElement != nullptr;
|
||||
reqElement = reqElement->NextSiblingElement("requirement")) {
|
||||
@@ -97,23 +74,27 @@ void AchievementsConfig::parseRequirements(tinyxml2::XMLElement* achievementElem
|
||||
}
|
||||
}
|
||||
|
||||
const Achievement* AchievementsConfig::getAchievementById(int id) const {
|
||||
auto it = m_achievements.find(id);
|
||||
return (it != m_achievements.end()) ? &it->second : nullptr;
|
||||
const Achievement* getAchievementById(uint16_t id) {
|
||||
auto it = g_parsedProject.m_achievements.find(id);
|
||||
return (it != g_parsedProject.m_achievements.end()) ? &it->second : nullptr;
|
||||
}
|
||||
|
||||
std::string AchievementsConfig::getAttributeValue(tinyxml2::XMLElement* element, const char* attribute, const std::string& defaultValue) {
|
||||
const std::unordered_map<uint16_t, Achievement>& getAllAchievements() {
|
||||
return g_parsedProject.m_achievements;
|
||||
}
|
||||
|
||||
std::string getAttributeValue(tinyxml2::XMLElement* element, const char* attribute, const std::string& defaultValue) {
|
||||
const char* value = element->Attribute(attribute);
|
||||
return value ? std::string(value) : defaultValue;
|
||||
}
|
||||
|
||||
int AchievementsConfig::getAttributeValueInt(tinyxml2::XMLElement* element, const char* attribute, int defaultValue) {
|
||||
int getAttributeValueInt(tinyxml2::XMLElement* element, const char* attribute, int defaultValue) {
|
||||
int value = defaultValue;
|
||||
element->QueryIntAttribute(attribute, &value);
|
||||
return value;
|
||||
}
|
||||
|
||||
bool AchievementsConfig::getAttributeValueBool(tinyxml2::XMLElement* element, const char* attribute, bool defaultValue) {
|
||||
bool getAttributeValueBool(tinyxml2::XMLElement* element, const char* attribute, bool defaultValue) {
|
||||
bool value = defaultValue;
|
||||
element->QueryBoolAttribute(attribute, &value);
|
||||
return value;
|
||||
|
||||
@@ -1,11 +1,20 @@
|
||||
#include "configs/harvestables.hpp"
|
||||
#include "project_parser.h"
|
||||
#include "helpers.hpp"
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <algorithm>
|
||||
|
||||
namespace cursebreaker {
|
||||
|
||||
bool HarvestablesConfig::loadFromXML(const std::string& filepath) {
|
||||
// Static helper functions
|
||||
static std::string getAttributeValue(tinyxml2::XMLElement* element, const char* attribute, const std::string& defaultValue = "");
|
||||
static int getAttributeValueInt(tinyxml2::XMLElement* element, const char* attribute, int defaultValue = 0);
|
||||
static bool getAttributeValueBool(tinyxml2::XMLElement* element, const char* attribute, bool defaultValue = false);
|
||||
static void parseHarvestable(tinyxml2::XMLElement* harvestableElement);
|
||||
static void parseLoot(tinyxml2::XMLElement* harvestableElement, Harvestable& harvestable);
|
||||
|
||||
bool loadHarvestablesFromXML(const std::string& filepath) {
|
||||
tinyxml2::XMLDocument doc;
|
||||
tinyxml2::XMLError result = doc.LoadFile(filepath.c_str());
|
||||
|
||||
@@ -20,7 +29,7 @@ bool HarvestablesConfig::loadFromXML(const std::string& filepath) {
|
||||
return false;
|
||||
}
|
||||
|
||||
m_harvestables.clear();
|
||||
g_parsedProject.m_harvestables.clear();
|
||||
|
||||
// Parse all harvestables
|
||||
for (tinyxml2::XMLElement* harvestableElement = root->FirstChildElement("harvestable");
|
||||
@@ -29,11 +38,11 @@ bool HarvestablesConfig::loadFromXML(const std::string& filepath) {
|
||||
parseHarvestable(harvestableElement);
|
||||
}
|
||||
|
||||
std::cout << "Loaded " << m_harvestables.size() << " harvestables from XML" << std::endl;
|
||||
std::cout << "Loaded " << g_parsedProject.m_harvestables.size() << " harvestables from XML" << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
void HarvestablesConfig::parseHarvestable(tinyxml2::XMLElement* harvestableElement) {
|
||||
void parseHarvestable(tinyxml2::XMLElement* harvestableElement) {
|
||||
Harvestable harvestable;
|
||||
|
||||
// Parse basic attributes
|
||||
@@ -49,10 +58,10 @@ void HarvestablesConfig::parseHarvestable(tinyxml2::XMLElement* harvestableEleme
|
||||
// Parse child elements
|
||||
parseLoot(harvestableElement, harvestable);
|
||||
|
||||
m_harvestables[harvestable.id] = std::move(harvestable);
|
||||
g_parsedProject.m_harvestables[harvestable.id] = std::move(harvestable);
|
||||
}
|
||||
|
||||
void HarvestablesConfig::parseLoot(tinyxml2::XMLElement* harvestableElement, Harvestable& harvestable) {
|
||||
void parseLoot(tinyxml2::XMLElement* harvestableElement, Harvestable& harvestable) {
|
||||
for (tinyxml2::XMLElement* lootElement = harvestableElement->FirstChildElement("loot");
|
||||
lootElement != nullptr;
|
||||
lootElement = lootElement->NextSiblingElement("loot")) {
|
||||
@@ -66,23 +75,27 @@ void HarvestablesConfig::parseLoot(tinyxml2::XMLElement* harvestableElement, Har
|
||||
}
|
||||
}
|
||||
|
||||
const Harvestable* HarvestablesConfig::getHarvestableById(int id) const {
|
||||
auto it = m_harvestables.find(id);
|
||||
return (it != m_harvestables.end()) ? &it->second : nullptr;
|
||||
const Harvestable* getHarvestableById(uint16_t id) {
|
||||
auto it = g_parsedProject.m_harvestables.find(id);
|
||||
return (it != g_parsedProject.m_harvestables.end()) ? &it->second : nullptr;
|
||||
}
|
||||
|
||||
std::string HarvestablesConfig::getAttributeValue(tinyxml2::XMLElement* element, const char* attribute, const std::string& defaultValue) {
|
||||
const std::unordered_map<uint16_t, Harvestable>& getAllHarvestables() {
|
||||
return g_parsedProject.m_harvestables;
|
||||
}
|
||||
|
||||
std::string getAttributeValue(tinyxml2::XMLElement* element, const char* attribute, const std::string& defaultValue) {
|
||||
const char* value = element->Attribute(attribute);
|
||||
return value ? std::string(value) : defaultValue;
|
||||
}
|
||||
|
||||
int HarvestablesConfig::getAttributeValueInt(tinyxml2::XMLElement* element, const char* attribute, int defaultValue) {
|
||||
int getAttributeValueInt(tinyxml2::XMLElement* element, const char* attribute, int defaultValue) {
|
||||
int value = defaultValue;
|
||||
element->QueryIntAttribute(attribute, &value);
|
||||
return value;
|
||||
}
|
||||
|
||||
bool HarvestablesConfig::getAttributeValueBool(tinyxml2::XMLElement* element, const char* attribute, bool defaultValue) {
|
||||
bool getAttributeValueBool(tinyxml2::XMLElement* element, const char* attribute, bool defaultValue) {
|
||||
bool value = defaultValue;
|
||||
element->QueryBoolAttribute(attribute, &value);
|
||||
return value;
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
#include "configs/items.hpp"
|
||||
#include "project_parser.h"
|
||||
#include "helpers.hpp"
|
||||
#include <iostream>
|
||||
#include <unordered_map>
|
||||
#include <sstream>
|
||||
@@ -6,169 +8,15 @@
|
||||
|
||||
namespace cursebreaker {
|
||||
|
||||
// Helper functions to convert strings to enums
|
||||
StatType stringToStatType(const std::string& str) {
|
||||
static const std::unordered_map<std::string, StatType> statMap = {
|
||||
{"damagephysical", StatType::damagePhysical},
|
||||
{"damagemagical", StatType::damageMagical},
|
||||
{"damageranged", StatType::damageRanged},
|
||||
{"accuracyphysical", StatType::accuracyPhysical},
|
||||
{"accuracymagical", StatType::accuracyMagical},
|
||||
{"accuracyranged", StatType::accuracyRanged},
|
||||
{"resistancephysical", StatType::resistancePhysical},
|
||||
{"resistancemagical", StatType::resistanceMagical},
|
||||
{"resistanceranged", StatType::resistanceRanged},
|
||||
{"health", StatType::health},
|
||||
{"mana", StatType::mana},
|
||||
{"manaregen", StatType::manaregen},
|
||||
{"healthregen", StatType::healthregen},
|
||||
{"movementSpeed", StatType::movementSpeed},
|
||||
{"power", StatType::power},
|
||||
{"critical", StatType::critical},
|
||||
{"healing", StatType::healing},
|
||||
{"DamageVsUndead", StatType::DamageVsUndead},
|
||||
{"DamageVsBeasts", StatType::DamageVsBeasts},
|
||||
{"CritterSlaying", StatType::CritterSlaying},
|
||||
{"harvestingSpeedWoodcutting", StatType::harvestingSpeedWoodcutting}
|
||||
};
|
||||
// Static helper functions
|
||||
static std::string getAttributeValue(tinyxml2::XMLElement* element, const char* attribute, const std::string& defaultValue = "");
|
||||
static int getAttributeValueInt(tinyxml2::XMLElement* element, const char* attribute, int defaultValue = 0);
|
||||
static bool getAttributeValueBool(tinyxml2::XMLElement* element, const char* attribute, bool defaultValue = false);
|
||||
static void parseItem(tinyxml2::XMLElement* itemElement);
|
||||
static void parseStats(tinyxml2::XMLElement* itemElement, Item& item);
|
||||
static void parseCraftings(tinyxml2::XMLElement* itemElement, Item& item);
|
||||
|
||||
auto it = statMap.find(str);
|
||||
return (it != statMap.end()) ? it->second : StatType::none;
|
||||
}
|
||||
|
||||
ItemCategory stringToItemCategory(const std::string& str) {
|
||||
static const std::unordered_map<std::string, ItemCategory> categoryMap = {
|
||||
{"bone", ItemCategory::bone},
|
||||
{"bow", ItemCategory::bow},
|
||||
{"crossbow", ItemCategory::crossbow},
|
||||
{"constructable", ItemCategory::constructable},
|
||||
{"torch", ItemCategory::torch},
|
||||
{"blacksmithhammer", ItemCategory::blacksmithhammer},
|
||||
{"questitem", ItemCategory::questitem},
|
||||
{"heavyArmor", ItemCategory::heavyArmor},
|
||||
{"warhammer", ItemCategory::warhammer},
|
||||
{"shield", ItemCategory::shield},
|
||||
{"hatchet", ItemCategory::hatchet},
|
||||
{"blade", ItemCategory::blade},
|
||||
{"armor", ItemCategory::armor},
|
||||
{"pickaxe", ItemCategory::pickaxe},
|
||||
{"fish", ItemCategory::fish},
|
||||
{"fishingrod", ItemCategory::fishingrod},
|
||||
{"shears", ItemCategory::shears},
|
||||
{"hammer", ItemCategory::hammer},
|
||||
{"battleaxe", ItemCategory::battleaxe},
|
||||
{"morningstar", ItemCategory::morningstar},
|
||||
{"wand", ItemCategory::wand},
|
||||
{"staff", ItemCategory::staff},
|
||||
{"dagger", ItemCategory::dagger}
|
||||
};
|
||||
|
||||
auto it = categoryMap.find(str);
|
||||
return (it != categoryMap.end()) ? it->second : ItemCategory::none;
|
||||
}
|
||||
|
||||
ItemType stringToItemType(const std::string& str) {
|
||||
static const std::unordered_map<std::string, ItemType> typeMap = {
|
||||
{"weapon", ItemType::weapon},
|
||||
{"shield", ItemType::shield},
|
||||
{"armor", ItemType::armor},
|
||||
{"head", ItemType::head},
|
||||
{"resource", ItemType::resource},
|
||||
{"consumable", ItemType::consumable},
|
||||
{"trinket", ItemType::trinket},
|
||||
{"bracelet", ItemType::bracelet}
|
||||
};
|
||||
|
||||
auto it = typeMap.find(str);
|
||||
return (it != typeMap.end()) ? it->second : ItemType::resource;
|
||||
}
|
||||
|
||||
Tool stringToTool(const std::string& str) {
|
||||
static const std::unordered_map<std::string, Tool> toolMap = {
|
||||
{"hatchet", Tool::hatchet},
|
||||
{"pickaxe", Tool::pickaxe},
|
||||
{"broom", Tool::broom},
|
||||
{"fishingrod", Tool::fishingrod}
|
||||
};
|
||||
|
||||
auto it = toolMap.find(str);
|
||||
return (it != toolMap.end()) ? it->second : Tool::none;
|
||||
}
|
||||
|
||||
SkillType stringToSkillType(const std::string& str) {
|
||||
static const std::unordered_map<std::string, SkillType> skillMap = {
|
||||
{"woodcutting", SkillType::woodcutting},
|
||||
{"fishing", SkillType::fishing},
|
||||
{"swordsmanship", SkillType::swordsmanship},
|
||||
{"mining", SkillType::mining},
|
||||
{"archery", SkillType::archery},
|
||||
{"magic", SkillType::magic},
|
||||
{"defence", SkillType::defence},
|
||||
{"blacksmithy", SkillType::blacksmithy},
|
||||
{"tailoring", SkillType::tailoring},
|
||||
{"carpentry", SkillType::carpentry},
|
||||
{"alchemy", SkillType::alchemy},
|
||||
{"cooking", SkillType::cooking}
|
||||
};
|
||||
|
||||
auto it = skillMap.find(str);
|
||||
return (it != skillMap.end()) ? it->second : SkillType::none;
|
||||
}
|
||||
|
||||
WorkbenchType stringToWorkbenchType(const std::string& str) {
|
||||
static const std::unordered_map<std::string, WorkbenchType> workbenchMap = {
|
||||
{"none", WorkbenchType::none},
|
||||
{"anvil", WorkbenchType::anvil},
|
||||
{"oven", WorkbenchType::oven},
|
||||
{"cooking", WorkbenchType::cooking},
|
||||
{"carpenter", WorkbenchType::carpenter},
|
||||
{"tailor", WorkbenchType::tailor},
|
||||
{"forge", WorkbenchType::forge},
|
||||
{"alchemist", WorkbenchType::alchemist},
|
||||
{"mystic", WorkbenchType::mystic}
|
||||
};
|
||||
|
||||
auto it = workbenchMap.find(str);
|
||||
return (it != workbenchMap.end()) ? it->second : WorkbenchType::none;
|
||||
}
|
||||
|
||||
GenstatType stringToGenstatType(const std::string& str) {
|
||||
static const std::unordered_map<std::string, GenstatType> genstatMap = {
|
||||
{"dagger", GenstatType::dagger},
|
||||
{"broadsword", GenstatType::broadsword},
|
||||
{"battleaxe", GenstatType::battleaxe},
|
||||
{"greatsword", GenstatType::greatsword},
|
||||
{"morningstar", GenstatType::morningstar},
|
||||
{"hammer", GenstatType::hammer},
|
||||
{"spear", GenstatType::spear},
|
||||
{"bow", GenstatType::bow},
|
||||
{"staff", GenstatType::staff},
|
||||
{"wand", GenstatType::wand},
|
||||
{"crossbow", GenstatType::crossbow},
|
||||
{"woodenshield", GenstatType::woodenshield},
|
||||
{"wizardhat", GenstatType::wizardhat},
|
||||
{"wizardrobe", GenstatType::wizardrobe},
|
||||
{"grandwizardhat", GenstatType::grandwizardhat},
|
||||
{"grandwizardrobe", GenstatType::grandwizardrobe},
|
||||
{"leatherhood", GenstatType::leatherhood},
|
||||
{"leatherbracelet", GenstatType::leatherbracelet},
|
||||
{"leatherarmor", GenstatType::leatherarmor},
|
||||
{"studdedleatherhood", GenstatType::studdedleatherhood},
|
||||
{"studdedleatherbracelet", GenstatType::studdedleatherbracelet},
|
||||
{"studdedleatherarmor", GenstatType::studdedleatherarmor},
|
||||
{"helmet", GenstatType::helmet},
|
||||
{"shield", GenstatType::shield},
|
||||
{"armor", GenstatType::armor},
|
||||
{"platehelmet", GenstatType::platehelmet},
|
||||
{"kiteshield", GenstatType::kiteshield},
|
||||
{"platearmor", GenstatType::platearmor}
|
||||
};
|
||||
|
||||
auto it = genstatMap.find(str);
|
||||
return (it != genstatMap.end()) ? it->second : GenstatType::none;
|
||||
}
|
||||
|
||||
bool ItemsConfig::loadFromXML(const std::string& filepath) {
|
||||
bool loadItemsFromXML(const std::string& filepath) {
|
||||
tinyxml2::XMLDocument doc;
|
||||
tinyxml2::XMLError result = doc.LoadFile(filepath.c_str());
|
||||
|
||||
@@ -183,7 +31,7 @@ bool ItemsConfig::loadFromXML(const std::string& filepath) {
|
||||
return false;
|
||||
}
|
||||
|
||||
m_items.clear();
|
||||
g_parsedProject.m_items.clear();
|
||||
|
||||
// Parse all items
|
||||
for (tinyxml2::XMLElement* itemElement = root->FirstChildElement("item");
|
||||
@@ -192,11 +40,11 @@ bool ItemsConfig::loadFromXML(const std::string& filepath) {
|
||||
parseItem(itemElement);
|
||||
}
|
||||
|
||||
std::cout << "Loaded " << m_items.size() << " items from XML" << std::endl;
|
||||
std::cout << "Loaded " << g_parsedProject.m_items.size() << " items from XML" << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
void ItemsConfig::parseItem(tinyxml2::XMLElement* itemElement) {
|
||||
void parseItem(tinyxml2::XMLElement* itemElement) {
|
||||
Item item;
|
||||
|
||||
// Parse basic attributes
|
||||
@@ -231,10 +79,10 @@ void ItemsConfig::parseItem(tinyxml2::XMLElement* itemElement) {
|
||||
parseStats(itemElement, item);
|
||||
parseCraftings(itemElement, item);
|
||||
|
||||
m_items[item.id] = std::move(item);
|
||||
g_parsedProject.m_items[item.id] = std::move(item);
|
||||
}
|
||||
|
||||
void ItemsConfig::parseStats(tinyxml2::XMLElement* itemElement, Item& item) {
|
||||
void parseStats(tinyxml2::XMLElement* itemElement, Item& item) {
|
||||
for (tinyxml2::XMLElement* statElement = itemElement->FirstChildElement("stat");
|
||||
statElement != nullptr;
|
||||
statElement = statElement->NextSiblingElement("stat")) {
|
||||
@@ -267,7 +115,7 @@ void ItemsConfig::parseStats(tinyxml2::XMLElement* itemElement, Item& item) {
|
||||
}
|
||||
|
||||
|
||||
void ItemsConfig::parseCraftings(tinyxml2::XMLElement* itemElement, Item& item) {
|
||||
void parseCraftings(tinyxml2::XMLElement* itemElement, Item& item) {
|
||||
for (tinyxml2::XMLElement* craftElement = itemElement->FirstChildElement("crafting");
|
||||
craftElement != nullptr;
|
||||
craftElement = craftElement->NextSiblingElement("crafting")) {
|
||||
@@ -309,23 +157,27 @@ void ItemsConfig::parseCraftings(tinyxml2::XMLElement* itemElement, Item& item)
|
||||
}
|
||||
}
|
||||
|
||||
const Item* ItemsConfig::getItemById(int id) const {
|
||||
auto it = m_items.find(id);
|
||||
return (it != m_items.end()) ? &it->second : nullptr;
|
||||
const Item* getItemById(uint16_t id) {
|
||||
auto it = g_parsedProject.m_items.find(id);
|
||||
return (it != g_parsedProject.m_items.end()) ? &it->second : nullptr;
|
||||
}
|
||||
|
||||
std::string ItemsConfig::getAttributeValue(tinyxml2::XMLElement* element, const char* attribute, const std::string& defaultValue) {
|
||||
const std::unordered_map<uint16_t, Item>& getAllItems() {
|
||||
return g_parsedProject.m_items;
|
||||
}
|
||||
|
||||
std::string getAttributeValue(tinyxml2::XMLElement* element, const char* attribute, const std::string& defaultValue) {
|
||||
const char* value = element->Attribute(attribute);
|
||||
return value ? std::string(value) : defaultValue;
|
||||
}
|
||||
|
||||
int ItemsConfig::getAttributeValueInt(tinyxml2::XMLElement* element, const char* attribute, int defaultValue) {
|
||||
int getAttributeValueInt(tinyxml2::XMLElement* element, const char* attribute, int defaultValue) {
|
||||
int value = defaultValue;
|
||||
element->QueryIntAttribute(attribute, &value);
|
||||
return value;
|
||||
}
|
||||
|
||||
bool ItemsConfig::getAttributeValueBool(tinyxml2::XMLElement* element, const char* attribute, bool defaultValue) {
|
||||
bool getAttributeValueBool(tinyxml2::XMLElement* element, const char* attribute, bool defaultValue) {
|
||||
bool value = defaultValue;
|
||||
element->QueryBoolAttribute(attribute, &value);
|
||||
return value;
|
||||
|
||||
@@ -1,9 +1,17 @@
|
||||
#include "configs/loot.hpp"
|
||||
#include "project_parser.h"
|
||||
#include <iostream>
|
||||
|
||||
namespace cursebreaker {
|
||||
|
||||
bool LootConfig::loadFromXML(const std::string& filepath) {
|
||||
// Static helper functions
|
||||
static std::string getAttributeValue(tinyxml2::XMLElement* element, const char* attribute, const std::string& defaultValue = "");
|
||||
static int getAttributeValueInt(tinyxml2::XMLElement* element, const char* attribute, int defaultValue = 0);
|
||||
static bool getAttributeValueBool(tinyxml2::XMLElement* element, const char* attribute, bool defaultValue = false);
|
||||
static void parseLootTable(tinyxml2::XMLElement* lootTableElement);
|
||||
static void parseEntries(tinyxml2::XMLElement* lootTableElement, LootTable& lootTable);
|
||||
|
||||
bool loadLootTablesFromXML(const std::string& filepath) {
|
||||
tinyxml2::XMLDocument doc;
|
||||
tinyxml2::XMLError result = doc.LoadFile(filepath.c_str());
|
||||
|
||||
@@ -18,7 +26,7 @@ bool LootConfig::loadFromXML(const std::string& filepath) {
|
||||
return false;
|
||||
}
|
||||
|
||||
m_lootTables.clear();
|
||||
g_parsedProject.m_lootTables.clear();
|
||||
|
||||
// Parse all loot tables
|
||||
for (tinyxml2::XMLElement* lootTableElement = root->FirstChildElement("lootTable");
|
||||
@@ -27,11 +35,11 @@ bool LootConfig::loadFromXML(const std::string& filepath) {
|
||||
parseLootTable(lootTableElement);
|
||||
}
|
||||
|
||||
std::cout << "Loaded " << m_lootTables.size() << " loot tables from XML" << std::endl;
|
||||
std::cout << "Loaded " << g_parsedProject.m_lootTables.size() << " loot tables from XML" << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
void LootConfig::parseLootTable(tinyxml2::XMLElement* lootTableElement) {
|
||||
void parseLootTable(tinyxml2::XMLElement* lootTableElement) {
|
||||
LootTable lootTable;
|
||||
|
||||
// Parse basic attributes
|
||||
@@ -42,10 +50,10 @@ void LootConfig::parseLootTable(tinyxml2::XMLElement* lootTableElement) {
|
||||
// Parse child elements
|
||||
parseEntries(lootTableElement, lootTable);
|
||||
|
||||
m_lootTables[lootTable.id] = std::move(lootTable);
|
||||
g_parsedProject.m_lootTables[lootTable.id] = std::move(lootTable);
|
||||
}
|
||||
|
||||
void LootConfig::parseEntries(tinyxml2::XMLElement* lootTableElement, LootTable& lootTable) {
|
||||
void parseEntries(tinyxml2::XMLElement* lootTableElement, LootTable& lootTable) {
|
||||
for (tinyxml2::XMLElement* entryElement = lootTableElement->FirstChildElement("entry");
|
||||
entryElement != nullptr;
|
||||
entryElement = entryElement->NextSiblingElement("entry")) {
|
||||
@@ -61,23 +69,27 @@ void LootConfig::parseEntries(tinyxml2::XMLElement* lootTableElement, LootTable&
|
||||
}
|
||||
}
|
||||
|
||||
const LootTable* LootConfig::getLootTableById(int id) const {
|
||||
auto it = m_lootTables.find(id);
|
||||
return (it != m_lootTables.end()) ? &it->second : nullptr;
|
||||
const LootTable* getLootTableById(uint16_t id) {
|
||||
auto it = g_parsedProject.m_lootTables.find(id);
|
||||
return (it != g_parsedProject.m_lootTables.end()) ? &it->second : nullptr;
|
||||
}
|
||||
|
||||
std::string LootConfig::getAttributeValue(tinyxml2::XMLElement* element, const char* attribute, const std::string& defaultValue) {
|
||||
const std::unordered_map<uint16_t, LootTable>& getAllLootTables() {
|
||||
return g_parsedProject.m_lootTables;
|
||||
}
|
||||
|
||||
std::string getAttributeValue(tinyxml2::XMLElement* element, const char* attribute, const std::string& defaultValue) {
|
||||
const char* value = element->Attribute(attribute);
|
||||
return value ? std::string(value) : defaultValue;
|
||||
}
|
||||
|
||||
int LootConfig::getAttributeValueInt(tinyxml2::XMLElement* element, const char* attribute, int defaultValue) {
|
||||
int getAttributeValueInt(tinyxml2::XMLElement* element, const char* attribute, int defaultValue) {
|
||||
int value = defaultValue;
|
||||
element->QueryIntAttribute(attribute, &value);
|
||||
return value;
|
||||
}
|
||||
|
||||
bool LootConfig::getAttributeValueBool(tinyxml2::XMLElement* element, const char* attribute, bool defaultValue) {
|
||||
bool getAttributeValueBool(tinyxml2::XMLElement* element, const char* attribute, bool defaultValue) {
|
||||
bool value = defaultValue;
|
||||
element->QueryBoolAttribute(attribute, &value);
|
||||
return value;
|
||||
|
||||
@@ -1,11 +1,21 @@
|
||||
#include "configs/npcs.hpp"
|
||||
#include "project_parser.h"
|
||||
#include "helpers.hpp"
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <algorithm>
|
||||
|
||||
namespace cursebreaker {
|
||||
|
||||
bool NPCsConfig::loadFromXML(const std::string& filepath) {
|
||||
// Static helper functions
|
||||
static std::string getAttributeValue(tinyxml2::XMLElement* element, const char* attribute, const std::string& defaultValue = "");
|
||||
static int getAttributeValueInt(tinyxml2::XMLElement* element, const char* attribute, int defaultValue = 0);
|
||||
static bool getAttributeValueBool(tinyxml2::XMLElement* element, const char* attribute, bool defaultValue = false);
|
||||
static void parseNPC(tinyxml2::XMLElement* npcElement);
|
||||
static void parseStats(tinyxml2::XMLElement* npcElement, NPC& npc);
|
||||
static void parseLoot(tinyxml2::XMLElement* npcElement, NPC& npc);
|
||||
|
||||
bool loadNPCsFromXML(const std::string& filepath) {
|
||||
tinyxml2::XMLDocument doc;
|
||||
tinyxml2::XMLError result = doc.LoadFile(filepath.c_str());
|
||||
|
||||
@@ -20,7 +30,7 @@ bool NPCsConfig::loadFromXML(const std::string& filepath) {
|
||||
return false;
|
||||
}
|
||||
|
||||
m_npcs.clear();
|
||||
g_parsedProject.m_npcs.clear();
|
||||
|
||||
// Parse all NPCs
|
||||
for (tinyxml2::XMLElement* npcElement = root->FirstChildElement("npc");
|
||||
@@ -29,11 +39,11 @@ bool NPCsConfig::loadFromXML(const std::string& filepath) {
|
||||
parseNPC(npcElement);
|
||||
}
|
||||
|
||||
std::cout << "Loaded " << m_npcs.size() << " NPCs from XML" << std::endl;
|
||||
std::cout << "Loaded " << g_parsedProject.m_npcs.size() << " NPCs from XML" << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
void NPCsConfig::parseNPC(tinyxml2::XMLElement* npcElement) {
|
||||
void parseNPC(tinyxml2::XMLElement* npcElement) {
|
||||
NPC npc;
|
||||
|
||||
// Parse basic attributes
|
||||
@@ -53,10 +63,10 @@ void NPCsConfig::parseNPC(tinyxml2::XMLElement* npcElement) {
|
||||
parseStats(npcElement, npc);
|
||||
parseLoot(npcElement, npc);
|
||||
|
||||
m_npcs[npc.id] = std::move(npc);
|
||||
g_parsedProject.m_npcs[npc.id] = std::move(npc);
|
||||
}
|
||||
|
||||
void NPCsConfig::parseStats(tinyxml2::XMLElement* npcElement, NPC& npc) {
|
||||
void parseStats(tinyxml2::XMLElement* npcElement, NPC& npc) {
|
||||
for (tinyxml2::XMLElement* statElement = npcElement->FirstChildElement("stat");
|
||||
statElement != nullptr;
|
||||
statElement = statElement->NextSiblingElement("stat")) {
|
||||
@@ -70,7 +80,7 @@ void NPCsConfig::parseStats(tinyxml2::XMLElement* npcElement, NPC& npc) {
|
||||
}
|
||||
}
|
||||
|
||||
void NPCsConfig::parseLoot(tinyxml2::XMLElement* npcElement, NPC& npc) {
|
||||
void parseLoot(tinyxml2::XMLElement* npcElement, NPC& npc) {
|
||||
std::string lootItemsStr = getAttributeValue(npcElement, "lootitems");
|
||||
if (!lootItemsStr.empty()) {
|
||||
std::stringstream ss(lootItemsStr);
|
||||
@@ -86,23 +96,27 @@ void NPCsConfig::parseLoot(tinyxml2::XMLElement* npcElement, NPC& npc) {
|
||||
}
|
||||
}
|
||||
|
||||
const NPC* NPCsConfig::getNPCById(int id) const {
|
||||
auto it = m_npcs.find(id);
|
||||
return (it != m_npcs.end()) ? &it->second : nullptr;
|
||||
const NPC* getNPCById(uint16_t id) {
|
||||
auto it = g_parsedProject.m_npcs.find(id);
|
||||
return (it != g_parsedProject.m_npcs.end()) ? &it->second : nullptr;
|
||||
}
|
||||
|
||||
std::string NPCsConfig::getAttributeValue(tinyxml2::XMLElement* element, const char* attribute, const std::string& defaultValue) {
|
||||
const std::unordered_map<uint16_t, NPC>& getAllNPCs() {
|
||||
return g_parsedProject.m_npcs;
|
||||
}
|
||||
|
||||
std::string getAttributeValue(tinyxml2::XMLElement* element, const char* attribute, const std::string& defaultValue) {
|
||||
const char* value = element->Attribute(attribute);
|
||||
return value ? std::string(value) : defaultValue;
|
||||
}
|
||||
|
||||
int NPCsConfig::getAttributeValueInt(tinyxml2::XMLElement* element, const char* attribute, int defaultValue) {
|
||||
int getAttributeValueInt(tinyxml2::XMLElement* element, const char* attribute, int defaultValue) {
|
||||
int value = defaultValue;
|
||||
element->QueryIntAttribute(attribute, &value);
|
||||
return value;
|
||||
}
|
||||
|
||||
bool NPCsConfig::getAttributeValueBool(tinyxml2::XMLElement* element, const char* attribute, bool defaultValue) {
|
||||
bool getAttributeValueBool(tinyxml2::XMLElement* element, const char* attribute, bool defaultValue) {
|
||||
bool value = defaultValue;
|
||||
element->QueryBoolAttribute(attribute, &value);
|
||||
return value;
|
||||
|
||||
@@ -1,9 +1,17 @@
|
||||
#include "configs/shops.hpp"
|
||||
#include "project_parser.h"
|
||||
#include <iostream>
|
||||
|
||||
namespace cursebreaker {
|
||||
|
||||
bool ShopsConfig::loadFromXML(const std::string& filepath) {
|
||||
// Static helper functions
|
||||
static std::string getAttributeValue(tinyxml2::XMLElement* element, const char* attribute, const std::string& defaultValue = "");
|
||||
static int getAttributeValueInt(tinyxml2::XMLElement* element, const char* attribute, int defaultValue = 0);
|
||||
static bool getAttributeValueBool(tinyxml2::XMLElement* element, const char* attribute, bool defaultValue = false);
|
||||
static void parseShop(tinyxml2::XMLElement* shopElement);
|
||||
static void parseInventory(tinyxml2::XMLElement* shopElement, Shop& shop);
|
||||
|
||||
bool loadShopsFromXML(const std::string& filepath) {
|
||||
tinyxml2::XMLDocument doc;
|
||||
tinyxml2::XMLError result = doc.LoadFile(filepath.c_str());
|
||||
|
||||
@@ -18,7 +26,7 @@ bool ShopsConfig::loadFromXML(const std::string& filepath) {
|
||||
return false;
|
||||
}
|
||||
|
||||
m_shops.clear();
|
||||
g_parsedProject.m_shops.clear();
|
||||
|
||||
// Parse all shops
|
||||
for (tinyxml2::XMLElement* shopElement = root->FirstChildElement("shop");
|
||||
@@ -27,11 +35,11 @@ bool ShopsConfig::loadFromXML(const std::string& filepath) {
|
||||
parseShop(shopElement);
|
||||
}
|
||||
|
||||
std::cout << "Loaded " << m_shops.size() << " shops from XML" << std::endl;
|
||||
std::cout << "Loaded " << g_parsedProject.m_shops.size() << " shops from XML" << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
void ShopsConfig::parseShop(tinyxml2::XMLElement* shopElement) {
|
||||
void parseShop(tinyxml2::XMLElement* shopElement) {
|
||||
Shop shop;
|
||||
|
||||
// Parse basic attributes
|
||||
@@ -43,10 +51,10 @@ void ShopsConfig::parseShop(tinyxml2::XMLElement* shopElement) {
|
||||
// Parse child elements
|
||||
parseInventory(shopElement, shop);
|
||||
|
||||
m_shops[shop.id] = std::move(shop);
|
||||
g_parsedProject.m_shops[shop.id] = std::move(shop);
|
||||
}
|
||||
|
||||
void ShopsConfig::parseInventory(tinyxml2::XMLElement* shopElement, Shop& shop) {
|
||||
void parseInventory(tinyxml2::XMLElement* shopElement, Shop& shop) {
|
||||
for (tinyxml2::XMLElement* itemElement = shopElement->FirstChildElement("item");
|
||||
itemElement != nullptr;
|
||||
itemElement = itemElement->NextSiblingElement("item")) {
|
||||
@@ -61,23 +69,27 @@ void ShopsConfig::parseInventory(tinyxml2::XMLElement* shopElement, Shop& shop)
|
||||
}
|
||||
}
|
||||
|
||||
const Shop* ShopsConfig::getShopById(int id) const {
|
||||
auto it = m_shops.find(id);
|
||||
return (it != m_shops.end()) ? &it->second : nullptr;
|
||||
const Shop* getShopById(uint16_t id) {
|
||||
auto it = g_parsedProject.m_shops.find(id);
|
||||
return (it != g_parsedProject.m_shops.end()) ? &it->second : nullptr;
|
||||
}
|
||||
|
||||
std::string ShopsConfig::getAttributeValue(tinyxml2::XMLElement* element, const char* attribute, const std::string& defaultValue) {
|
||||
const std::unordered_map<uint16_t, Shop>& getAllShops() {
|
||||
return g_parsedProject.m_shops;
|
||||
}
|
||||
|
||||
std::string getAttributeValue(tinyxml2::XMLElement* element, const char* attribute, const std::string& defaultValue) {
|
||||
const char* value = element->Attribute(attribute);
|
||||
return value ? std::string(value) : defaultValue;
|
||||
}
|
||||
|
||||
int ShopsConfig::getAttributeValueInt(tinyxml2::XMLElement* element, const char* attribute, int defaultValue) {
|
||||
int getAttributeValueInt(tinyxml2::XMLElement* element, const char* attribute, int defaultValue) {
|
||||
int value = defaultValue;
|
||||
element->QueryIntAttribute(attribute, &value);
|
||||
return value;
|
||||
}
|
||||
|
||||
bool ShopsConfig::getAttributeValueBool(tinyxml2::XMLElement* element, const char* attribute, bool defaultValue) {
|
||||
bool getAttributeValueBool(tinyxml2::XMLElement* element, const char* attribute, bool defaultValue) {
|
||||
bool value = defaultValue;
|
||||
element->QueryBoolAttribute(attribute, &value);
|
||||
return value;
|
||||
|
||||
198
src/helpers.cpp
Normal file
198
src/helpers.cpp
Normal file
@@ -0,0 +1,198 @@
|
||||
#include "helpers.hpp"
|
||||
|
||||
namespace cursebreaker {
|
||||
|
||||
// Helper functions to convert strings to enums
|
||||
StatType stringToStatType(const std::string& str) {
|
||||
static const std::unordered_map<std::string, StatType> statMap = {
|
||||
{"damagephysical", StatType::damagePhysical},
|
||||
{"damagemagical", StatType::damageMagical},
|
||||
{"damageranged", StatType::damageRanged},
|
||||
{"accuracyphysical", StatType::accuracyPhysical},
|
||||
{"accuracymagical", StatType::accuracyMagical},
|
||||
{"accuracyranged", StatType::accuracyRanged},
|
||||
{"resistancephysical", StatType::resistancePhysical},
|
||||
{"resistancemagical", StatType::resistanceMagical},
|
||||
{"resistanceranged", StatType::resistanceRanged},
|
||||
{"health", StatType::health},
|
||||
{"mana", StatType::mana},
|
||||
{"manaregen", StatType::manaregen},
|
||||
{"healthregen", StatType::healthregen},
|
||||
{"movementSpeed", StatType::movementSpeed},
|
||||
{"power", StatType::power},
|
||||
{"critical", StatType::critical},
|
||||
{"healing", StatType::healing},
|
||||
{"DamageVsUndead", StatType::DamageVsUndead},
|
||||
{"DamageVsBeasts", StatType::DamageVsBeasts},
|
||||
{"CritterSlaying", StatType::CritterSlaying},
|
||||
{"harvestingSpeedWoodcutting", StatType::harvestingSpeedWoodcutting}
|
||||
};
|
||||
|
||||
auto it = statMap.find(str);
|
||||
return (it != statMap.end()) ? it->second : StatType::none;
|
||||
}
|
||||
|
||||
ItemCategory stringToItemCategory(const std::string& str) {
|
||||
static const std::unordered_map<std::string, ItemCategory> categoryMap = {
|
||||
{"bone", ItemCategory::bone},
|
||||
{"bow", ItemCategory::bow},
|
||||
{"crossbow", ItemCategory::crossbow},
|
||||
{"constructable", ItemCategory::constructable},
|
||||
{"torch", ItemCategory::torch},
|
||||
{"blacksmithhammer", ItemCategory::blacksmithhammer},
|
||||
{"questitem", ItemCategory::questitem},
|
||||
{"heavyArmor", ItemCategory::heavyArmor},
|
||||
{"warhammer", ItemCategory::warhammer},
|
||||
{"shield", ItemCategory::shield},
|
||||
{"hatchet", ItemCategory::hatchet},
|
||||
{"blade", ItemCategory::blade},
|
||||
{"armor", ItemCategory::armor},
|
||||
{"pickaxe", ItemCategory::pickaxe},
|
||||
{"fish", ItemCategory::fish},
|
||||
{"fishingrod", ItemCategory::fishingrod},
|
||||
{"shears", ItemCategory::shears},
|
||||
{"hammer", ItemCategory::hammer},
|
||||
{"battleaxe", ItemCategory::battleaxe},
|
||||
{"morningstar", ItemCategory::morningstar},
|
||||
{"wand", ItemCategory::wand},
|
||||
{"staff", ItemCategory::staff},
|
||||
{"dagger", ItemCategory::dagger}
|
||||
};
|
||||
|
||||
auto it = categoryMap.find(str);
|
||||
return (it != categoryMap.end()) ? it->second : ItemCategory::none;
|
||||
}
|
||||
|
||||
ItemType stringToItemType(const std::string& str) {
|
||||
static const std::unordered_map<std::string, ItemType> typeMap = {
|
||||
{"weapon", ItemType::weapon},
|
||||
{"shield", ItemType::shield},
|
||||
{"armor", ItemType::armor},
|
||||
{"head", ItemType::head},
|
||||
{"resource", ItemType::resource},
|
||||
{"consumable", ItemType::consumable},
|
||||
{"trinket", ItemType::trinket},
|
||||
{"bracelet", ItemType::bracelet}
|
||||
};
|
||||
|
||||
auto it = typeMap.find(str);
|
||||
return (it != typeMap.end()) ? it->second : ItemType::resource;
|
||||
}
|
||||
|
||||
Tool stringToTool(const std::string& str) {
|
||||
static const std::unordered_map<std::string, Tool> toolMap = {
|
||||
{"hatchet", Tool::hatchet},
|
||||
{"pickaxe", Tool::pickaxe},
|
||||
{"broom", Tool::broom},
|
||||
{"fishingrod", Tool::fishingrod}
|
||||
};
|
||||
|
||||
auto it = toolMap.find(str);
|
||||
return (it != toolMap.end()) ? it->second : Tool::none;
|
||||
}
|
||||
|
||||
SkillType stringToSkillType(const std::string& str) {
|
||||
static const std::unordered_map<std::string, SkillType> skillMap = {
|
||||
{"woodcutting", SkillType::woodcutting},
|
||||
{"fishing", SkillType::fishing},
|
||||
{"swordsmanship", SkillType::swordsmanship},
|
||||
{"mining", SkillType::mining},
|
||||
{"archery", SkillType::archery},
|
||||
{"magic", SkillType::magic},
|
||||
{"defence", SkillType::defence},
|
||||
{"blacksmithy", SkillType::blacksmithy},
|
||||
{"tailoring", SkillType::tailoring},
|
||||
{"carpentry", SkillType::carpentry},
|
||||
{"alchemy", SkillType::alchemy},
|
||||
{"cooking", SkillType::cooking}
|
||||
};
|
||||
|
||||
auto it = skillMap.find(str);
|
||||
return (it != skillMap.end()) ? it->second : SkillType::none;
|
||||
}
|
||||
|
||||
WorkbenchType stringToWorkbenchType(const std::string& str) {
|
||||
static const std::unordered_map<std::string, WorkbenchType> workbenchMap = {
|
||||
{"none", WorkbenchType::none},
|
||||
{"anvil", WorkbenchType::anvil},
|
||||
{"oven", WorkbenchType::oven},
|
||||
{"cooking", WorkbenchType::cooking},
|
||||
{"carpenter", WorkbenchType::carpenter},
|
||||
{"tailor", WorkbenchType::tailor},
|
||||
{"forge", WorkbenchType::forge},
|
||||
{"alchemist", WorkbenchType::alchemist},
|
||||
{"mystic", WorkbenchType::mystic}
|
||||
};
|
||||
|
||||
auto it = workbenchMap.find(str);
|
||||
return (it != workbenchMap.end()) ? it->second : WorkbenchType::none;
|
||||
}
|
||||
|
||||
GenstatType stringToGenstatType(const std::string& str) {
|
||||
static const std::unordered_map<std::string, GenstatType> genstatMap = {
|
||||
{"dagger", GenstatType::dagger},
|
||||
{"broadsword", GenstatType::broadsword},
|
||||
{"battleaxe", GenstatType::battleaxe},
|
||||
{"greatsword", GenstatType::greatsword},
|
||||
{"morningstar", GenstatType::morningstar},
|
||||
{"hammer", GenstatType::hammer},
|
||||
{"spear", GenstatType::spear},
|
||||
{"bow", GenstatType::bow},
|
||||
{"staff", GenstatType::staff},
|
||||
{"wand", GenstatType::wand},
|
||||
{"crossbow", GenstatType::crossbow},
|
||||
{"woodenshield", GenstatType::woodenshield},
|
||||
{"wizardhat", GenstatType::wizardhat},
|
||||
{"wizardrobe", GenstatType::wizardrobe},
|
||||
{"grandwizardhat", GenstatType::grandwizardhat},
|
||||
{"grandwizardrobe", GenstatType::grandwizardrobe},
|
||||
{"leatherhood", GenstatType::leatherhood},
|
||||
{"leatherbracelet", GenstatType::leatherbracelet},
|
||||
{"leatherarmor", GenstatType::leatherarmor},
|
||||
{"studdedleatherhood", GenstatType::studdedleatherhood},
|
||||
{"studdedleatherbracelet", GenstatType::studdedleatherbracelet},
|
||||
{"studdedleatherarmor", GenstatType::studdedleatherarmor},
|
||||
{"helmet", GenstatType::helmet},
|
||||
{"shield", GenstatType::shield},
|
||||
{"armor", GenstatType::armor},
|
||||
{"platehelmet", GenstatType::platehelmet},
|
||||
{"kiteshield", GenstatType::kiteshield},
|
||||
{"platearmor", GenstatType::platearmor}
|
||||
};
|
||||
|
||||
auto it = genstatMap.find(str);
|
||||
return (it != genstatMap.end()) ? it->second : GenstatType::none;
|
||||
}
|
||||
|
||||
ActionType stringToActionType(const std::string& str) {
|
||||
static const std::unordered_map<std::string, ActionType> actionMap = {
|
||||
{"NpcDeath", ActionType::NpcDeath},
|
||||
{"PlayerDeath", ActionType::PlayerDeath},
|
||||
{"PlayerRespawn", ActionType::PlayerRespawn},
|
||||
{"NpcInteract", ActionType::NpcInteract},
|
||||
{"QuestUpdate", ActionType::QuestUpdate},
|
||||
{"QuestTimerEnd", ActionType::QuestTimerEnd},
|
||||
{"UseItemOnItem", ActionType::UseItemOnItem},
|
||||
{"UseItemOnNpc", ActionType::UseItemOnNpc},
|
||||
{"ConsumeItem", ActionType::ConsumeItem},
|
||||
{"NpcCombatInteract", ActionType::NpcCombatInteract},
|
||||
{"NpcKilledByPlayer", ActionType::NpcKilledByPlayer},
|
||||
{"EnterMap", ActionType::EnterMap},
|
||||
{"VarUpdated", ActionType::VarUpdated},
|
||||
{"GrantAchievement", ActionType::GrantAchievement},
|
||||
{"PlayerKilledByNpc", ActionType::PlayerKilledByNpc},
|
||||
{"UseItem", ActionType::UseItem},
|
||||
{"CraftItem", ActionType::CraftItem},
|
||||
{"HarvestItem", ActionType::HarvestItem},
|
||||
{"BuyItem", ActionType::BuyItem},
|
||||
{"NpcTagKilledByPlayer", ActionType::NpcTagKilledByPlayer},
|
||||
{"UseAbility", ActionType::UseAbility},
|
||||
{"LootItem", ActionType::LootItem},
|
||||
{"UseItemCategoryOnItem", ActionType::UseItemCategoryOnItem}
|
||||
};
|
||||
|
||||
auto it = actionMap.find(str);
|
||||
return (it != actionMap.end()) ? it->second : ActionType::none;
|
||||
}
|
||||
|
||||
} // namespace cursebreaker
|
||||
22
src/main.cpp
22
src/main.cpp
@@ -7,6 +7,8 @@
|
||||
#include "assets/scene.hpp"
|
||||
#include "configs/items.hpp"
|
||||
|
||||
using namespace cursebreaker;
|
||||
|
||||
int main() {
|
||||
|
||||
ParseProject("../../CBAssets/_GameAssets/");
|
||||
@@ -17,25 +19,5 @@ int main() {
|
||||
BuildTree(scene);
|
||||
}
|
||||
|
||||
// Test items parser
|
||||
std::cout << "Testing items parser..." << std::endl;
|
||||
auto& itemsConfig = cursebreaker::ItemsConfig::getInstance();
|
||||
bool success = itemsConfig.loadFromXML("../../CBAssets/Data/XMLs/Items/Items.xml");
|
||||
if (success) {
|
||||
std::cout << "Successfully loaded items XML!" << std::endl;
|
||||
|
||||
// Test getting a specific item
|
||||
const auto* item = itemsConfig.getItemById(150);
|
||||
if (item) {
|
||||
std::cout << "Found item: " << item->name << " (ID: " << item->id << ")" << std::endl;
|
||||
std::cout << "Description: " << item->description << std::endl;
|
||||
std::cout << "Level: " << item->level << ", Price: " << item->price << std::endl;
|
||||
} else {
|
||||
std::cout << "Item with ID 150 not found" << std::endl;
|
||||
}
|
||||
} else {
|
||||
std::cout << "Failed to load items XML!" << std::endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -29,6 +29,8 @@
|
||||
#include "assets/mesh_filter.hpp"
|
||||
#include "assets/prefab_instance.hpp"
|
||||
|
||||
namespace cursebreaker {
|
||||
|
||||
constexpr uint32_t fnv1a_hash(const char* str, uint32_t hash = 2166136261u)
|
||||
{
|
||||
return (*str == '\0') ? hash : fnv1a_hash(str + 1, (hash ^ static_cast<uint32_t>(*str)) * 16777619u);
|
||||
@@ -461,3 +463,5 @@ void ParseProject(const std::filesystem::path& projectRoot)
|
||||
project.m_sceneAssets = ParseScenes(std::vector<AssetPath>(tilesFiles.begin(), tilesFiles.end()));
|
||||
}
|
||||
|
||||
|
||||
} // namespace cursebreaker
|
||||
|
||||
Reference in New Issue
Block a user