Class: GameEcs::Query
- Inherits:
-
Object
- Object
- GameEcs::Query
- Defined in:
- lib/game_ecs/entity_store.rb
Instance Attribute Summary collapse
-
#components ⇒ Object
readonly
Returns the value of attribute components.
-
#maybes ⇒ Object
readonly
Returns the value of attribute maybes.
-
#musts ⇒ Object
readonly
Returns the value of attribute musts.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #cacheable? ⇒ Boolean
- #hash ⇒ Object
-
#initialize ⇒ Query
constructor
A new instance of Query.
- #matches?(eid, comps) ⇒ Boolean
- #maybe(k) ⇒ Object
- #must(k) ⇒ Object
- #required_components ⇒ Object
- #with(attr_map) ⇒ Object
Constructor Details
#initialize ⇒ Query
Returns a new instance of Query.
422 423 424 425 |
# File 'lib/game_ecs/entity_store.rb', line 422 def initialize @components = [] @musts = [] end |
Instance Attribute Details
#components ⇒ Object (readonly)
Returns the value of attribute components.
411 412 413 |
# File 'lib/game_ecs/entity_store.rb', line 411 def components @components end |
#maybes ⇒ Object (readonly)
Returns the value of attribute maybes.
411 412 413 |
# File 'lib/game_ecs/entity_store.rb', line 411 def maybes @maybes end |
#musts ⇒ Object (readonly)
Returns the value of attribute musts.
411 412 413 |
# File 'lib/game_ecs/entity_store.rb', line 411 def musts @musts end |
Class Method Details
.maybe(*args) ⇒ Object
418 419 420 |
# File 'lib/game_ecs/entity_store.rb', line 418 def self.maybe(*args) Query.new.maybe(*args) end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
455 456 457 |
# File 'lib/game_ecs/entity_store.rb', line 455 def ==(other) self.musts == other.musts && self.maybes == other.maybes end |
#cacheable? ⇒ Boolean
459 460 461 |
# File 'lib/game_ecs/entity_store.rb', line 459 def cacheable? @cacheable ||= @musts.all?{|m| m.attr_conditions.values.all?{|ac| !ac.respond_to?(:call) } } end |
#hash ⇒ Object
464 465 466 |
# File 'lib/game_ecs/entity_store.rb', line 464 def hash @_hash ||= self.musts.hash ^ self.maybes.hash end |
#matches?(eid, comps) ⇒ Boolean
451 452 453 |
# File 'lib/game_ecs/entity_store.rb', line 451 def matches?(eid, comps) @musts.all?{|m| m.matches?(eid, comps)} # ignore maybes ;) end |
#maybe(k) ⇒ Object
443 444 445 446 447 448 449 |
# File 'lib/game_ecs/entity_store.rb', line 443 def maybe(k) @maybes ||= [] @last_condition = Maybe.new(k) @maybes << @last_condition @components << k self end |
#must(k) ⇒ Object
427 428 429 430 431 432 |
# File 'lib/game_ecs/entity_store.rb', line 427 def must(k) @last_condition = Must.new(k) @musts << @last_condition @components << k self end |
#required_components ⇒ Object
434 435 436 |
# File 'lib/game_ecs/entity_store.rb', line 434 def required_components @musts.flat_map(&:components).uniq end |
#with(attr_map) ⇒ Object
438 439 440 441 |
# File 'lib/game_ecs/entity_store.rb', line 438 def with(attr_map) @last_condition.merge_conditions(attr_map) self end |