add entity:set_enabled(...)

This commit is contained in:
MihailRis
2025-01-21 05:31:07 +03:00
parent 13fde2116d
commit f2101f6504
6 changed files with 32 additions and 3 deletions
+18 -2
View File
@@ -68,6 +68,22 @@ local Entity = {__index={
def_index=function(self) return entities.get_def(self.eid) end,
def_name=function(self) return entities.def_name(entities.get_def(self.eid)) end,
get_player=function(self) return entities.get_player(self.eid) end,
set_enabled=function(self, name, flag)
local comp = self.components[name]
if comp then
if flag then
if comp.__disabled and comp.on_enable then
comp.on_enable()
end
comp.__disabled = nil
else
if not comp.__disabled and comp.on_disable then
comp.on_disable()
end
comp.__disabled = true
end
end
end,
}}
local entities = {}
@@ -99,7 +115,7 @@ return {
end
for _, component in pairs(entity.components) do
local callback = component.on_update
if callback then
if not component.__disabled and callback then
local result, err = pcall(callback, tps)
if err then
debug.error(err)
@@ -113,7 +129,7 @@ return {
for _,entity in pairs(entities) do
for _, component in pairs(entity.components) do
local callback = component.on_render
if callback then
if not component.__disabled and callback then
local result, err = pcall(callback, delta)
if err then
debug.error(err)