Class: GameEcs::Condition
- Inherits:
-
Object
- Object
- GameEcs::Condition
- Defined in:
- lib/game_ecs/entity_store.rb
Instance Attribute Summary collapse
-
#attr_conditions ⇒ Object
readonly
Returns the value of attribute attr_conditions.
-
#k ⇒ Object
readonly
Returns the value of attribute k.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #attrs_match?(id, comps) ⇒ Boolean
- #components ⇒ Object
- #hash ⇒ Object
-
#initialize(k) ⇒ Condition
constructor
A new instance of Condition.
- #merge_conditions(attrs) ⇒ Object
Constructor Details
#initialize(k) ⇒ Condition
Returns a new instance of Condition.
360 361 362 363 |
# File 'lib/game_ecs/entity_store.rb', line 360 def initialize(k) @attr_conditions = {} @k = k end |
Instance Attribute Details
#attr_conditions ⇒ Object (readonly)
Returns the value of attribute attr_conditions.
359 360 361 |
# File 'lib/game_ecs/entity_store.rb', line 359 def attr_conditions @attr_conditions end |
#k ⇒ Object (readonly)
Returns the value of attribute k.
359 360 361 |
# File 'lib/game_ecs/entity_store.rb', line 359 def k @k end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
365 366 367 368 369 |
# File 'lib/game_ecs/entity_store.rb', line 365 def ==(other) @k == other.k && @attr_conditions.size == other.attr_conditions.size && @attr_conditions.all?{|ac,v| other.attr_conditions[ac] == v} end |
#attrs_match?(id, comps) ⇒ Boolean
379 380 381 382 383 384 385 386 387 388 389 |
# File 'lib/game_ecs/entity_store.rb', line 379 def attrs_match?(id, comps) comp = comps[@k] @attr_conditions.all? do |name, cond| val = comp.send(name) if cond.respond_to? :call cond.call val else val == cond end end end |
#components ⇒ Object
375 376 377 |
# File 'lib/game_ecs/entity_store.rb', line 375 def components @k end |
#hash ⇒ Object
371 372 373 |
# File 'lib/game_ecs/entity_store.rb', line 371 def hash @_hash ||= @k.hash ^ @attr_conditions.hash end |
#merge_conditions(attrs) ⇒ Object
391 392 393 394 |
# File 'lib/game_ecs/entity_store.rb', line 391 def merge_conditions(attrs) @attr_conditions ||= {} @attr_conditions.merge! attrs end |