feat: world script reloading
This commit is contained in:
@@ -79,6 +79,14 @@ const ContentPackRuntime* Content::getPackRuntime(const std::string& id) const {
|
||||
return found->second.get();
|
||||
}
|
||||
|
||||
ContentPackRuntime* Content::getPackRuntime(const std::string& id) {
|
||||
auto found = packs.find(id);
|
||||
if (found == packs.end()) {
|
||||
return nullptr;
|
||||
}
|
||||
return found->second.get();
|
||||
}
|
||||
|
||||
const UptrsMap<std::string, BlockMaterial>& Content::getBlockMaterials() const {
|
||||
return blockMaterials;
|
||||
}
|
||||
|
||||
@@ -248,6 +248,7 @@ public:
|
||||
const rigging::SkeletonConfig* getSkeleton(const std::string& id) const;
|
||||
const BlockMaterial* findBlockMaterial(const std::string& id) const;
|
||||
const ContentPackRuntime* getPackRuntime(const std::string& id) const;
|
||||
ContentPackRuntime* getPackRuntime(const std::string& id);
|
||||
|
||||
const UptrsMap<std::string, BlockMaterial>& getBlockMaterials() const;
|
||||
const UptrsMap<std::string, ContentPackRuntime>& getPacks() const;
|
||||
|
||||
@@ -889,6 +889,21 @@ void ContentLoader::reloadScript(const Content& content, ItemDef& item) {
|
||||
load_script(content, item);
|
||||
}
|
||||
|
||||
void ContentLoader::loadWorldScript(ContentPackRuntime& runtime) {
|
||||
const auto& pack = runtime.getInfo();
|
||||
const auto& folder = pack.folder;
|
||||
io::path scriptFile = folder / "scripts/world.lua";
|
||||
if (io::is_regular_file(scriptFile)) {
|
||||
scripting::load_world_script(
|
||||
runtime.getEnvironment(),
|
||||
pack.id,
|
||||
scriptFile,
|
||||
pack.id + ":scripts/world.lua",
|
||||
runtime.worldfuncsset
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void ContentLoader::loadScripts(Content& content) {
|
||||
load_scripts(content, content.blocks);
|
||||
load_scripts(content, content.items);
|
||||
@@ -898,16 +913,8 @@ void ContentLoader::loadScripts(Content& content) {
|
||||
const auto& folder = pack.folder;
|
||||
|
||||
// Load main world script
|
||||
io::path scriptFile = folder / "scripts/world.lua";
|
||||
if (io::is_regular_file(scriptFile)) {
|
||||
scripting::load_world_script(
|
||||
runtime->getEnvironment(),
|
||||
pack.id,
|
||||
scriptFile,
|
||||
pack.id + ":scripts/world.lua",
|
||||
runtime->worldfuncsset
|
||||
);
|
||||
}
|
||||
loadWorldScript(*runtime);
|
||||
|
||||
// Load entity components
|
||||
io::path componentsDir = folder / "scripts/components";
|
||||
foreach_file(componentsDir, [&pack](const io::path& file) {
|
||||
|
||||
@@ -77,6 +77,7 @@ public:
|
||||
void load();
|
||||
|
||||
static void loadScripts(Content& content);
|
||||
static void loadWorldScript(ContentPackRuntime& pack);
|
||||
static void reloadScript(const Content& content, Block& block);
|
||||
static void reloadScript(const Content& content, ItemDef& item);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user