refactor Engine
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include "content/Content.hpp"
|
||||
#include "content/ContentLoader.hpp"
|
||||
#include "content/ContentControl.hpp"
|
||||
#include "lighting/Lighting.hpp"
|
||||
#include "logic/BlocksController.hpp"
|
||||
#include "logic/LevelController.hpp"
|
||||
@@ -625,7 +626,7 @@ static int l_reload_script(lua::State* L) {
|
||||
if (content == nullptr) {
|
||||
throw std::runtime_error("content is not initialized");
|
||||
}
|
||||
auto& writeableContent = *engine->getWriteableContent();
|
||||
auto& writeableContent = *content_control->get();
|
||||
auto& def = writeableContent.blocks.require(name);
|
||||
ContentLoader::reloadScript(writeableContent, def);
|
||||
return 0;
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "world/generator/VoxelFragment.hpp"
|
||||
#include "content/ContentLoader.hpp"
|
||||
#include "content/Content.hpp"
|
||||
#include "content/ContentControl.hpp"
|
||||
#include "engine/Engine.hpp"
|
||||
#include "../lua_custom_types.hpp"
|
||||
|
||||
@@ -50,7 +51,7 @@ static int l_load_fragment(lua::State* L) {
|
||||
/// @brief Get a list of all world generators
|
||||
/// @return A table with the IDs of all world generators
|
||||
static int l_get_generators(lua::State* L) {
|
||||
auto packs = engine->getAllContentPacks();
|
||||
auto packs = content_control->getAllContentPacks();
|
||||
|
||||
lua::createtable(L, 0, 0);
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "content/Content.hpp"
|
||||
#include "frontend/UiDocument.hpp"
|
||||
#include "frontend/hud.hpp"
|
||||
#include "content/ContentControl.hpp"
|
||||
#include "graphics/ui/elements/InventoryView.hpp"
|
||||
#include "items/Inventories.hpp"
|
||||
#include "logic/BlocksController.hpp"
|
||||
@@ -176,7 +177,7 @@ static int l_reload_script(lua::State* L) {
|
||||
if (content == nullptr) {
|
||||
throw std::runtime_error("content is not initialized");
|
||||
}
|
||||
auto& writeableContent = *engine->getWriteableContent();
|
||||
auto& writeableContent = *content_control->get();
|
||||
auto pack = writeableContent.getPackRuntime(packid);
|
||||
const auto& info = pack->getInfo();
|
||||
scripting::load_hud_script(
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "engine/Engine.hpp"
|
||||
#include "content/ContentControl.hpp"
|
||||
#include "frontend/hud.hpp"
|
||||
#include "frontend/screens/Screen.hpp"
|
||||
#include "graphics/ui/GUI.hpp"
|
||||
@@ -136,7 +137,7 @@ static void reset_pack_bindings(const io::path& packFolder) {
|
||||
|
||||
static int l_reset_bindings(lua::State*) {
|
||||
reset_pack_bindings("res:");
|
||||
for (auto& pack : engine->getContentPacks()) {
|
||||
for (const auto& pack : content_control->getContentPacks()) {
|
||||
reset_pack_bindings(pack.folder);
|
||||
}
|
||||
return 0;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "content/Content.hpp"
|
||||
#include "content/ContentLoader.hpp"
|
||||
#include "content/ContentControl.hpp"
|
||||
#include "items/ItemDef.hpp"
|
||||
#include "api_lua.hpp"
|
||||
#include "engine/Engine.hpp"
|
||||
@@ -94,7 +95,7 @@ static int l_reload_script(lua::State* L) {
|
||||
if (content == nullptr) {
|
||||
throw std::runtime_error("content is not initialized");
|
||||
}
|
||||
auto& writeableContent = *engine->getWriteableContent();
|
||||
auto& writeableContent = *content_control->get();
|
||||
auto& def = writeableContent.items.require(name);
|
||||
ContentLoader::reloadScript(writeableContent, def);
|
||||
return 0;
|
||||
|
||||
@@ -21,7 +21,7 @@ using namespace scripting;
|
||||
|
||||
static int l_pack_get_folder(lua::State* L) {
|
||||
std::string packName = lua::tostring(L, 1);
|
||||
auto packs = engine->getAllContentPacks();
|
||||
auto packs = content_control->getAllContentPacks();
|
||||
|
||||
for (auto& pack : packs) {
|
||||
if (pack.id == packName) {
|
||||
@@ -33,7 +33,7 @@ static int l_pack_get_folder(lua::State* L) {
|
||||
|
||||
/// @brief pack.get_installed() -> array<string>
|
||||
static int l_pack_get_installed(lua::State* L) {
|
||||
auto& packs = engine->getContentPacks();
|
||||
auto& packs = content_control->getContentPacks();
|
||||
lua::createtable(L, packs.size(), 0);
|
||||
for (size_t i = 0; i < packs.size(); i++) {
|
||||
lua::pushstring(L, packs[i].id);
|
||||
@@ -49,10 +49,10 @@ static int l_pack_get_available(lua::State* L) {
|
||||
worldFolder = level->getWorld()->wfile->getFolder();
|
||||
}
|
||||
PacksManager manager;
|
||||
manager.setSources(engine->getContentControl().getDefaultSources());
|
||||
manager.setSources(content_control->getDefaultSources());
|
||||
manager.scan();
|
||||
|
||||
const auto& installed = engine->getContentPacks();
|
||||
const auto& installed = content_control->getContentPacks();
|
||||
for (auto& pack : installed) {
|
||||
manager.exclude(pack.id);
|
||||
}
|
||||
@@ -142,8 +142,7 @@ static int pack_get_infos(lua::State* L) {
|
||||
lua::pop(L, 1);
|
||||
}
|
||||
std::unordered_map<std::string, ContentPack> packs;
|
||||
auto content = engine->getContent();
|
||||
const auto& loadedPacks = engine->getContentPacks();
|
||||
const auto& loadedPacks = content_control->getContentPacks();
|
||||
for (const auto& pack : loadedPacks) {
|
||||
if (ids.find(pack.id) != ids.end()) {
|
||||
packs[pack.id] = pack;
|
||||
@@ -156,7 +155,7 @@ static int pack_get_infos(lua::State* L) {
|
||||
worldFolder = level->getWorld()->wfile->getFolder();
|
||||
}
|
||||
PacksManager manager;
|
||||
manager.setSources(engine->getContentControl().getDefaultSources());
|
||||
manager.setSources(content_control->getDefaultSources());
|
||||
manager.scan();
|
||||
auto vec =
|
||||
manager.getAll(std::vector<std::string>(ids.begin(), ids.end()));
|
||||
@@ -187,8 +186,7 @@ static int l_pack_get_info(lua::State* L) {
|
||||
}
|
||||
auto packid = lua::tostring(L, 1);
|
||||
|
||||
auto content = engine->getContent();
|
||||
auto& packs = engine->getContentPacks();
|
||||
auto& packs = content_control->getContentPacks();
|
||||
auto found =
|
||||
std::find_if(packs.begin(), packs.end(), [packid](const auto& pack) {
|
||||
return pack.id == packid;
|
||||
@@ -199,7 +197,7 @@ static int l_pack_get_info(lua::State* L) {
|
||||
worldFolder = level->getWorld()->wfile->getFolder();
|
||||
}
|
||||
PacksManager manager;
|
||||
manager.setSources(engine->getContentControl().getDefaultSources());
|
||||
manager.setSources(content_control->getDefaultSources());
|
||||
manager.scan();
|
||||
auto vec = manager.getAll({packid});
|
||||
if (!vec.empty()) {
|
||||
@@ -212,7 +210,7 @@ static int l_pack_get_info(lua::State* L) {
|
||||
}
|
||||
|
||||
static int l_pack_get_base_packs(lua::State* L) {
|
||||
auto& packs = engine->getContentControl().getBasePacks();
|
||||
auto& packs = content_control->getBasePacks();
|
||||
lua::createtable(L, packs.size(), 0);
|
||||
for (size_t i = 0; i < packs.size(); i++) {
|
||||
lua::pushstring(L, packs[i]);
|
||||
@@ -237,7 +235,7 @@ static int l_pack_assemble(lua::State* L) {
|
||||
worldFolder = level->getWorld()->wfile->getFolder();
|
||||
}
|
||||
PacksManager manager;
|
||||
manager.setSources(engine->getContentControl().getDefaultSources());
|
||||
manager.setSources(content_control->getDefaultSources());
|
||||
manager.scan();
|
||||
try {
|
||||
ids = manager.assemble(ids);
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "coders/json.hpp"
|
||||
#include "content/Content.hpp"
|
||||
#include "content/ContentLoader.hpp"
|
||||
#include "content/ContentControl.hpp"
|
||||
#include "engine/Engine.hpp"
|
||||
#include "world/files/WorldFiles.hpp"
|
||||
#include "io/engine_paths.hpp"
|
||||
@@ -217,7 +218,7 @@ static int l_reload_script(lua::State* L) {
|
||||
if (content == nullptr) {
|
||||
throw std::runtime_error("content is not initialized");
|
||||
}
|
||||
auto& writeableContent = *engine->getWriteableContent();
|
||||
auto& writeableContent = *content_control->get();
|
||||
auto pack = writeableContent.getPackRuntime(packid);
|
||||
ContentLoader::loadWorldScript(*pack);
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user