Skip to content

Commit

Permalink
ameba fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kalinon committed Dec 16, 2024
1 parent e998a7e commit 8450138
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 20 deletions.
6 changes: 3 additions & 3 deletions spec/entitas/events_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/entitas/collector.cr
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ module Entitas
self.entities.size
end

def each
def each(& : TEntity ->)
self.entities.each do |entity|
yield entity
end
Expand Down
2 changes: 1 addition & 1 deletion src/entitas/contexts.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions src/entitas/controller.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/entitas/interfaces/i_component.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 8 additions & 8 deletions src/entitas/macros/component.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Expand Down Expand Up @@ -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 %}
Expand Down
2 changes: 1 addition & 1 deletion src/entitas/macros/events.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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?)
Expand Down
2 changes: 1 addition & 1 deletion src/entitas/multi_reactive_system.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/entitas/reactive_system.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 8450138

Please sign in to comment.