world creation and generators menus moved to xml

This commit is contained in:
MihailRis
2024-04-19 05:34:02 +03:00
parent ef4294ab47
commit 4f299be681
15 changed files with 187 additions and 136 deletions
+30
View File
@@ -8,6 +8,7 @@
#include "../../../logic/LevelController.h"
#include "../../../window/Events.h"
#include "../../../window/Window.h"
#include "../../../world/WorldGenerators.h"
#include "../scripting.h"
#include <vector>
@@ -29,6 +30,14 @@ static int l_get_worlds_list(lua_State* L) {
return 1;
}
static int l_new_world(lua_State* L) {
auto name = lua_tostring(L, 1);
auto seed = lua_tostring(L, 2);
auto generator = lua_tostring(L, 3);
menus::create_world(scripting::engine, name, seed, generator);
return 0;
}
static int l_open_world(lua_State* L) {
auto name = lua_tostring(L, 1);
scripting::engine->setScreen(nullptr);
@@ -126,8 +135,27 @@ static int l_quit(lua_State* L) {
return 0;
}
static int l_get_default_generator(lua_State* L) {
lua_pushstring(L, WorldGenerators::getDefaultGeneratorID().c_str());
return 1;
}
static int l_get_generators(lua_State* L) {
const auto& generators = WorldGenerators::getGeneratorsIDs();
lua_createtable(L, generators.size(), 0);
int i = 0;
for (auto& id : generators) {
lua_pushstring(L, id.c_str());
lua_rawseti(L, -2, i + 1);
i++;
}
return 1;
}
const luaL_Reg corelib [] = {
{"get_worlds_list", lua_wrap_errors<l_get_worlds_list>},
{"new_world", lua_wrap_errors<l_new_world>},
{"open_world", lua_wrap_errors<l_open_world>},
{"close_world", lua_wrap_errors<l_close_world>},
{"delete_world", lua_wrap_errors<l_delete_world>},
@@ -138,5 +166,7 @@ const luaL_Reg corelib [] = {
{"set_setting", lua_wrap_errors<l_set_setting>},
{"str_setting", lua_wrap_errors<l_str_setting>},
{"quit", lua_wrap_errors<l_quit>},
{"get_default_generator", lua_wrap_errors<l_get_default_generator>},
{"get_generators", lua_wrap_errors<l_get_generators>},
{NULL, NULL}
};
+3
View File
@@ -120,6 +120,9 @@ static bool getattr(lua_State* L, gui::TextBox* box, const std::string& attr) {
} else if (attr == "placeholder") {
lua_pushstring(L, util::wstr2str_utf8(box->getPlaceholder()).c_str());
return true;
} else if (attr == "valid") {
lua_pushboolean(L, box->validate());
return true;
}
return false;
}
+12
View File
@@ -3,8 +3,12 @@
#include "../scripting.h"
#include "../../../world/Level.h"
#include "../../../world/World.h"
#include "../../../engine.h"
#include <cmath>
#include <filesystem>
namespace fs = std::filesystem;
static int l_world_get_total_time(lua_State* L) {
lua_pushnumber(L, scripting::level->getWorld()->totalTime);
@@ -27,10 +31,18 @@ static int l_world_get_seed(lua_State* L) {
return 1;
}
static int l_world_exists(lua_State* L) {
auto name = lua_tostring(L, 1);
auto worldsDir = scripting::engine->getPaths()->getWorldFolder(name);
lua_pushboolean(L, fs::is_directory(worldsDir));
return 1;
}
const luaL_Reg worldlib [] = {
{"get_total_time", lua_wrap_errors<l_world_get_total_time>},
{"get_day_time", lua_wrap_errors<l_world_get_day_time>},
{"set_day_time", lua_wrap_errors<l_world_set_day_time>},
{"get_seed", lua_wrap_errors<l_world_get_seed>},
{"exists", lua_wrap_errors<l_world_exists>},
{NULL, NULL}
};