Commit Graph

10 Commits

Author SHA1 Message Date
John McCardle cb0130b46e 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
2025-07-03 21:09:06 -04:00
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
John McCardle 923350137d Implement Entity.index() method for Issue #73
Added index() method to Entity class that returns the entity's
position in its parent grid's entity collection. This enables
proper entity removal patterns using entity.index().
2025-07-03 21:02:14 -04:00
John McCardle 6134869371 Add validation to keypressScene() for non-callable arguments
Added PyCallable_Check validation to ensure keypressScene() only
accepts callable objects. Now properly raises TypeError with a
clear error message when passed non-callable arguments like
strings, numbers, None, or dicts.
2025-07-03 20:41:03 -04:00
John McCardle 4715356b5e Fix Sprite texture setter 'error return without exception set'
Implemented the missing UISprite::set_texture method to properly:
- Validate the input is a Texture instance
- Update the sprite's texture using setTexture()
- Return appropriate error messages for invalid inputs

The setter now works correctly and no longer returns -1 without
setting an exception.
2025-07-03 20:31:36 -04:00
John McCardle 6dd1cec600 Fix Entity property setters and PyVector implementation
Fixed the 'new style getargs format' error in Entity property setters by:
- Implementing PyObject_to_sfVector2f/2i using PyVector::from_arg
- Adding proper error checking in Entity::set_position
- Implementing PyVector get_member/set_member for x/y properties
- Fixing PyVector::from_arg to handle non-tuple arguments correctly

Now Entity.pos and Entity.sprite_number setters work correctly with
proper type validation.
2025-07-03 20:27:32 -04:00
John McCardle f82b861bcd Fix Issue #74: Add missing Grid.grid_y property
Added individual grid_x and grid_y getter properties to the Grid class
to complement the existing grid_size property. This allows direct access
to grid dimensions and fixes error messages that referenced these
properties before they existed.

closes #74
2025-07-03 19:48:33 -04:00
John McCardle 59e6f8d53d Fix Issue #78: Middle mouse click no longer sends 'C' keyboard event
The bug was caused by accessing event.key.code on a mouse event without
checking the event type first. Since SFML uses a union for events, this
read garbage data. The middle mouse button value (2) coincidentally matched
the keyboard 'C' value (2), causing the spurious keyboard event.

Fixed by adding event type check before accessing key-specific fields.
Only keyboard events (KeyPressed/KeyReleased) now trigger key callbacks.

Test added to verify middle clicks no longer generate keyboard events.

Closes #78
2025-07-03 19:42:32 -04:00
John McCardle 1c71d8d4f7 Fix Grid to support None/null texture and fix error message bug
- Allow Grid to be created with None as texture parameter
- Use default cell dimensions (16x16) when no texture provided
- Skip sprite rendering when texture is null, but still render colors
- Fix issue #77: Corrected copy/paste error in Grid.at() error messages
- Grid now functional for color-only rendering and entity positioning

Test created to verify Grid works without texture, showing colored cells.

Closes #77
2025-07-03 19:40:42 -04:00
John McCardle 18cfe93a44 Fix --exec interactive prompt bug and create comprehensive test suite
Major fixes:
- Fixed --exec entering Python REPL instead of game loop
- Resolved screenshot transparency issue (requires timer callbacks)
- Added debug output to trace Python initialization

Test suite created:
- 13 comprehensive tests covering all Python-exposed methods
- Tests use timer callback pattern for proper game loop interaction
- Discovered multiple critical bugs and missing features

Critical bugs found:
- Grid class segfaults on instantiation (blocks all Grid functionality)
- Issue #78 confirmed: Middle mouse click sends 'C' keyboard event
- Entity property setters have argument parsing errors
- Sprite texture setter returns improper error
- keypressScene() segfaults on non-callable arguments

Documentation updates:
- Updated CLAUDE.md with testing guidelines and TDD practices
- Created test reports documenting all findings
- Updated ROADMAP.md with test results and new priorities

The Grid segfault is now the highest priority as it blocks all Grid-based functionality.
2025-07-03 19:25:49 -04:00