This issue proposes adding dedicated mouse event handlers to the ABS Engine entity lifecycle system, specifically hover and click events exposed through clearly named class constants.
Proposed Event Constants
The following constants should be added to the event naming convention:
L_CLICKED -- left mouse button click
MIDDLE_CLICKED -- middle mouse button click
R_CLICKED -- right mouse button click
MOUSE_HOVERED -- mouse cursor is positioned over the entity's rectangle
Motivation
Currently, the event lifecycle function on entity scripts receives raw Pygame events. Detecting whether the mouse is interacting with a specific entity requires the script author to manually check mouse position against the entity's rect and filter event types by hand. This is repetitive boilerplate that every interactive entity ends up duplicating.
Adding first-class mouse event constants would:
- Reduce boilerplate. Script authors could check for
L_CLICKED or MOUSE_HOVERED the same way they handle any other engine event, without writing manual rect-vs-position hit tests.
- Improve consistency. The naming convention mirrors the existing event system and gives mouse interactions a predictable, discoverable API.
- Lower the barrier for new developers. Someone building their first interactive entity should not need to know the internals of Pygame's mouse event system. A clear, engine-level abstraction makes the engine friendlier to use.
- Enable cleaner entity scripts. Scripts stay focused on game logic rather than input plumbing, which aligns with the intent of the three-function lifecycle design (
init, update, event).
Implementation Notes
- Hover detection can use the existing rect system. Each tick, the scene (or the entity's internal
update_rect step) can check whether the mouse position falls within the entity's rect and fire MOUSE_HOVERED accordingly.
- Click detection can be handled inside the
event propagation path. When a Pygame mouse button event is received, the engine checks whether the cursor is within the entity's rect before dispatching L_CLICKED, MIDDLE_CLICKED, or R_CLICKED to that entity's event function.
- This keeps all hit-testing logic inside the engine and out of user scripts.
Acceptance Criteria
This issue proposes adding dedicated mouse event handlers to the ABS Engine entity lifecycle system, specifically hover and click events exposed through clearly named class constants.
Proposed Event Constants
The following constants should be added to the event naming convention:
L_CLICKED-- left mouse button clickMIDDLE_CLICKED-- middle mouse button clickR_CLICKED-- right mouse button clickMOUSE_HOVERED-- mouse cursor is positioned over the entity's rectangleMotivation
Currently, the
eventlifecycle function on entity scripts receives raw Pygame events. Detecting whether the mouse is interacting with a specific entity requires the script author to manually check mouse position against the entity's rect and filter event types by hand. This is repetitive boilerplate that every interactive entity ends up duplicating.Adding first-class mouse event constants would:
L_CLICKEDorMOUSE_HOVEREDthe same way they handle any other engine event, without writing manual rect-vs-position hit tests.init,update,event).Implementation Notes
update_rectstep) can check whether the mouse position falls within the entity's rect and fireMOUSE_HOVEREDaccordingly.eventpropagation path. When a Pygame mouse button event is received, the engine checks whether the cursor is within the entity's rect before dispatchingL_CLICKED,MIDDLE_CLICKED, orR_CLICKEDto that entity'seventfunction.Acceptance Criteria
L_CLICKED,MIDDLE_CLICKED, andR_CLICKEDfire on the correct mouse button press when the cursor is within the entity's rectMOUSE_HOVEREDfires each tick the cursor is within the entity's recteventlifecycle function