diff options
Diffstat (limited to 'src/AssetManager.cpp')
-rw-r--r-- | src/AssetManager.cpp | 42 |
1 files changed, 5 insertions, 37 deletions
diff --git a/src/AssetManager.cpp b/src/AssetManager.cpp index 361e2ef..66e7767 100644 --- a/src/AssetManager.cpp +++ b/src/AssetManager.cpp @@ -11,9 +11,9 @@ #define STB_IMAGE_IMPLEMENTATION #define STBI_ONLY_PNG #include <stb_image.h> -#include <sol.hpp> #include "Utility.hpp" +#include "Plugin.hpp" namespace fs = std::experimental::filesystem::v1; @@ -25,7 +25,6 @@ std::map<BlockId, std::string> blockIdToBlockName; std::unique_ptr<AssetTreeNode> assetTree; std::unique_ptr<TextureAtlas> atlas; std::map<BlockId, BlockFaces> blockIdToBlockFaces; -sol::state lua; void LoadIds(); void LoadAssets(); @@ -62,6 +61,8 @@ void AssetManager::InitAssetManager() LoadIds(); ParseBlockModels(); + + PluginSystem::Init(); LoadScripts(); } @@ -102,30 +103,6 @@ void LoadTextures() { } void LoadScripts() { - lua.open_libraries(sol::lib::base, sol::lib::table); - lua["AC"] = lua.create_table(); - lua["plugins"] = lua.create_table(); - lua["AC"]["RegisterPlugin"].set_function([&](sol::table &self, sol::table &plugin) { - std::string pluginName; - try { - pluginName = plugin["name"]; - lua["plugins"][pluginName] = plugin; - LOG(INFO) << "Loading plugin " << (lua["plugins"][pluginName]["displayName"] ? lua["plugins"][pluginName]["displayName"] : pluginName); - if (lua["plugins"][pluginName]["onLoad"]) - lua["plugins"][pluginName]["onLoad"].call(lua["plugins"][pluginName]); - } catch (sol::error &e) { - if (pluginName.empty()) - return; - - LOG(ERROR) << "Plugin " << pluginName << " loading failed: " << e.what(); - lua["plugins"][pluginName] = sol::lua_nil; - } - }); - - LOG(INFO) << "Loading Lua..."; - std::vector<std::string> loadedScripts; - std::vector<std::string> failedScripts; - AssetTreeNode *node = AssetManager::GetAssetByAssetName("/"); for (auto &it : node->childs) { for (auto &child : it->childs) { @@ -137,21 +114,12 @@ void LoadScripts() { LOG(ERROR) << "Unrecognised script file /" << it->name; continue; } - try { - lua.script(asset->code); - } - catch (sol::error &e) { - LOG(ERROR) << "LUA script " << it->name << "/" << child->name << "/" << script->name << " parsing failed: " << e.what(); - failedScripts.push_back(it->name); - continue; - } - loadedScripts.push_back(it->name); + PluginSystem::Execute(asset->code); } } } } - - LOG(INFO) << "Lua loaded: " << loadedScripts.size() << " failed: " << failedScripts.size(); + LOG(INFO) << "Scripts loaded"; } void WalkDirEntry(const fs::directory_entry &dirEntry, AssetTreeNode *node) { |