From 50c73082119192c0bfef77b345258269514fb4f9 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Sat, 28 Sep 2024 14:23:20 +0300 Subject: [PATCH] move core.get_generators to generation.get_generators --- res/layouts/pages/generators.xml.lua | 2 +- src/engine.cpp | 6 +++++ src/engine.hpp | 2 ++ src/logic/scripting/lua/libcore.cpp | 28 ----------------------- src/logic/scripting/lua/libgeneration.cpp | 21 +++++++++++++++++ 5 files changed, 30 insertions(+), 29 deletions(-) diff --git a/res/layouts/pages/generators.xml.lua b/res/layouts/pages/generators.xml.lua index dd9b6743..04c1d8bb 100644 --- a/res/layouts/pages/generators.xml.lua +++ b/res/layouts/pages/generators.xml.lua @@ -1,7 +1,7 @@ settings = session.get_entry('new_world') function on_open() - local names = core.get_generators() + local names = generation.get_generators() table.sort(names) local panel = document.root diff --git a/src/engine.cpp b/src/engine.cpp index 6a98e1d3..7bb847d9 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -398,6 +398,12 @@ const Content* Engine::getContent() const { return content.get(); } +std::vector Engine::getAllContentPacks() { + auto packs = getContentPacks(); + packs.insert(packs.begin(), ContentPack::createCore(paths)); + return packs; +} + std::vector& Engine::getContentPacks() { return contentPacks; } diff --git a/src/engine.hpp b/src/engine.hpp index de25c220..75b9a1b7 100644 --- a/src/engine.hpp +++ b/src/engine.hpp @@ -130,6 +130,8 @@ public: /// @brief Get selected content packs std::vector& getContentPacks(); + std::vector getAllContentPacks(); + std::vector& getBasePacks(); /// @brief Get current screen diff --git a/src/logic/scripting/lua/libcore.cpp b/src/logic/scripting/lua/libcore.cpp index 5f04ff64..84033656 100644 --- a/src/logic/scripting/lua/libcore.cpp +++ b/src/logic/scripting/lua/libcore.cpp @@ -4,7 +4,6 @@ #include "constants.hpp" #include "engine.hpp" #include "content/Content.hpp" -#include "content/ContentLoader.hpp" #include "files/engine_paths.hpp" #include "files/settings_io.hpp" #include "frontend/menu.hpp" @@ -180,32 +179,6 @@ static int l_get_default_generator(lua::State* L) { return lua::pushstring(L, WorldGenerator::DEFAULT); } -/// @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) { - const auto& packs = engine->getContentPacks(); - - lua::createtable(L, 0, 0); - - int i = 0; - auto names = ContentLoader::scanContent( - ContentPack::createCore(engine->getPaths()), ContentType::GENERATOR); - for (const auto& name : names) { - lua::pushstring(L, name); - lua::rawseti(L, i + 1); - i++; - } - for (const auto& pack : packs) { - auto names = ContentLoader::scanContent(pack, ContentType::GENERATOR); - for (const auto& name : names) { - lua::pushstring(L, name); - lua::rawseti(L, i + 1); - i++; - } - } - return 1; -} - const luaL_Reg corelib[] = { {"new_world", lua::wrap}, {"open_world", lua::wrap}, @@ -219,5 +192,4 @@ const luaL_Reg corelib[] = { {"get_setting_info", lua::wrap}, {"quit", lua::wrap}, {"get_default_generator", lua::wrap}, - {"get_generators", lua::wrap}, {NULL, NULL}}; diff --git a/src/logic/scripting/lua/libgeneration.cpp b/src/logic/scripting/lua/libgeneration.cpp index 2f5e4851..ec425345 100644 --- a/src/logic/scripting/lua/libgeneration.cpp +++ b/src/logic/scripting/lua/libgeneration.cpp @@ -5,6 +5,7 @@ #include "coders/binary_json.hpp" #include "world/Level.hpp" #include "world/generator/VoxelFragment.hpp" +#include "content/ContentLoader.hpp" #include "engine.hpp" #include "lua_custom_types.hpp" @@ -42,7 +43,27 @@ static int l_load_structure(lua::State* L) { return lua::newuserdata(L, std::move(structure)); } +/// @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(); + + lua::createtable(L, 0, 0); + + int i = 1; + for (const auto& pack : packs) { + auto names = ContentLoader::scanContent(pack, ContentType::GENERATOR); + for (const auto& name : names) { + lua::pushstring(L, name); + lua::rawseti(L, i); + i++; + } + } + return 1; +} + const luaL_Reg generationlib[] = { {"save_structure", lua::wrap}, {"load_structure", lua::wrap}, + {"get_generators", lua::wrap}, {NULL, NULL}};