diff --git a/spec/entitas/events_spec.cr b/spec/entitas/events_spec.cr index cdfd9c2..c8cb89f 100644 --- a/spec/entitas/events_spec.cr +++ b/spec/entitas/events_spec.cr @@ -23,7 +23,7 @@ private class RemoveEventTest property listener : Test4Entity property contexts : Contexts - property remove_comp_when_empty : Bool + property? remove_comp_when_empty : Bool property value : String? = nil def initialize(@contexts, @remove_comp_when_empty) @@ -37,13 +37,13 @@ private class RemoveEventTest def on_standard_event(entity, component : StandardEvent) # logger.warn { "on_standard_event" } - @listener.remove_any_standard_event_listener(self, remove_comp_when_empty) + @listener.remove_any_standard_event_listener(self, remove_comp_when_empty?) @value = component.value end def on_flag_entity_event(entity, component : FlagEntityEvent) # logger.warn { "on_flag_entity_event" } - listener.remove_flag_entity_event_listener(self, remove_comp_when_empty) + listener.remove_flag_entity_event_listener(self, remove_comp_when_empty?) @value = "true" end end diff --git a/src/entitas/collector.cr b/src/entitas/collector.cr index d012bbc..436730e 100644 --- a/src/entitas/collector.cr +++ b/src/entitas/collector.cr @@ -91,7 +91,7 @@ module Entitas self.entities.size end - def each + def each(& : TEntity ->) self.entities.each do |entity| yield entity end diff --git a/src/entitas/contexts.cr b/src/entitas/contexts.cr index 2ed3bdd..1215dcb 100644 --- a/src/entitas/contexts.cr +++ b/src/entitas/contexts.cr @@ -23,7 +23,7 @@ class Entitas::Contexts self.all_contexts.each &.reset end - def each + def each(& : Entitas::IContext? ->) self.all_contexts.each do |ctx| yield ctx end diff --git a/src/entitas/controller.cr b/src/entitas/controller.cr index 7db235b..d21ad3a 100644 --- a/src/entitas/controller.cr +++ b/src/entitas/controller.cr @@ -12,7 +12,7 @@ module Entitas # Will allow you to interact with the returned `Contexts` with a `Mutex` lock # preventing `#update` from being called in another thread - def with_contexts + def with_contexts(& : Entitas::Contexts ->) self.synchronize do yield self.contexts end @@ -23,10 +23,11 @@ module Entitas end def find_systems(klass : Class) : Array(Entitas::System) - if self.systems.nil? + sys = self.systems + if sys.nil? Array(Entitas::System).new else - self.systems.not_nil!.find_systems(klass) + sys.find_systems(klass) end end diff --git a/src/entitas/interfaces/i_component.cr b/src/entitas/interfaces/i_component.cr index 4c1be33..e5ba8c8 100644 --- a/src/entitas/interfaces/i_component.cr +++ b/src/entitas/interfaces/i_component.cr @@ -2,7 +2,7 @@ module Entitas::IComponent Log = ::Log.for(self) # Will return true if the class is a unique component for a context - abstract def is_unique? : Bool + abstract def unique? : Bool abstract def init(**args) abstract def reset diff --git a/src/entitas/macros/component.cr b/src/entitas/macros/component.cr index 250c9bd..a7b8cbf 100644 --- a/src/entitas/macros/component.cr +++ b/src/entitas/macros/component.cr @@ -133,7 +133,7 @@ module Entitas::IComponent def to_json(json : JSON::Builder) json.object do json.field "name", {{@type.id.stringify}} - json.field "unique", is_unique? + json.field "unique", unique? json.field("data") do json.object do {% for var_name in comp_variables.keys %} @@ -206,31 +206,31 @@ module Entitas::IComponent # :nodoc: macro setup_unique - {% is_unique = @type.annotation(::Component::Unique) ? true : false %} + {% unique = @type.annotation(::Component::Unique) ? true : false %} - {% if flag?(:entitas_debug_generator) %}{% puts " - setup_unique for #{@type.id} : #{is_unique}" %}{% end %} + {% if flag?(:entitas_debug_generator) %}{% puts " - setup_unique for #{@type.id} : #{unique}" %}{% end %} # If the component has the unique annotation, # set the class method to `true` # The framework will make sure that only one instance of a unique component can be present in your context - {% if is_unique %} + {% if unique %} # Will return true if the class is a unique component for a context - def is_unique? : Bool + def unique? : Bool true end # :ditto: - def self.is_unique? : Bool + def self.unique? : Bool true end {% else %} # Will return true if the class is a unique component for a context - def is_unique? : Bool + def unique? : Bool false end # :ditto: - def self.is_unique? : Bool + def self.unique? : Bool false end {% end %} diff --git a/src/entitas/macros/events.cr b/src/entitas/macros/events.cr index a87fabc..eedbe80 100644 --- a/src/entitas/macros/events.cr +++ b/src/entitas/macros/events.cr @@ -254,7 +254,7 @@ macro component_event(contexts, comp, target, _type = EventType::Added, priority end def remove_{{listener_component_meth_name.id}}(value : {{listener_module.id}}, remove_comp_when_empty = false) - {% if flag?(:entitas_enable_logging) %}Log.debug { "remove_{{listener_component_meth_name.id}} - remove_comp_when_empty: #{remove_comp_when_empty}, value: #{value}" }{% end %} + {% if flag?(:entitas_enable_logging) %}Log.debug { "remove_{{listener_component_meth_name.id}} - remove_comp_when_empty: #{remove_comp_when_empty?}, value: #{value}" }{% end %} %listeners = self.{{listener_component_meth_name.id}}.value %listeners.delete(value) if(remove_comp_when_empty && %listeners.empty?) diff --git a/src/entitas/multi_reactive_system.cr b/src/entitas/multi_reactive_system.cr index 1f41e57..c759724 100644 --- a/src/entitas/multi_reactive_system.cr +++ b/src/entitas/multi_reactive_system.cr @@ -15,7 +15,7 @@ module Entitas private property collected_buffer : Array(IEntity) = Array(IEntity).new private property buffer : Array(IEntity) = Array(IEntity).new private property to_string_cache : String? = nil - protected property _filter : Proc(IEntity, Bool) = ->(entity : IEntity) { true } + protected property _filter : Proc(IEntity, Bool) = ->(_entity : IEntity) { true } def initialize(@collectors : Array(ICollector)); end diff --git a/src/entitas/reactive_system.cr b/src/entitas/reactive_system.cr index f3a8e4e..da07f65 100644 --- a/src/entitas/reactive_system.cr +++ b/src/entitas/reactive_system.cr @@ -14,7 +14,7 @@ module Entitas private getter collector : ICollector private property buffer : Array(Entitas::IEntity) = Array(Entitas::IEntity).new private property to_string_cache : String? = nil - protected property _filter : Proc(Entitas::IEntity, Bool) = ->(entity : Entitas::IEntity) { true } + protected property _filter : Proc(Entitas::IEntity, Bool) = ->(_entity : Entitas::IEntity) { true } def initialize(@collector : ICollector); end