mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-03-22 23:30:14 +00:00
Addons can now persist data across sessions using the standard WoW
SavedVariables pattern:
1. Declare in .toc: ## SavedVariables: MyAddonDB
2. Use the global in Lua: MyAddonDB = MyAddonDB or {default = true}
3. Data is automatically saved on logout and restored on next login
Implementation:
- TocFile::getSavedVariables() parses comma-separated variable names
- LuaEngine::loadSavedVariables() executes saved .lua file to restore globals
- LuaEngine::saveSavedVariables() serializes Lua tables/values to valid Lua
- Serializer handles tables (nested), strings, numbers, booleans, nil
- Save triggered on PLAYER_LEAVING_WORLD and AddonManager::shutdown()
- Files stored as <AddonDir>/<AddonName>.lua.saved
Updated HelloWorld addon to track login count across sessions.
38 lines
996 B
C++
38 lines
996 B
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();
|
|
|
|
private:
|
|
LuaEngine luaEngine_;
|
|
std::vector<TocFile> addons_;
|
|
|
|
bool loadAddon(const TocFile& addon);
|
|
std::string getSavedVariablesPath(const TocFile& addon) const;
|
|
};
|
|
|
|
} // namespace wowee::addons
|