chione 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -259,7 +259,8 @@ describe Chione::World do
259
259
  entity = world.create_entity( archetype )
260
260
 
261
261
  expect( entity ).to be_a( Chione::Entity )
262
- expect( entity.components.keys ).to include( *archetype.components.keys )
262
+ expect( world.components_for(entity).keys ).
263
+ to contain_exactly( *archetype.components.keys )
263
264
  end
264
265
 
265
266
 
@@ -306,68 +307,27 @@ describe Chione::World do
306
307
 
307
308
  describe "components" do
308
309
 
309
- let( :world ) do
310
- instance = super()
311
- instance.defer_events = false
312
- instance
313
- end
314
-
315
-
316
- let!( :entity1 ) do
317
- obj = world.create_entity
318
- obj.add_component( location_component.new )
319
- obj
320
- end
321
-
322
- let!( :entity2 ) do
323
- obj = world.create_entity
324
- obj.add_component( location_component.new )
325
- obj.add_component( tags_component.new )
326
- obj
327
- end
328
-
329
- let!( :entity3 ) do
330
- obj = world.create_entity
331
- obj.add_component( tags_component.new )
332
- obj
333
- end
334
-
335
- let( :location_aspect ) { Chione::Aspect.with_one_of(location_component) }
336
- let( :tags_aspect ) { Chione::Aspect.with_one_of(tags_component) }
337
- let( :colored_aspect ) { Chione::Aspect.with_one_of(color_component) }
338
- let( :tagged_located_aspect ) do
339
- Chione::Aspect.with_all_of( location_component, tags_component )
310
+ it "can add a component for an entity" do
311
+ entity = world.create_entity
312
+ world.add_component_to( entity, location_component )
313
+ expect( world ).to have_component_for( entity, location_component )
340
314
  end
341
315
 
342
316
 
343
- it "can look up sets of entities which match Aspects" do
344
- entities_with_location = world.entities_with( location_aspect )
345
- expect( entities_with_location ).to include( entity1, entity2 )
346
- expect( entities_with_location ).to_not include( entity3 )
347
-
348
- entities_with_tags = world.entities_with( tags_aspect )
349
- expect( entities_with_tags ).to include( entity2, entity3 )
350
- expect( entities_with_tags ).to_not include( entity1 )
351
-
352
- entities_with_both = world.entities_with( tagged_located_aspect )
353
- expect( entities_with_both ).to include( entity2 )
354
- expect( entities_with_both ).to_not include( entity1, entity3 )
355
-
356
- entities_with_color = world.entities_with( colored_aspect )
357
- expect( entities_with_color ).to be_empty
317
+ it "can remove a component from an entity" do
318
+ entity = world.create_entity
319
+ world.add_component_to( entity, location_component )
320
+ world.remove_component_from( entity, location_component )
321
+ expect( world ).to_not have_component_for( entity, location_component )
358
322
  end
359
323
 
360
324
 
361
- it "can look up sets of entities which match a System's aspect" do
362
- system = Class.new( Chione::System )
363
- system.for_entities_that_have \
364
- all_of: [ location_component ],
365
- one_of: [ tags_component, color_component ]
366
-
367
- entities = world.entities_for( system )
325
+ it "can test to see whether an entity has a component type" do
326
+ entity = world.create_entity
368
327
 
369
- expect( entities ).to include( entity2 )
370
- expect( entities ).to_not include( entity1, entity3 )
328
+ expect( world ).to_not have_component_for( entity, location_component )
329
+ world.add_component_to( entity, location_component )
330
+ expect( world ).to have_component_for( entity, location_component )
371
331
  end
372
332
 
373
333
  end
@@ -389,6 +349,14 @@ describe Chione::World do
389
349
  end
390
350
 
391
351
 
352
+ it "can have Systems removed from it" do
353
+ world.add_system( test_system )
354
+ result = world.remove_system( test_system )
355
+ expect( world.systems ).to_not include( test_system )
356
+ expect( result ).to be_a( test_system )
357
+ end
358
+
359
+
392
360
  it "can register Systems constructed with custom arguments" do
393
361
  system = world.add_system( test_system, 1, 2 )
394
362
  expect( system.args ).to eq([ 1, 2 ])
@@ -402,7 +370,19 @@ describe Chione::World do
402
370
 
403
371
  sys = world.add_system( test_system )
404
372
 
405
- expect( event_payload ).to eq([ 'system/added', [test_system.name] ])
373
+ expect( event_payload ).to eq([ 'system/added', [sys] ])
374
+ end
375
+
376
+
377
+ it "broadcasts a `system/removed` event when a System is removed" do
378
+ event_payload = nil
379
+ world.defer_events = false
380
+ world.subscribe( 'system/removed' ) {|*payload| event_payload = payload }
381
+
382
+ sys = world.add_system( test_system )
383
+ world.remove_system( test_system )
384
+
385
+ expect( event_payload ).to eq([ 'system/removed', [sys] ])
406
386
  end
407
387
 
408
388
 
@@ -423,6 +403,60 @@ describe Chione::World do
423
403
  expect( system.started ).to be_truthy
424
404
  end
425
405
 
406
+
407
+ it "stops a system before it's removed if it was started" do
408
+ system = world.add_system( test_system )
409
+ world.start
410
+ sleep 0.1 until world.running?
411
+ world.remove_system( test_system )
412
+ expect( system.stopped ).to be_truthy
413
+ world.stop
414
+ end
415
+
416
+ end
417
+
418
+
419
+ describe "aspects" do
420
+
421
+ let( :entity1 ) do
422
+ obj = world.create_entity
423
+ obj.add_component( location_component.new )
424
+ obj
425
+ end
426
+ let( :entity2 ) do
427
+ obj = world.create_entity
428
+ obj.add_component( location_component.new )
429
+ obj.add_component( tags_component.new )
430
+ obj
431
+ end
432
+ let( :entity3 ) do
433
+ obj = world.create_entity
434
+ obj.add_component( tags_component.new )
435
+ obj
436
+ end
437
+
438
+ let( :location_aspect ) { Chione::Aspect.with_one_of(location_component) }
439
+ let( :tags_aspect ) { Chione::Aspect.with_one_of(tags_component) }
440
+ let( :colored_aspect ) { Chione::Aspect.with_one_of(color_component) }
441
+ let( :tagged_located_aspect ) do
442
+ Chione::Aspect.with_all_of( location_component, tags_component )
443
+ end
444
+
445
+
446
+ it "can look up sets of entities which match Aspects" do
447
+ entities_with_location = world.entities_with( location_aspect )
448
+ expect( entities_with_location ).to contain_exactly( entity1.id, entity2.id )
449
+
450
+ entities_with_tags = world.entities_with( tags_aspect )
451
+ expect( entities_with_tags ).to contain_exactly( entity2.id, entity3.id )
452
+
453
+ entities_with_both = world.entities_with( tagged_located_aspect )
454
+ expect( entities_with_both ).to contain_exactly( entity2.id )
455
+
456
+ entities_with_color = world.entities_with( colored_aspect )
457
+ expect( entities_with_color ).to be_empty
458
+ end
459
+
426
460
  end
427
461
 
428
462
 
@@ -435,13 +469,20 @@ describe Chione::World do
435
469
  end
436
470
 
437
471
 
438
- it "can register Managers" do
472
+ it "can have Managers added to it" do
439
473
  manager = world.add_manager( test_manager )
440
474
  expect( world.managers ).to include( test_manager )
441
475
  expect( world.managers[test_manager] ).to be( manager )
442
476
  end
443
477
 
444
478
 
479
+ it "can have Managers removed from it" do
480
+ world.add_manager( test_manager )
481
+ world.remove_manager( test_manager )
482
+ expect( world.managers ).to_not include( test_manager )
483
+ end
484
+
485
+
445
486
  it "can register Managers constructed with custom arguments" do
446
487
  manager = world.add_manager( test_manager, 1, 2 )
447
488
  expect( manager.args ).to eq([ 1, 2 ])
@@ -455,7 +496,19 @@ describe Chione::World do
455
496
 
456
497
  manager = world.add_manager( test_manager )
457
498
 
458
- expect( event_payload ).to eq([ 'manager/added', [test_manager.name] ])
499
+ expect( event_payload ).to eq([ 'manager/added', [manager] ])
500
+ end
501
+
502
+
503
+ it "broadcasts a `manager/removed` event when a Manager is removed" do
504
+ event_payload = nil
505
+ world.defer_events = false
506
+ world.subscribe( 'manager/removed' ) {|*payload| event_payload = payload }
507
+
508
+ world.add_manager( test_manager )
509
+ manager = world.remove_manager( test_manager )
510
+
511
+ expect( event_payload ).to eq([ 'manager/removed', [manager] ])
459
512
  end
460
513
 
461
514
 
@@ -476,6 +529,16 @@ describe Chione::World do
476
529
  expect( manager.started ).to be_truthy
477
530
  end
478
531
 
532
+
533
+ it "stops a manager when it's removed if it was started" do
534
+ world.add_manager( test_manager )
535
+ world.start
536
+ sleep 0.1 until world.running?
537
+ manager = world.remove_manager( test_manager )
538
+ expect( manager.stopped ).to be_truthy
539
+ world.stop
540
+ end
541
+
479
542
  end
480
543
 
481
544
  end
@@ -6,6 +6,7 @@ require 'simplecov' if ENV['COVERAGE']
6
6
  require 'rspec'
7
7
  require 'deprecatable'
8
8
  require 'loggability/spechelpers'
9
+ require 'faker'
9
10
 
10
11
  require 'chione'
11
12
 
@@ -16,6 +17,8 @@ module Chione::TestHelpers
16
17
  end
17
18
 
18
19
 
20
+ Faker::Config.locale = :en
21
+
19
22
 
20
23
  RSpec.configure do |config|
21
24
  # include Chione::TestHelpers
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chione
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Granger
@@ -10,9 +10,9 @@ bindir: bin
10
10
  cert_chain:
11
11
  - |
12
12
  -----BEGIN CERTIFICATE-----
13
- MIIEbDCCAtSgAwIBAgIBATANBgkqhkiG9w0BAQsFADA+MQwwCgYDVQQDDANnZWQx
13
+ MIIEbDCCAtSgAwIBAgIBATANBgkqhkiG9w0BAQUFADA+MQwwCgYDVQQDDANnZWQx
14
14
  GTAXBgoJkiaJk/IsZAEZFglGYWVyaWVNVUQxEzARBgoJkiaJk/IsZAEZFgNvcmcw
15
- HhcNMTYwODIwMTgxNzQyWhcNMTcwODIwMTgxNzQyWjA+MQwwCgYDVQQDDANnZWQx
15
+ HhcNMTcwOTI3MDAzMDQ0WhcNMTgwOTI3MDAzMDQ0WjA+MQwwCgYDVQQDDANnZWQx
16
16
  GTAXBgoJkiaJk/IsZAEZFglGYWVyaWVNVUQxEzARBgoJkiaJk/IsZAEZFgNvcmcw
17
17
  ggGiMA0GCSqGSIb3DQEBAQUAA4IBjwAwggGKAoIBgQC/JWGRHO+USzR97vXjkFgt
18
18
  83qeNf2KHkcvrRTSnR64i6um/ziin0I0oX23H7VYrDJC9A/uoUa5nGRJS5Zw/+wW
@@ -25,17 +25,17 @@ cert_chain:
25
25
  /D+K9JW9DDs3Yjgv9k4h7YMhW5gftosd+NkNC/+Y2CkCAwEAAaN1MHMwCQYDVR0T
26
26
  BAIwADALBgNVHQ8EBAMCBLAwHQYDVR0OBBYEFHKN/nkRusdqCJEuq3lgB3fJvyTg
27
27
  MBwGA1UdEQQVMBOBEWdlZEBGYWVyaWVNVUQub3JnMBwGA1UdEgQVMBOBEWdlZEBG
28
- YWVyaWVNVUQub3JnMA0GCSqGSIb3DQEBCwUAA4IBgQAPJzKiT0zBU7kpqe0aS2qb
29
- FI0PJ4y5I8buU4IZGUD5NEt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vw5KAGBmfX8nht/Py90DQrbRvakATGI=
37
37
  -----END CERTIFICATE-----
38
- date: 2017-05-31 00:00:00.000000000 Z
38
+ date: 2017-12-12 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: loggability
@@ -107,6 +107,34 @@ dependencies:
107
107
  - - "~>"
108
108
  - !ruby/object:Gem::Version
109
109
  version: '1.0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: fluent_fixtures
112
+ requirement: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: '0.6'
117
+ type: :runtime
118
+ prerelease: false
119
+ version_requirements: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - "~>"
122
+ - !ruby/object:Gem::Version
123
+ version: '0.6'
124
+ - !ruby/object:Gem::Dependency
125
+ name: faker
126
+ requirement: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - "~>"
129
+ - !ruby/object:Gem::Version
130
+ version: '1.8'
131
+ type: :runtime
132
+ prerelease: false
133
+ version_requirements: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - "~>"
136
+ - !ruby/object:Gem::Version
137
+ version: '1.8'
110
138
  - !ruby/object:Gem::Dependency
111
139
  name: hoe-mercurial
112
140
  requirement: !ruby/object:Gem::Requirement
@@ -238,6 +266,9 @@ files:
238
266
  - lib/chione/behaviors.rb
239
267
  - lib/chione/component.rb
240
268
  - lib/chione/entity.rb
269
+ - lib/chione/fixtures.rb
270
+ - lib/chione/fixtures/entities.rb
271
+ - lib/chione/iterating_system.rb
241
272
  - lib/chione/manager.rb
242
273
  - lib/chione/mixins.rb
243
274
  - lib/chione/system.rb
@@ -246,6 +277,7 @@ files:
246
277
  - spec/chione/aspect_spec.rb
247
278
  - spec/chione/component_spec.rb
248
279
  - spec/chione/entity_spec.rb
280
+ - spec/chione/iterating_system_spec.rb
249
281
  - spec/chione/manager_spec.rb
250
282
  - spec/chione/mixins_spec.rb
251
283
  - spec/chione/system_spec.rb
@@ -274,7 +306,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
274
306
  version: '0'
275
307
  requirements: []
276
308
  rubyforge_project:
277
- rubygems_version: 2.6.11
309
+ rubygems_version: 2.6.14
278
310
  signing_key:
279
311
  specification_version: 4
280
312
  summary: An Entity/Component System framework inspired by Artemis
metadata.gz.sig CHANGED
Binary file