remove content-related functions from core library

This commit is contained in:
MihailRis 2026-01-07 20:03:34 +03:00
parent 9af675611f
commit 126a8485a1
3 changed files with 67 additions and 68 deletions

View file

@ -27,14 +27,12 @@ end
local __vc__app_script_coroutine
local function complete_app_lib(app)
local __core_load_content = core.load_content
local __core_reset_content = core.reset_content
local __core_reconfig_packs = core.reconfig_packs
local __app_load_content = app.load_content
local __app_reset_content = app.reset_content
local __app_reconfig_packs = app.reconfig_packs
local __app_tick = coroutine.yield
local __app_set_setting = app.set_setting
local __app_quit = app.quit
core.load_content = nil
core.reset_content = nil
app.sleep = sleep
app.script = __VC_SCRIPT_NAME
@ -61,13 +59,13 @@ local function complete_app_lib(app)
end
app.reconfig_packs = function(...)
call_in_app_script_co(__core_reconfig_packs, ...)
call_in_app_script_co(__app_reconfig_packs, ...)
end
app.load_content = function(...)
call_in_app_script_co(__core_load_content, ...)
call_in_app_script_co(__app_load_content, ...)
end
app.reset_content = function(...)
call_in_app_script_co(__core_reset_content, ...)
call_in_app_script_co(__app_reset_content, ...)
end
function app.config_packs(packs_list)

View file

@ -4,6 +4,7 @@
#include "io/settings_io.hpp"
#include "io/devices/MemoryDevice.hpp"
#include "logic/scripting/scripting.hpp"
#include "logic/EngineController.hpp"
#include "content/ContentControl.hpp"
#include "engine/Engine.hpp"
#include "engine/EnginePaths.hpp"
@ -29,6 +30,63 @@ static int l_is_content_loaded(lua::State* L) {
return lua::pushboolean(L, content != nullptr);
}
static int l_load_content(lua::State* L) {
content_control->loadContent();
return 0;
}
static int l_reset_content(lua::State* L) {
if (level != nullptr) {
throw std::runtime_error("world must be closed before");
}
std::vector<std::string> nonResetPacks;
if (lua::istable(L, 1)) {
int len = lua::objlen(L, 1);
for (int i = 0; i < len; i++) {
lua::rawgeti(L, i + 1, 1);
nonResetPacks.emplace_back(lua::require_lstring(L, -1));
lua::pop(L);
}
}
content_control->resetContent(std::move(nonResetPacks));
return 0;
}
/// @brief Reconfigure packs
/// @param addPacks An array of packs to add
/// @param remPacks An array of packs to remove
static int l_reconfig_packs(lua::State* L) {
if (!lua::istable(L, 1)) {
throw std::runtime_error("strings array expected as the first argument");
}
if (!lua::istable(L, 2)) {
throw std::runtime_error("strings array expected as the second argument");
}
std::vector<std::string> addPacks;
int addLen = lua::objlen(L, 1);
for (int i = 0; i < addLen; i++) {
lua::rawgeti(L, i + 1, 1);
addPacks.emplace_back(lua::require_lstring(L, -1));
lua::pop(L);
}
std::vector<std::string> remPacks;
int remLen = lua::objlen(L, 2);
for (int i = 0; i < remLen; i++) {
lua::rawgeti(L, i + 1, 2);
remPacks.emplace_back(lua::require_lstring(L, -1));
lua::pop(L);
}
auto engineController = engine->getController();
try {
engineController->reconfigPacks(controller, addPacks, remPacks);
} catch (const contentpack_error& err) {
throw std::runtime_error(
std::string(err.what()) + " [" + err.getPackId() + " ]"
);
}
return 0;
}
static int l_start_debug_instance(lua::State* L) {
if (!engine->getProject().permissions.has(Permissions::DEBUGGING)) {
throw std::runtime_error("project has no debugging permission");
@ -217,6 +275,9 @@ static int l_quit(lua::State*) {
const luaL_Reg applib[] = {
{"get_version", lua::wrap<l_get_version>},
{"is_content_loaded", lua::wrap<l_is_content_loaded>},
{"load_content", lua::wrap<l_load_content>},
{"reset_content", lua::wrap<l_reset_content>},
{"reconfig_packs", lua::wrap<l_reconfig_packs>},
{"start_debug_instance", lua::wrap<l_start_debug_instance>},
{"focus", lua::wrap<l_focus>},
{"create_memory_device", lua::wrap<l_create_memory_device>},

View file

@ -23,28 +23,6 @@
using namespace scripting;
static int l_load_content(lua::State* L) {
content_control->loadContent();
return 0;
}
static int l_reset_content(lua::State* L) {
if (level != nullptr) {
throw std::runtime_error("world must be closed before");
}
std::vector<std::string> nonResetPacks;
if (lua::istable(L, 1)) {
int len = lua::objlen(L, 1);
for (int i = 0; i < len; i++) {
lua::rawgeti(L, i + 1, 1);
nonResetPacks.emplace_back(lua::require_lstring(L, -1));
lua::pop(L);
}
}
content_control->resetContent(std::move(nonResetPacks));
return 0;
}
/// @brief Creating new world
/// @param name Name world
/// @param seed Seed world
@ -122,41 +100,6 @@ static int l_delete_world(lua::State* L) {
return 0;
}
/// @brief Reconfigure packs
/// @param addPacks An array of packs to add
/// @param remPacks An array of packs to remove
static int l_reconfig_packs(lua::State* L) {
if (!lua::istable(L, 1)) {
throw std::runtime_error("strings array expected as the first argument");
}
if (!lua::istable(L, 2)) {
throw std::runtime_error("strings array expected as the second argument");
}
std::vector<std::string> addPacks;
int addLen = lua::objlen(L, 1);
for (int i = 0; i < addLen; i++) {
lua::rawgeti(L, i + 1, 1);
addPacks.emplace_back(lua::require_lstring(L, -1));
lua::pop(L);
}
std::vector<std::string> remPacks;
int remLen = lua::objlen(L, 2);
for (int i = 0; i < remLen; i++) {
lua::rawgeti(L, i + 1, 2);
remPacks.emplace_back(lua::require_lstring(L, -1));
lua::pop(L);
}
auto engineController = engine->getController();
try {
engineController->reconfigPacks(controller, addPacks, remPacks);
} catch (const contentpack_error& err) {
throw std::runtime_error(
std::string(err.what()) + " [" + err.getPackId() + " ]"
);
}
return 0;
}
static int l_blank(lua::State*) {
return 0;
}
@ -190,15 +133,12 @@ static int l_capture_output(lua::State* L) {
const luaL_Reg corelib[] = {
{"blank", lua::wrap<l_blank>},
{"load_content", lua::wrap<l_load_content>},
{"reset_content", lua::wrap<l_reset_content>},
{"new_world", lua::wrap<l_new_world>},
{"open_world", lua::wrap<l_open_world>},
{"reopen_world", lua::wrap<l_reopen_world>},
{"save_world", lua::wrap<l_save_world>},
{"close_world", lua::wrap<l_close_world>},
{"delete_world", lua::wrap<l_delete_world>},
{"reconfig_packs", lua::wrap<l_reconfig_packs>},
{"capture_output", lua::wrap<l_capture_output>},
{nullptr, nullptr}
};