add entity:set_enabled(...)
This commit is contained in:
parent
13fde2116d
commit
f2101f6504
@ -18,7 +18,7 @@ Creates a rule. If a handler is specified, returns the id for deletion.
|
||||
> Rules that have not been created can be used, but resetting via rules.reset will result in setting the value to nil.
|
||||
|
||||
```lua
|
||||
rules.listen(
|
||||
rules.listen(
|
||||
-- rule name
|
||||
name: str,
|
||||
-- value change handler function
|
||||
|
||||
@ -26,6 +26,9 @@ entity:get_uid() -> int
|
||||
entity:get_component(name: str) -> component or nil
|
||||
-- Checks for the presence of a component by name
|
||||
entity:has_component(name: str) -> bool
|
||||
|
||||
-- Enables/disables the component
|
||||
entity:set_enabled(name: str, enable: bool)
|
||||
```
|
||||
|
||||
## Built-in components
|
||||
|
||||
@ -26,6 +26,9 @@ entity:get_uid() -> int
|
||||
entity:get_component(name: str) -> компонент или nil
|
||||
-- Проверяет наличие компонента по имени
|
||||
entity:has_component(name: str) -> bool
|
||||
|
||||
-- Включает/выключает компонент по имени
|
||||
entity:set_enabled(name: str, enable: bool)
|
||||
```
|
||||
|
||||
## Встроенные компоненты
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -104,6 +104,9 @@ namespace dv {
|
||||
}
|
||||
|
||||
boolean_t value::asBoolean() const {
|
||||
if (type == value_type::none) {
|
||||
return false;
|
||||
}
|
||||
check_type(type, value_type::boolean);
|
||||
return val.boolean;
|
||||
}
|
||||
|
||||
@ -614,6 +614,10 @@ static void process_entity_callback(
|
||||
) {
|
||||
auto L = lua::get_main_state();
|
||||
lua::pushenv(L, *env);
|
||||
if (lua::hasfield(L, "__disabled")) {
|
||||
lua::pop(L);
|
||||
return;
|
||||
}
|
||||
if (lua::getfield(L, name)) {
|
||||
if (args) {
|
||||
lua::call_nothrow(L, args(L), 0);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user