Kelsidavis-WoWee/include/addons/addon_manager.hpp
Kelsi e21f808714 feat: support SavedVariablesPerCharacter for per-character addon data
Implement the SavedVariablesPerCharacter TOC directive that many addons
use to store different settings per character (Bartender, Dominos,
MoveAnything, WeakAuras, etc.). Without this, all characters share the
same addon data file.

Per-character files are stored as <AddonName>.<CharacterName>.lua.saved
alongside the existing account-wide <AddonName>.lua.saved files. The
character name is resolved from the player GUID at world entry time.

Changes:
- TocFile::getSavedVariablesPerCharacter() parses the TOC directive
- AddonManager loads/saves per-character vars alongside account-wide vars
- Character name set from game handler before addon loading
2026-03-21 02:46:21 -07:00

46 lines
1.3 KiB
C++

#pragma once
#include "addons/lua_engine.hpp"
#include "addons/toc_parser.hpp"
#include <memory>
#include <string>
#include <vector>
namespace wowee::addons {
class AddonManager {
public:
AddonManager();
~AddonManager();
bool initialize(game::GameHandler* gameHandler);
void scanAddons(const std::string& addonsPath);
void loadAllAddons();
bool runScript(const std::string& code);
void fireEvent(const std::string& event, const std::vector<std::string>& args = {});
void update(float deltaTime);
void shutdown();
const std::vector<TocFile>& getAddons() const { return addons_; }
LuaEngine* getLuaEngine() { return &luaEngine_; }
bool isInitialized() const { return luaEngine_.isInitialized(); }
void saveAllSavedVariables();
void setCharacterName(const std::string& name) { characterName_ = name; }
/// Re-initialize the Lua VM and reload all addons (used by /reload).
bool reload();
private:
LuaEngine luaEngine_;
std::vector<TocFile> addons_;
game::GameHandler* gameHandler_ = nullptr;
std::string addonsPath_;
bool loadAddon(const TocFile& addon);
std::string getSavedVariablesPath(const TocFile& addon) const;
std::string getSavedVariablesPerCharacterPath(const TocFile& addon) const;
std::string characterName_;
};
} // namespace wowee::addons