mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-08 20:41:49 +00:00
Added script-listener to packs loading
This commit is contained in:
parent
b5f5aeb5c6
commit
61625ffe00
5 changed files with 92 additions and 1 deletions
|
|
@ -334,12 +334,16 @@ void ContentLoader::load() {
|
|||
|
||||
fixPackIndices();
|
||||
|
||||
loadMainScript(*runtime);
|
||||
|
||||
auto folder = pack->folder;
|
||||
|
||||
builder.defaults = paths.readCombinedObject(
|
||||
EnginePaths::CONFIG_DEFAULTS.string()
|
||||
);
|
||||
|
||||
scripting::on_content_initialization();
|
||||
|
||||
// Load world generators
|
||||
io::path generatorsDir = folder / "generators";
|
||||
foreach_file(generatorsDir, [this](const io::path& file) {
|
||||
|
|
@ -462,6 +466,21 @@ void ContentLoader::reloadScript(const Content& content, ItemDef& item) {
|
|||
load_script(content, item);
|
||||
}
|
||||
|
||||
void ContentLoader::loadMainScript(ContentPackRuntime& runtime) {
|
||||
const auto& pack = runtime.getInfo();
|
||||
const auto& folder = pack.folder;
|
||||
io::path scriptFile = folder / "scripts/main.lua";
|
||||
if (io::is_regular_file(scriptFile)) {
|
||||
scripting::load_main_script(
|
||||
runtime.getEnvironment(),
|
||||
pack.id,
|
||||
scriptFile,
|
||||
pack.id + ":scripts/main.lua",
|
||||
runtime.mainfuncsset
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void ContentLoader::loadWorldScript(ContentPackRuntime& runtime) {
|
||||
const auto& pack = runtime.getInfo();
|
||||
const auto& folder = pack.folder;
|
||||
|
|
@ -478,6 +497,7 @@ void ContentLoader::loadWorldScript(ContentPackRuntime& runtime) {
|
|||
}
|
||||
|
||||
void ContentLoader::loadScripts(Content& content) {
|
||||
scripting::on_content_loading();
|
||||
load_scripts(content, content.blocks);
|
||||
load_scripts(content, content.items);
|
||||
|
||||
|
|
@ -486,7 +506,7 @@ void ContentLoader::loadScripts(Content& content) {
|
|||
const auto& pack = runtime->getInfo();
|
||||
const auto& folder = pack.folder;
|
||||
|
||||
// Load main world script
|
||||
// Load world script
|
||||
loadWorldScript(*runtime);
|
||||
|
||||
// Load entity components
|
||||
|
|
@ -501,6 +521,8 @@ void ContentLoader::loadScripts(Content& content) {
|
|||
);
|
||||
});
|
||||
}
|
||||
|
||||
scripting::on_content_loaded();
|
||||
}
|
||||
|
||||
void ContentLoader::loadResources(ResourceType type, const dv::value& list) {
|
||||
|
|
|
|||
|
|
@ -58,6 +58,7 @@ public:
|
|||
void load();
|
||||
|
||||
static void loadScripts(Content& content);
|
||||
static void loadMainScript(ContentPackRuntime& pack);
|
||||
static void loadWorldScript(ContentPackRuntime& pack);
|
||||
static void reloadScript(const Content& content, Block& block);
|
||||
static void reloadScript(const Content& content, ItemDef& item);
|
||||
|
|
|
|||
|
|
@ -129,12 +129,17 @@ struct WorldFuncsSet {
|
|||
bool oninventoryclosed;
|
||||
};
|
||||
|
||||
struct MainFuncsSet {
|
||||
bool oncontentloading;
|
||||
};
|
||||
|
||||
class ContentPackRuntime {
|
||||
ContentPack info;
|
||||
ContentPackStats stats {};
|
||||
scriptenv env;
|
||||
public:
|
||||
WorldFuncsSet worldfuncsset {};
|
||||
MainFuncsSet mainfuncsset {};
|
||||
|
||||
ContentPackRuntime(ContentPack info, scriptenv env);
|
||||
~ContentPackRuntime();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue