Implement sprite index validation for Issue #33
Added validation to prevent setting sprite indices outside the valid range for a texture. The implementation: - Adds getSpriteCount() method to PyTexture to expose total sprites - Validates sprite_number setter to ensure index is within bounds - Provides clear error messages showing valid range - Works for both Sprite and Entity objects closes #33
This commit is contained in:
parent
1e7f5e9e7e
commit
cb0130b46e
5 changed files with 153 additions and 2 deletions
25
quick_sprite_test.py
Normal file
25
quick_sprite_test.py
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
import mcrfpy
|
||||
|
||||
# Test sprite index validation
|
||||
t = mcrfpy.Texture("assets/kenney_ice.png", 16, 16)
|
||||
s = mcrfpy.Sprite(10, 10, t, 5)
|
||||
|
||||
print(f"Initial sprite index: {s.sprite_number}")
|
||||
|
||||
# Try valid index
|
||||
s.sprite_number = 50
|
||||
print(f"Set to 50: {s.sprite_number}")
|
||||
|
||||
# Try invalid index
|
||||
try:
|
||||
s.sprite_number = 200
|
||||
print("ERROR: Should have rejected index 200")
|
||||
except ValueError as e:
|
||||
print(f"✓ Correctly rejected: {e}")
|
||||
|
||||
# Try negative
|
||||
try:
|
||||
s.sprite_number = -1
|
||||
print("ERROR: Should have rejected negative index")
|
||||
except ValueError as e:
|
||||
print(f"✓ Correctly rejected negative: {e}")
|
||||
Loading…
Add table
Add a link
Reference in a new issue