update component parent environment to the pack environment
This commit is contained in:
@@ -380,25 +380,6 @@ void ContentLoader::loadBlockMaterial(BlockMaterial& def, const fs::path& file)
|
|||||||
root->str("break-sound", def.breakSound);
|
root->str("break-sound", def.breakSound);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T, void(ContentLoader::*loadfunc)(T&, const std::string&, const std::string&)>
|
|
||||||
static void load_defs(ContentLoader* cl, dynamic::List* arr, const ContentPack* pack, ContentUnitBuilder<T>& builder, size_t& counter) {
|
|
||||||
if (arr == nullptr) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (size_t i = 0; i < arr->size(); i++) {
|
|
||||||
std::string name = arr->str(i);
|
|
||||||
auto colon = name.find(':');
|
|
||||||
std::string full = colon == std::string::npos ? pack->id + ":" + name : name;
|
|
||||||
if (colon != std::string::npos) name[colon] = '/';
|
|
||||||
auto& def = builder.create(full);
|
|
||||||
if (colon != std::string::npos) {
|
|
||||||
def.scriptName = name.substr(0, colon) + '/' + def.scriptName;
|
|
||||||
}
|
|
||||||
cl->*loadfunc(def, full, name);
|
|
||||||
counter++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ContentLoader::load() {
|
void ContentLoader::load() {
|
||||||
logger.info() << "loading pack [" << pack->id << "]";
|
logger.info() << "loading pack [" << pack->id << "]";
|
||||||
|
|
||||||
|
|||||||
@@ -451,7 +451,7 @@ void scripting::load_entity_component(const scriptenv& penv, const EntityDef& de
|
|||||||
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, 0, src, file.u8string());
|
lua::loadbuffer(L, *penv, src, file.u8string());
|
||||||
lua::store_in(L, lua::CHUNKS_TABLE, def.scriptName);
|
lua::store_in(L, lua::CHUNKS_TABLE, def.scriptName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+19
-12
@@ -53,20 +53,27 @@ entityid_t Entities::spawn(
|
|||||||
auto& body = registry.emplace<Rigidbody>(
|
auto& body = registry.emplace<Rigidbody>(
|
||||||
entity, true, Hitbox {pos, def.hitbox}, std::vector<Trigger>{});
|
entity, true, Hitbox {pos, def.hitbox}, std::vector<Trigger>{});
|
||||||
for (auto& box : def.triggers) {
|
for (auto& box : def.triggers) {
|
||||||
body.triggers.emplace_back(Trigger{true, id, box, AABB{}, {}, {},
|
body.triggers.emplace_back(Trigger{
|
||||||
[=](auto entityid, auto index, auto otherid) {
|
true,
|
||||||
if (auto entity = get(entityid)) {
|
id,
|
||||||
if (entity->isValid()) {
|
box,
|
||||||
scripting::on_trigger_enter(*entity, index, otherid);
|
AABB{},
|
||||||
|
{},
|
||||||
|
{},
|
||||||
|
[=](auto entityid, auto index, auto otherid) {
|
||||||
|
if (auto entity = get(entityid)) {
|
||||||
|
if (entity->isValid()) {
|
||||||
|
scripting::on_trigger_enter(*entity, index, otherid);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
}, [=](auto entityid, auto index, auto otherid) {
|
[=](auto entityid, auto index, auto otherid) {
|
||||||
if (auto entity = get(entityid)) {
|
if (auto entity = get(entityid)) {
|
||||||
if (entity->isValid()) {
|
if (entity->isValid()) {
|
||||||
scripting::on_trigger_exit(*entity, index, otherid);
|
scripting::on_trigger_exit(*entity, index, otherid);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}});
|
||||||
}});
|
|
||||||
}
|
}
|
||||||
auto& scripting = registry.emplace<Scripting>(
|
auto& scripting = registry.emplace<Scripting>(
|
||||||
entity, entity_funcs_set {}, nullptr);
|
entity, entity_funcs_set {}, nullptr);
|
||||||
|
|||||||
@@ -73,6 +73,13 @@ namespace rigging {
|
|||||||
class RigConfig {
|
class RigConfig {
|
||||||
std::unique_ptr<RigNode> root;
|
std::unique_ptr<RigNode> root;
|
||||||
std::unordered_map<std::string, size_t> indices;
|
std::unordered_map<std::string, size_t> indices;
|
||||||
|
|
||||||
|
/// Nodes and indices are ordered from root to subnodes.
|
||||||
|
/// Example:
|
||||||
|
/// 0 - root
|
||||||
|
/// 1 --- sub1
|
||||||
|
/// 2 ----- subsub1
|
||||||
|
/// 3 --- sub2
|
||||||
std::vector<RigNode*> nodes;
|
std::vector<RigNode*> nodes;
|
||||||
|
|
||||||
size_t update(
|
size_t update(
|
||||||
|
|||||||
Reference in New Issue
Block a user