Implement EntityCollection.extend() method for Issue #27
Added extend() method to EntityCollection that accepts any iterable of Entity objects and adds them all to the collection. The method: - Accepts lists, tuples, generators, or any iterable - Validates all items are Entity objects - Sets the grid association for each added entity - Properly handles errors and empty iterables closes #27
This commit is contained in:
parent
923350137d
commit
1e7f5e9e7e
4 changed files with 165 additions and 1 deletions
20
quick_extend_test.py
Normal file
20
quick_extend_test.py
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
import mcrfpy
|
||||
|
||||
# Create grid
|
||||
t = mcrfpy.Texture("assets/kenney_ice.png", 16, 16)
|
||||
g = mcrfpy.Grid(5, 5, t, (0, 0), (100, 100))
|
||||
|
||||
# Create some entities
|
||||
entities = [mcrfpy.Entity((i, i), t, i, g) for i in range(3)]
|
||||
|
||||
# Test extend
|
||||
print(f"Initial entities: {len(g.entities)}")
|
||||
g.entities.extend(entities)
|
||||
print(f"After extend: {len(g.entities)}")
|
||||
|
||||
# Test with tuple
|
||||
more = (mcrfpy.Entity((3, 3), t, 3, g), mcrfpy.Entity((4, 4), t, 4, g))
|
||||
g.entities.extend(more)
|
||||
print(f"After second extend: {len(g.entities)}")
|
||||
|
||||
print("✓ EntityCollection.extend() works!")
|
||||
Loading…
Add table
Add a link
Reference in a new issue