add on_update event

This commit is contained in:
MihailRis
2024-06-29 22:19:42 +03:00
parent bb1c0b4b44
commit 982c8b132d
7 changed files with 41 additions and 10 deletions
+10 -3
View File
@@ -114,8 +114,9 @@ static scriptenv create_entity_environment(const scriptenv& parent, int entityId
lua::pushvalue(L, -2);
lua::setfield(L, "entity");
lua::pop(L, 2);
lua::setfield(L, "env");
lua::pop(L);
return std::shared_ptr<int>(new int(id), [=](int* id) {
lua::removeEnvironment(L, *id);
@@ -307,12 +308,18 @@ bool scripting::on_entity_despawn(const EntityDef& def, const Entity& entity) {
bool scripting::on_entity_grounded(const EntityDef& def, const Entity& entity) {
const auto& script = entity.getScripting();
if (script.funcsset.on_despawn) {
if (script.funcsset.on_grounded) {
return process_entity_callback(script.env, "on_grounded", nullptr);
}
return true;
}
void scripting::on_entities_update() {
auto L = lua::get_main_thread();
lua::get_from(L, STDCOMP, "update", true);
lua::call_nothrow(L, 0, 0);
}
void scripting::on_ui_open(
UiDocument* layout,
std::vector<dynamic::Value> args
+1
View File
@@ -79,6 +79,7 @@ namespace scripting {
scriptenv on_entity_spawn(const EntityDef& def, entityid_t eid, entity_funcs_set&);
bool on_entity_despawn(const EntityDef& def, const Entity& entity);
bool on_entity_grounded(const EntityDef& def, const Entity& entity);
void on_entities_update();
/// @brief Called on UI view show
void on_ui_open(