tinyecs 0.5.2__tar.gz → 0.5.3a0__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tinyecs
3
- Version: 0.5.2
3
+ Version: 0.5.3a0
4
4
  Summary: The teeniest, tiniest ECS system
5
5
  Author-email: Michael Lamertz <michael.lamertz@gmail.com>
6
6
  License-Expression: MIT
@@ -1,7 +1,7 @@
1
1
  [project]
2
2
  name = "tinyecs"
3
3
  description = "The teeniest, tiniest ECS system"
4
- version = "0.5.2"
4
+ version = "0.5.3a"
5
5
  readme = "README.rst"
6
6
 
7
7
  authors = [
@@ -14,10 +14,11 @@ __all__ = ['Component', 'ComponentID', 'DomainID', 'EntityID',
14
14
  'create_entity', 'eid_has', 'eid_of_comp', 'eids_by_cids',
15
15
  'eids_by_property', 'has', 'has_property', 'healthcheck',
16
16
  'purge_by_property', 'remove_archetype', 'remove_component',
17
- 'remove_entity', 'remove_from_archetype', 'remove_property',
18
- 'remove_system', 'remove_system_from_domain', 'reset',
19
- 'run_all_systems', 'run_bulk_system', 'run_domain', 'run_system',
20
- 'set_properties', 'set_property', 'update_component',]
17
+ 'remove_domain', 'remove_entity', 'remove_from_archetype',
18
+ 'remove_property', 'remove_system', 'remove_system_from_domain',
19
+ 'reset', 'run_all_systems', 'run_bulk_system', 'run_domain',
20
+ 'run_system', 'set_properties', 'set_property',
21
+ 'update_component',]
21
22
 
22
23
  type EntityID = Hashable
23
24
  type ComponentID = Hashable
@@ -352,7 +353,7 @@ def remove_system(fn: SystemFunction) -> None:
352
353
  pass
353
354
 
354
355
 
355
- def add_system_to_domain(domain: DomainID, system: SystemFunction) -> None:
356
+ def add_system_to_domain(domain: DomainID, *system: SystemFunction, after=None) -> None:
356
357
  """Create or extend a domain with the given system.
357
358
 
358
359
  :param system: The system function
@@ -364,11 +365,16 @@ def add_system_to_domain(domain: DomainID, system: SystemFunction) -> None:
364
365
  .. important:: The system must first be registered with add_system.
365
366
  """
366
367
 
367
- if system not in sidx:
368
- raise UnknownSystemError(f'system {system} is not registered')
369
- if domain not in didx:
370
- didx[domain] = set()
371
- didx[domain].add(system)
368
+ for s in system:
369
+ if s not in sidx:
370
+ raise UnknownSystemError(f'system {s} is not registered')
371
+ if domain not in didx:
372
+ didx[domain] = []
373
+
374
+ try:
375
+ didx[domain].insert(didx[domain].index(after) + 1, s)
376
+ except ValueError:
377
+ didx[domain].append(s)
372
378
 
373
379
 
374
380
  def remove_system_from_domain(domain: DomainID, system: SystemFunction) -> None:
@@ -384,6 +390,21 @@ def remove_system_from_domain(domain: DomainID, system: SystemFunction) -> None:
384
390
  return
385
391
  try:
386
392
  didx[domain].remove(system)
393
+ except ValueError:
394
+ pass
395
+
396
+
397
+ def remove_domain(domain: DomainID) -> None:
398
+ """Remove the given domain.
399
+
400
+ :param domain: The domain to remove
401
+ :return: None
402
+
403
+ .. note:: A non existing domain is silently ignored
404
+ """
405
+
406
+ try:
407
+ del didx[domain]
387
408
  except KeyError:
388
409
  pass
389
410
 
@@ -637,6 +658,14 @@ def run_all_systems(**kwargs) -> dict[SystemFunction, _RunSystemResult]:
637
658
 
638
659
  This calls above run_system for all registered systems with their
639
660
  appropriate components.
661
+
662
+ .. important:: If you pass kwargs to ``run_all_systems``, naturally all
663
+ systems have to accept kwargs. This is in the responsibility of the
664
+ programmer.
665
+
666
+ This function is provided for very simple use cases, use either well
667
+ ordered lists of ``run_system`` calls or the domain system, which will
668
+ be much less error prone.
640
669
  """
641
670
 
642
671
  return {fn: run_system(fn, *comps, **kwargs)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tinyecs
3
- Version: 0.5.2
3
+ Version: 0.5.3a0
4
4
  Summary: The teeniest, tiniest ECS system
5
5
  Author-email: Michael Lamertz <michael.lamertz@gmail.com>
6
6
  License-Expression: MIT
@@ -326,6 +326,43 @@ def test_run_domain():
326
326
  assert res == {}
327
327
 
328
328
 
329
+ def test_stable_domain_order():
330
+ def dummy_system1b(eid, comp): pass
331
+ def dummy_system1a(eid, comp): pass
332
+ def dummy_system2a(eid, comp): pass
333
+ def dummy_system2b(eid, comp): pass
334
+ def dummy_system3(eid, comp): pass
335
+
336
+ ecs.reset()
337
+ ecs.add_system(dummy_system1a, 'dummy_comp')
338
+ ecs.add_system(dummy_system1b, 'dummy_comp')
339
+ ecs.add_system(dummy_system2a, 'dummy_comp')
340
+ ecs.add_system(dummy_system2b, 'dummy_comp')
341
+ ecs.add_system(dummy_system3, 'dummy_comp')
342
+
343
+ ecs.add_system_to_domain('ze_domain', dummy_system1a, dummy_system2a)
344
+ assert ecs.didx['ze_domain'] == [dummy_system1a, dummy_system2a]
345
+
346
+ ecs.add_system_to_domain('ze_domain', dummy_system1b, after=dummy_system1a)
347
+ assert ecs.didx['ze_domain'] == [dummy_system1a, dummy_system1b, dummy_system2a]
348
+
349
+ ecs.add_system_to_domain('ze_domain', dummy_system2b, after=dummy_system2a)
350
+ assert ecs.didx['ze_domain'] == [dummy_system1a, dummy_system1b, dummy_system2a, dummy_system2b]
351
+
352
+
353
+ def test_remove_domain():
354
+ def dummy_system(eid, comp): pass
355
+
356
+ ecs.reset()
357
+ ecs.add_system(dummy_system, 'dummy_comp')
358
+
359
+ ecs.add_system_to_domain('ze_domain', dummy_system)
360
+ ecs.remove_domain('ze_domain')
361
+ assert 'ze_domain' not in ecs.didx
362
+
363
+ ecs.remove_domain('ze_domain')
364
+
365
+
329
366
  def test_eid_has():
330
367
  ecs.reset()
331
368
  e1, e2 = setup()
File without changes
File without changes
File without changes