McRogueFace/quick_extend_test.py
John McCardle 1e7f5e9e7e 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
2025-07-03 21:05:47 -04:00

20 lines
No EOL
553 B
Python

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!")