reduce redundancy
This commit is contained in:
@@ -359,7 +359,7 @@ void ContentLoader::loadEntity(EntityDef& def, const std::string& full, const st
|
|||||||
for (auto& componentName : def.components) {
|
for (auto& componentName : def.components) {
|
||||||
auto scriptfile = folder/fs::path("scripts/components/"+componentName+".lua");
|
auto scriptfile = folder/fs::path("scripts/components/"+componentName+".lua");
|
||||||
if (fs::is_regular_file(scriptfile)) {
|
if (fs::is_regular_file(scriptfile)) {
|
||||||
scripting::load_entity_component(env, componentName, scriptfile);
|
scripting::load_entity_component(componentName, scriptfile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -514,11 +514,11 @@ void scripting::load_item_script(const scriptenv& senv, const std::string& prefi
|
|||||||
funcsset.on_block_break_by = register_event(env, "on_block_break_by", prefix+".blockbreakby");
|
funcsset.on_block_break_by = register_event(env, "on_block_break_by", prefix+".blockbreakby");
|
||||||
}
|
}
|
||||||
|
|
||||||
void scripting::load_entity_component(const scriptenv& penv, const std::string& name, const fs::path& file) {
|
void scripting::load_entity_component(const std::string& name, const fs::path& file) {
|
||||||
auto L = lua::get_main_thread();
|
auto L = lua::get_main_thread();
|
||||||
std::string src = files::read_string(file);
|
std::string src = files::read_string(file);
|
||||||
logger.info() << "script (component) " << file.u8string();
|
logger.info() << "script (component) " << file.u8string();
|
||||||
lua::loadbuffer(L, *penv, src, file.u8string());
|
lua::loadbuffer(L, 0, src, file.u8string());
|
||||||
lua::store_in(L, lua::CHUNKS_TABLE, name);
|
lua::store_in(L, lua::CHUNKS_TABLE, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -127,7 +127,6 @@ namespace scripting {
|
|||||||
item_funcs_set& funcsset);
|
item_funcs_set& funcsset);
|
||||||
|
|
||||||
void load_entity_component(
|
void load_entity_component(
|
||||||
const scriptenv& env,
|
|
||||||
const std::string& name,
|
const std::string& name,
|
||||||
const fs::path& file);
|
const fs::path& file);
|
||||||
|
|
||||||
|
|||||||
@@ -405,8 +405,8 @@ void Entities::render(Assets* assets, ModelBatch& batch, const Frustum& frustum,
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool Entities::hasBlockingInside(AABB aabb) {
|
bool Entities::hasBlockingInside(AABB aabb) {
|
||||||
auto view = registry.view<EntityId, Transform, Rigidbody>();
|
auto view = registry.view<EntityId, Rigidbody>();
|
||||||
for (auto [entity, eid, transform, body] : view.each()) {
|
for (auto [entity, eid, body] : view.each()) {
|
||||||
if (eid.def.blocking && aabb.intersect(body.hitbox.getAABB())) {
|
if (eid.def.blocking && aabb.intersect(body.hitbox.getAABB())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user