Class: GameEcs::EntityStore::QueryResultSet
- Inherits:
-
Object
- Object
- GameEcs::EntityStore::QueryResultSet
- Extended by:
- Forwardable
- Defined in:
- lib/game_ecs/entity_store.rb
Instance Method Summary collapse
- #<<(rec) ⇒ Object
- #add_component(id:, component:) ⇒ Object
- #delete(id: nil, ids: nil) ⇒ Object
- #each ⇒ Object
- #has_id?(id) ⇒ Boolean
-
#initialize(records:, ids:) ⇒ QueryResultSet
constructor
A new instance of QueryResultSet.
Constructor Details
#initialize(records:, ids:) ⇒ QueryResultSet
Returns a new instance of QueryResultSet.
291 292 293 294 |
# File 'lib/game_ecs/entity_store.rb', line 291 def initialize(records:, ids:) @records = records @ids = Set.new(ids) end |
Instance Method Details
#<<(rec) ⇒ Object
295 296 297 298 |
# File 'lib/game_ecs/entity_store.rb', line 295 def <<(rec) @ids << rec.id @records << rec end |
#add_component(id:, component:) ⇒ Object
302 303 304 305 |
# File 'lib/game_ecs/entity_store.rb', line 302 def add_component(id:, component:) index = @records.index{ |rec| id == rec&.id } @records[index].update_component(component) if index >= 0 end |
#delete(id: nil, ids: nil) ⇒ Object
306 307 308 309 310 311 312 313 314 315 316 317 318 319 |
# File 'lib/game_ecs/entity_store.rb', line 306 def delete(id:nil, ids:nil) if id @records.delete_at(@records.index{ |rec| id == rec&.id } || @records.size) if @ids.include? id @ids.delete id else unless (@ids & ids).empty? # ids.each do |id| # @ids.delete id # end @ids = @ids - ids @records.delete_if{|res| ids.include? res.id} end end end |
#each ⇒ Object
320 321 322 323 324 |
# File 'lib/game_ecs/entity_store.rb', line 320 def each @records.each do |rec| yield rec end end |
#has_id?(id) ⇒ Boolean
299 300 301 |
# File 'lib/game_ecs/entity_store.rb', line 299 def has_id?(id) @ids.include? id end |