diff --git a/res/config/defaults.toml b/res/config/defaults.toml new file mode 100644 index 00000000..53de523f --- /dev/null +++ b/res/config/defaults.toml @@ -0,0 +1 @@ +generator = "core:default" diff --git a/res/content/base/config/defaults.toml b/res/content/base/config/defaults.toml new file mode 100644 index 00000000..d292d2ce --- /dev/null +++ b/res/content/base/config/defaults.toml @@ -0,0 +1 @@ +generator = "base:demo" diff --git a/res/layouts/pages/new_world.xml.lua b/res/layouts/pages/new_world.xml.lua index 5c0c1480..25e6f424 100644 --- a/res/layouts/pages/new_world.xml.lua +++ b/res/layouts/pages/new_world.xml.lua @@ -29,7 +29,7 @@ function on_open() "%s [%s]", gui.str("Content", "menu"), #pack.get_installed() ) if settings.generator == nil then - settings.generator = core.get_default_generator() + settings.generator = generation.get_default_generator() end document.generator_btn.text = string.format( "%s: %s", diff --git a/src/engine.cpp b/src/engine.cpp index b32128f7..6ba4fcee 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -345,6 +345,11 @@ void Engine::resetContent() { resRoots.push_back({"core", pack.folder}); load_configs(pack.folder); } + auto manager = createPacksManager(fs::path()); + manager.scan(); + for (const auto& pack : manager.getAll(basePacks)) { + resRoots.push_back({pack.id, pack.folder}); + } resPaths = std::make_unique(resdir, resRoots); contentPacks.clear(); content.reset(); @@ -353,8 +358,6 @@ void Engine::resetContent() { loadAssets(); onAssetsLoaded(); - auto manager = createPacksManager(fs::path()); - manager.scan(); contentPacks = manager.getAll(basePacks); } diff --git a/src/files/engine_paths.hpp b/src/files/engine_paths.hpp index 3abcb4ea..c5289243 100644 --- a/src/files/engine_paths.hpp +++ b/src/files/engine_paths.hpp @@ -44,6 +44,9 @@ public: std::filesystem::path resolve(const std::string& path, bool throwErr = true); static std::tuple parsePath(std::string_view view); + + static inline auto CONFIG_DEFAULTS = + std::filesystem::u8path("config/defaults.toml"); private: std::filesystem::path userFilesFolder {"."}; std::filesystem::path resourcesFolder {"res"}; diff --git a/src/logic/scripting/lua/libs/libcore.cpp b/src/logic/scripting/lua/libs/libcore.cpp index 84033656..6f0dd8b8 100644 --- a/src/logic/scripting/lua/libs/libcore.cpp +++ b/src/logic/scripting/lua/libs/libcore.cpp @@ -173,12 +173,6 @@ static int l_quit(lua::State*) { return 0; } -/// @brief Get the default world generator -/// @return The ID of the default world generator -static int l_get_default_generator(lua::State* L) { - return lua::pushstring(L, WorldGenerator::DEFAULT); -} - const luaL_Reg corelib[] = { {"new_world", lua::wrap}, {"open_world", lua::wrap}, @@ -191,5 +185,4 @@ const luaL_Reg corelib[] = { {"str_setting", lua::wrap}, {"get_setting_info", lua::wrap}, {"quit", lua::wrap}, - {"get_default_generator", lua::wrap}, {NULL, NULL}}; diff --git a/src/logic/scripting/lua/libs/libgeneration.cpp b/src/logic/scripting/lua/libs/libgeneration.cpp index 793dc868..8ff0c32a 100644 --- a/src/logic/scripting/lua/libs/libgeneration.cpp +++ b/src/logic/scripting/lua/libs/libgeneration.cpp @@ -62,8 +62,18 @@ static int l_get_generators(lua::State* L) { return 1; } +/// @brief Get the default world generator +/// @return The ID of the default world generator +static int l_get_default_generator(lua::State* L) { + auto combined = engine->getResPaths()->readCombinedObject( + EnginePaths::CONFIG_DEFAULTS.u8string() + ); + return lua::pushstring(L, combined["generator"].asString()); +} + const luaL_Reg generationlib[] = { {"save_structure", lua::wrap}, {"load_structure", lua::wrap}, {"get_generators", lua::wrap}, + {"get_default_generator", lua::wrap}, {NULL, NULL}}; diff --git a/src/world/World.cpp b/src/world/World.cpp index 52fac83f..5267561d 100644 --- a/src/world/World.cpp +++ b/src/world/World.cpp @@ -206,9 +206,6 @@ void WorldInfo::deserialize(const dv::value& root) { generator = root["generator"].asString(generator); seed = root["seed"].asInteger(seed); - if (generator.empty()) { - generator = WorldGenerator::DEFAULT; - } if (root.has("version")) { auto& verobj = root["version"]; major = verobj["major"].asInteger(); diff --git a/src/world/generator/WorldGenerator.hpp b/src/world/generator/WorldGenerator.hpp index c3943e47..c6f37fa1 100644 --- a/src/world/generator/WorldGenerator.hpp +++ b/src/world/generator/WorldGenerator.hpp @@ -131,7 +131,4 @@ public: void generate(voxel* voxels, int x, int z); WorldGenDebugInfo createDebugInfo() const; - - /// @brief Default generator name // TODO: move to config - inline static std::string DEFAULT = "core:default"; };