Entities have grid_pos initializer argument, but pos property #176

Closed
opened 2026-01-04 22:02:39 +00:00 by john · 1 comment
Owner

could probably dig up a lot of history behind this problem and if pos vs grid_pos is worth the headache to distinguish, but regardless, I don't think the inconsistency is appropriate. I'm leaning towards making PyEntity use grid_pos as the property name.

could probably dig up a lot of history behind this problem and if `pos` vs `grid_pos` is worth the headache to distinguish, but regardless, I don't think the inconsistency is appropriate. I'm leaning towards making PyEntity use `grid_pos` as the property name.
Author
Owner

Implementation Complete

Resolved the Entity position naming inconsistency with a three-tier coordinate system:

New Entity Properties

Property Type Unit Purpose
pos, x, y Vector/float pixels Pixel position relative to grid (like UIDrawable)
grid_pos, grid_x, grid_y Vector/int tiles Integer tile coordinates (logical game position)
draw_pos Vector tiles (float) Fractional tile position for smooth animation

Key Features

  1. pos/x/y (pixels) - Computed as draw_pos * tile_size

    • Requires entity to be attached to a grid (raises RuntimeError otherwise)
    • Enables alignment with grid children: caption.pos = entity.pos
  2. grid_pos/grid_x/grid_y (tiles) - Integer tile coordinates

    • Works with or without grid attachment
    • Matches the grid_pos constructor argument
    • Used for game logic (which cell the entity occupies)
  3. draw_pos (fractional tiles) - For smooth animation

    • Animate between cells: entity.animate("draw_x", 5.0, 1.0)
    • Grid renders entity at this fractional position

Animation Changes

Animation property names updated for clarity:

  • draw_x, draw_y - Preferred names for tile coordinate animation
  • x, y - Kept as aliases for backwards compatibility

Files Changed

  • src/UIEntity.h - Added new getter/setter declarations, updated docstring
  • src/UIEntity.cpp - Implemented pixel position getters/setters, updated getsetters array, updated repr to show grid_x/grid_y

Test

New test: tests/issue_176_entity_position_test.py

## Implementation Complete Resolved the Entity position naming inconsistency with a three-tier coordinate system: ### New Entity Properties | Property | Type | Unit | Purpose | |----------|------|------|---------| | `pos`, `x`, `y` | Vector/float | pixels | Pixel position relative to grid (like UIDrawable) | | `grid_pos`, `grid_x`, `grid_y` | Vector/int | tiles | Integer tile coordinates (logical game position) | | `draw_pos` | Vector | tiles (float) | Fractional tile position for smooth animation | ### Key Features 1. **`pos`/`x`/`y` (pixels)** - Computed as `draw_pos * tile_size` - Requires entity to be attached to a grid (raises `RuntimeError` otherwise) - Enables alignment with grid children: `caption.pos = entity.pos` 2. **`grid_pos`/`grid_x`/`grid_y` (tiles)** - Integer tile coordinates - Works with or without grid attachment - Matches the `grid_pos` constructor argument - Used for game logic (which cell the entity occupies) 3. **`draw_pos` (fractional tiles)** - For smooth animation - Animate between cells: `entity.animate("draw_x", 5.0, 1.0)` - Grid renders entity at this fractional position ### Animation Changes Animation property names updated for clarity: - `draw_x`, `draw_y` - Preferred names for tile coordinate animation - `x`, `y` - Kept as aliases for backwards compatibility ### Files Changed - `src/UIEntity.h` - Added new getter/setter declarations, updated docstring - `src/UIEntity.cpp` - Implemented pixel position getters/setters, updated getsetters array, updated repr to show `grid_x`/`grid_y` ### Test New test: `tests/issue_176_entity_position_test.py`
john closed this issue 2026-01-07 00:57:16 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
john/McRogueFace#176
No description provided.