update components loading scheme

This commit is contained in:
MihailRis 2024-07-10 07:15:07 +03:00
parent 8edf9440a3
commit 0ebc3da7f6
3 changed files with 14 additions and 9 deletions

View File

@ -1,6 +1,6 @@
{
"components": [
"drop"
"base:drop"
],
"hitbox": [0.4, 0.25, 0.4],
"sensors": [

View File

@ -1,6 +1,6 @@
{
"components": [
"falling_block"
"base:falling_block"
],
"skeleton-name": "base:block",
"hitbox": [0.8, 0.8, 0.8]

View File

@ -355,13 +355,6 @@ void ContentLoader::loadEntity(EntityDef& def, const std::string& full, const st
auto folder = pack->folder;
auto configFile = folder/fs::path("entities/"+name+".json");
if (fs::exists(configFile)) loadEntity(def, full, configFile);
for (auto& componentName : def.components) {
auto scriptfile = folder/fs::path("scripts/components/"+componentName+".lua");
if (fs::is_regular_file(scriptfile)) {
scripting::load_entity_component(componentName, scriptfile);
}
}
}
void ContentLoader::loadBlock(Block& def, const std::string& full, const std::string& name) {
@ -478,4 +471,16 @@ void ContentLoader::load() {
builder.add(rigging::SkeletonConfig::parse(text, file.u8string(), name));
}
}
fs::path componentsDir = folder / fs::u8path("scripts/components");
if (fs::is_directory(componentsDir)) {
for (const auto& entry : fs::directory_iterator(componentsDir)) {
fs::path scriptfile = entry.path();
if (fs::is_regular_file(scriptfile)) {
auto name = pack->id+":"+scriptfile.stem().u8string();
std::cout << name << std::endl;
scripting::load_entity_component(name, scriptfile);
}
}
}
}