mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-14 15:31:49 +00:00
fixes
This commit is contained in:
parent
89a6747c21
commit
b035621249
5 changed files with 11 additions and 38 deletions
|
|
@ -334,7 +334,7 @@ void ContentLoader::load() {
|
||||||
|
|
||||||
fixPackIndices();
|
fixPackIndices();
|
||||||
|
|
||||||
loadMainScript(*runtime);
|
loadContentScript(*runtime);
|
||||||
|
|
||||||
auto folder = pack->folder;
|
auto folder = pack->folder;
|
||||||
|
|
||||||
|
|
@ -342,8 +342,6 @@ void ContentLoader::load() {
|
||||||
EnginePaths::CONFIG_DEFAULTS.string()
|
EnginePaths::CONFIG_DEFAULTS.string()
|
||||||
);
|
);
|
||||||
|
|
||||||
scripting::on_content_initialization();
|
|
||||||
|
|
||||||
// Load world generators
|
// Load world generators
|
||||||
io::path generatorsDir = folder / "generators";
|
io::path generatorsDir = folder / "generators";
|
||||||
foreach_file(generatorsDir, [this](const io::path& file) {
|
foreach_file(generatorsDir, [this](const io::path& file) {
|
||||||
|
|
@ -466,17 +464,16 @@ void ContentLoader::reloadScript(const Content& content, ItemDef& item) {
|
||||||
load_script(content, item);
|
load_script(content, item);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContentLoader::loadMainScript(ContentPackRuntime& runtime) {
|
void ContentLoader::loadContentScript(ContentPackRuntime& runtime) {
|
||||||
const auto& pack = runtime.getInfo();
|
const auto& pack = runtime.getInfo();
|
||||||
const auto& folder = pack.folder;
|
const auto& folder = pack.folder;
|
||||||
io::path scriptFile = folder / "scripts/main.lua";
|
io::path scriptFile = folder / "scripts/content.lua";
|
||||||
if (io::is_regular_file(scriptFile)) {
|
if (io::is_regular_file(scriptFile)) {
|
||||||
scripting::load_main_script(
|
scripting::load_content_script(
|
||||||
runtime.getEnvironment(),
|
runtime.getEnvironment(),
|
||||||
pack.id,
|
pack.id,
|
||||||
scriptFile,
|
scriptFile,
|
||||||
pack.id + ":scripts/main.lua",
|
pack.id + ":scripts/content.lua"
|
||||||
runtime.mainfuncsset
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@ public:
|
||||||
void load();
|
void load();
|
||||||
|
|
||||||
static void loadScripts(Content& content);
|
static void loadScripts(Content& content);
|
||||||
static void loadMainScript(ContentPackRuntime& pack);
|
static void loadContentScript(ContentPackRuntime& pack);
|
||||||
static void loadWorldScript(ContentPackRuntime& pack);
|
static void loadWorldScript(ContentPackRuntime& pack);
|
||||||
static void reloadScript(const Content& content, Block& block);
|
static void reloadScript(const Content& content, Block& block);
|
||||||
static void reloadScript(const Content& content, ItemDef& item);
|
static void reloadScript(const Content& content, ItemDef& item);
|
||||||
|
|
|
||||||
|
|
@ -129,19 +129,12 @@ struct WorldFuncsSet {
|
||||||
bool oninventoryclosed;
|
bool oninventoryclosed;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct MainFuncsSet {
|
|
||||||
bool oncontentinitialization;
|
|
||||||
bool onscriptsloading;
|
|
||||||
bool oncontentloaded;
|
|
||||||
};
|
|
||||||
|
|
||||||
class ContentPackRuntime {
|
class ContentPackRuntime {
|
||||||
ContentPack info;
|
ContentPack info;
|
||||||
ContentPackStats stats {};
|
ContentPackStats stats {};
|
||||||
scriptenv env;
|
scriptenv env;
|
||||||
public:
|
public:
|
||||||
WorldFuncsSet worldfuncsset {};
|
WorldFuncsSet worldfuncsset {};
|
||||||
MainFuncsSet mainfuncsset {};
|
|
||||||
|
|
||||||
ContentPackRuntime(ContentPack info, scriptenv env);
|
ContentPackRuntime(ContentPack info, scriptenv env);
|
||||||
~ContentPackRuntime();
|
~ContentPackRuntime();
|
||||||
|
|
|
||||||
|
|
@ -627,16 +627,6 @@ void scripting::on_ui_close(UiDocument* layout, Inventory* inventory) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void scripting::on_content_initialization() {
|
|
||||||
auto L = lua::get_main_state();
|
|
||||||
|
|
||||||
for (auto& pack : content_control->getAllContentPacks()) {
|
|
||||||
lua::emit_event(L, pack.id + ":.oncontentinitialization", [](auto L) {
|
|
||||||
return 0;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void scripting::on_scripts_loading() {
|
void scripting::on_scripts_loading() {
|
||||||
auto L = lua::get_main_state();
|
auto L = lua::get_main_state();
|
||||||
|
|
||||||
|
|
@ -793,17 +783,15 @@ void scripting::load_world_script(
|
||||||
register_event(env, "on_inventory_closed", prefix + ":.inventoryclosed");
|
register_event(env, "on_inventory_closed", prefix + ":.inventoryclosed");
|
||||||
}
|
}
|
||||||
|
|
||||||
void scripting::load_main_script(
|
void scripting::load_content_script(
|
||||||
const scriptenv& senv,
|
const scriptenv& senv,
|
||||||
const std::string& prefix,
|
const std::string& prefix,
|
||||||
const io::path& file,
|
const io::path& file,
|
||||||
const std::string& fileName,
|
const std::string& fileName
|
||||||
MainFuncsSet& funcsset
|
|
||||||
) {
|
) {
|
||||||
int env = *senv;
|
int env = *senv;
|
||||||
lua::pop(lua::get_main_state(), load_script(env, "main", file, fileName));
|
lua::pop(lua::get_main_state(), load_script(env, "content", file, fileName));
|
||||||
|
|
||||||
register_event(env, "on_content_initialization", prefix + ":.oncontentinitialization");
|
|
||||||
register_event(env, "on_scripts_loading", prefix + ":.onscriptsloading");
|
register_event(env, "on_scripts_loading", prefix + ":.onscriptsloading");
|
||||||
register_event(env, "on_content_loaded", prefix + ":.oncontentloaded");
|
register_event(env, "on_content_loaded", prefix + ":.oncontentloaded");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,6 @@ struct BlockFuncNamesCache;
|
||||||
struct ItemFuncsSet;
|
struct ItemFuncsSet;
|
||||||
struct ItemFuncNamesCache;
|
struct ItemFuncNamesCache;
|
||||||
struct WorldFuncsSet;
|
struct WorldFuncsSet;
|
||||||
struct MainFuncsSet;
|
|
||||||
struct UserComponent;
|
struct UserComponent;
|
||||||
struct UiDocScript;
|
struct UiDocScript;
|
||||||
class BlocksController;
|
class BlocksController;
|
||||||
|
|
@ -161,9 +160,6 @@ namespace scripting {
|
||||||
/// @brief Called on UI view close
|
/// @brief Called on UI view close
|
||||||
void on_ui_close(UiDocument* layout, Inventory* inventory);
|
void on_ui_close(UiDocument* layout, Inventory* inventory);
|
||||||
|
|
||||||
/// @brief Called before loading
|
|
||||||
void on_content_initialization();
|
|
||||||
|
|
||||||
/// @brief Called on Content loading
|
/// @brief Called on Content loading
|
||||||
void on_scripts_loading();
|
void on_scripts_loading();
|
||||||
|
|
||||||
|
|
@ -231,12 +227,11 @@ namespace scripting {
|
||||||
WorldFuncsSet& funcsset
|
WorldFuncsSet& funcsset
|
||||||
);
|
);
|
||||||
|
|
||||||
void load_main_script(
|
void load_content_script(
|
||||||
const scriptenv& env,
|
const scriptenv& env,
|
||||||
const std::string& packid,
|
const std::string& packid,
|
||||||
const io::path& file,
|
const io::path& file,
|
||||||
const std::string& fileName,
|
const std::string& fileName
|
||||||
MainFuncsSet& funcsset
|
|
||||||
);
|
);
|
||||||
|
|
||||||
/// @brief Load script associated with an UiDocument
|
/// @brief Load script associated with an UiDocument
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue