summaryrefslogtreecommitdiffstats
path: root/src/AssetManager.cpp
diff options
context:
space:
mode:
authorLaG1924 <12997935+LaG1924@users.noreply.github.com>2019-02-17 17:24:52 +0100
committerLaG1924 <12997935+LaG1924@users.noreply.github.com>2019-04-21 12:55:48 +0200
commita2fd708de4ede7427589125e680f3fb339926f4e (patch)
tree75faed7c12a7898e435cf9f40e1ca3af85ca06ec /src/AssetManager.cpp
parentMinor lua-api improvement (diff)
downloadAltCraft-a2fd708de4ede7427589125e680f3fb339926f4e.tar
AltCraft-a2fd708de4ede7427589125e680f3fb339926f4e.tar.gz
AltCraft-a2fd708de4ede7427589125e680f3fb339926f4e.tar.bz2
AltCraft-a2fd708de4ede7427589125e680f3fb339926f4e.tar.lz
AltCraft-a2fd708de4ede7427589125e680f3fb339926f4e.tar.xz
AltCraft-a2fd708de4ede7427589125e680f3fb339926f4e.tar.zst
AltCraft-a2fd708de4ede7427589125e680f3fb339926f4e.zip
Diffstat (limited to 'src/AssetManager.cpp')
-rw-r--r--src/AssetManager.cpp42
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) {