diff options
| author | realtradam <[email protected]> | 2022-02-03 04:18:07 -0500 |
|---|---|---|
| committer | realtradam <[email protected]> | 2022-02-03 04:18:07 -0500 |
| commit | 866ed5e2ca86d2f780492f01c30b3350037d3f7c (patch) | |
| tree | f298a64b860b1d1ef64f4f3dae7c9670aa12a257 /spec/entity_manager_spec.rb | |
| parent | 1e9ee993f6f996352c797d9f9a4268e5a7c2f513 (diff) | |
| download | FelECS-866ed5e2ca86d2f780492f01c30b3350037d3f7c.tar.gz FelECS-866ed5e2ca86d2f780492f01c30b3350037d3f7c.zip | |
added new group method for entity managerv5.0.1
Diffstat (limited to 'spec/entity_manager_spec.rb')
| -rw-r--r-- | spec/entity_manager_spec.rb | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/spec/entity_manager_spec.rb b/spec/entity_manager_spec.rb index 25afa45..234c424 100644 --- a/spec/entity_manager_spec.rb +++ b/spec/entity_manager_spec.rb @@ -8,6 +8,8 @@ describe 'Entities' do before :all do $VERBOSE = nil @component_manager ||= FelECS::Components.new('TestEntity', :param1, param2: 'def') + @component_manager1 ||= FelECS::Components.new('TestEntity1', :param1, param2: 'def') + @component_manager2 ||= FelECS::Components.new('TestEntity2', :param1, param2: 'def') end before :each do @@ -25,6 +27,48 @@ describe 'Entities' do $stderr = @orig_stderr FelECS::Entities.reverse_each(&:delete) @component_manager.reverse_each(&:delete) + @component_manager1.reverse_each(&:delete) + @component_manager2.reverse_each(&:delete) + end + + it 'can iterate over component groups' do + cmp_1_1 = @component_manager1.new(param1: 1) + cmp_1_2 = @component_manager1.new(param1: 1) + cmp_1_3 = @component_manager1.new(param1: 1) + cmp_remove = @component_manager2.new + @ent0.add cmp_1_1, @cmp0, cmp_1_1, @component_manager2.new + @ent1.add cmp_1_2, @cmp1, cmp_1_2, cmp_remove + @ent2.add cmp_1_3, @component_manager2.new + @ent1.remove cmp_remove + FelECS::Entities.group(@component_manager1, @component_manager2) do |cmp1, cmp2, ent| + cmp1.param1 += 1 + end + cmp_1_1.param1 + expect(cmp_1_1.param1).to eq(2) + expect(cmp_1_2.param1).to eq(1) + expect(cmp_1_3.param1).to eq(2) + end + + it 'can iterate over a single component in a group' do + @ent0.add @cmp0 + @ent1.add @cmp1 + @ent2.add @cmp2 + @cmp0.param1 = @cmp1.param1 = @cmp2.param1 = 1 + FelECS::Entities.group(@component_manager) do |cmp, ent| + cmp.param1 += 1 + end + expect(@cmp0.param1).to eq(2) + expect(@cmp1.param1).to eq(2) + expect(@cmp2.param1).to eq(2) + end + + it 'can iterate over no components in a group' do + @cmp0.param1 = 1 + @ent0.add @cmp0 + FelECS::Entities.group do + @cmp0.param1 = 0 + end + expect(@cmp0.param1).to eq(1) end it 'can get a single component' do |
