move core.get_generators to generation.get_generators

This commit is contained in:
MihailRis
2024-09-28 14:23:20 +03:00
parent c46090f881
commit 50c7308211
5 changed files with 30 additions and 29 deletions
+1 -1
View File
@@ -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
+6
View File
@@ -398,6 +398,12 @@ const Content* Engine::getContent() const {
return content.get();
}
std::vector<ContentPack> Engine::getAllContentPacks() {
auto packs = getContentPacks();
packs.insert(packs.begin(), ContentPack::createCore(paths));
return packs;
}
std::vector<ContentPack>& Engine::getContentPacks() {
return contentPacks;
}
+2
View File
@@ -130,6 +130,8 @@ public:
/// @brief Get selected content packs
std::vector<ContentPack>& getContentPacks();
std::vector<ContentPack> getAllContentPacks();
std::vector<std::string>& getBasePacks();
/// @brief Get current screen
-28
View File
@@ -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<l_new_world>},
{"open_world", lua::wrap<l_open_world>},
@@ -219,5 +192,4 @@ const luaL_Reg corelib[] = {
{"get_setting_info", lua::wrap<l_get_setting_info>},
{"quit", lua::wrap<l_quit>},
{"get_default_generator", lua::wrap<l_get_default_generator>},
{"get_generators", lua::wrap<l_get_generators>},
{NULL, NULL}};
+21
View File
@@ -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<lua::LuaVoxelStructure>(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<l_save_structure>},
{"load_structure", lua::wrap<l_load_structure>},
{"get_generators", lua::wrap<l_get_generators>},
{NULL, NULL}};