class GameEcs::Query

Attributes

components[R]
maybes[R]
musts[R]

Public Class Methods

maybe(*args) click to toggle source
# File lib/game_ecs/entity_store.rb, line 418
def self.maybe(*args)
  Query.new.maybe(*args)
end
must(*args) click to toggle source
# File lib/game_ecs/entity_store.rb, line 415
def self.must(*args)
  Query.new.must(*args)
end
new() click to toggle source
# File lib/game_ecs/entity_store.rb, line 422
def initialize
  @components = []
  @musts = []
end
none() click to toggle source
# File lib/game_ecs/entity_store.rb, line 412
def self.none
  Query.new
end

Public Instance Methods

==(other) click to toggle source
# File lib/game_ecs/entity_store.rb, line 455
def ==(other)
  self.musts == other.musts && self.maybes == other.maybes
end
Also aliased as: eql?
cacheable?() click to toggle source
# 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
eql?(other)
Alias for: ==
hash() click to toggle source
# File lib/game_ecs/entity_store.rb, line 464
def hash
  @_hash ||= self.musts.hash ^ self.maybes.hash
end
matches?(eid, comps) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# File lib/game_ecs/entity_store.rb, line 434
def required_components
  @musts.flat_map(&:components).uniq
end
with(attr_map) click to toggle source
# File lib/game_ecs/entity_store.rb, line 438
def with(attr_map)
  @last_condition.merge_conditions(attr_map)
  self
end