add entity:set_enabled(...)
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user