the low-hanging fruit of pre-existing issues and standardizing the
Python interfaces
Special thanks to Claude Code, ~100k output tokens for this merge
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
commit 99f301e3a0
Author: John McCardle <mccardle.john@gmail.com>
Date: Sat Jul 5 16:25:32 2025 -0400
Add position tuple support and pos property to UI elements
closes #83, closes #84
- Issue #83: Add position tuple support to constructors
- Frame and Sprite now accept both (x, y) and ((x, y)) forms
- Also accept Vector objects as position arguments
- Caption and Entity already supported tuple/Vector forms
- Uses PyVector::from_arg for flexible position parsing
- Issue #84: Add pos property to Frame and Sprite
- Added pos getter that returns a Vector
- Added pos setter that accepts Vector or tuple
- Provides consistency with Caption and Entity which already had pos properties
- All UI elements now have a uniform way to get/set positions as Vectors
Both features improve API consistency and make it easier to work with positions.
commit 2f2b488fb5
Author: John McCardle <mccardle.john@gmail.com>
Date: Sat Jul 5 16:18:10 2025 -0400
Standardize sprite_index property and add scale_x/scale_y to UISprite
closes #81, closes #82
- Issue #81: Standardized property name to sprite_index across UISprite and UIEntity
- Added sprite_index as the primary property name
- Kept sprite_number as a deprecated alias for backward compatibility
- Updated repr() methods to use sprite_index
- Updated animation system to recognize both names
- Issue #82: Added scale_x and scale_y properties to UISprite
- Enables non-uniform scaling of sprites
- scale property still works for uniform scaling
- Both properties work with the animation system
All existing code using sprite_number continues to work due to backward compatibility.
commit 5a003a9aa5
Author: John McCardle <mccardle.john@gmail.com>
Date: Sat Jul 5 16:09:52 2025 -0400
Fix multiple low priority issues
closes #12, closes #80, closes #95, closes #96, closes #99
- Issue #12: Set tp_new to NULL for GridPoint and GridPointState to prevent instantiation from Python
- Issue #80: Renamed Caption.size to Caption.font_size for semantic clarity
- Issue #95: Fixed UICollection repr to show actual derived types instead of generic UIDrawable
- Issue #96: Added extend() method to UICollection for API consistency with UIEntityCollection
- Issue #99: Exposed read-only properties for Texture (sprite_width, sprite_height, sheet_width, sheet_height, sprite_count, source) and Font (family, source)
All issues have corresponding tests that verify the fixes work correctly.
commit e5affaf317
Author: John McCardle <mccardle.john@gmail.com>
Date: Sat Jul 5 15:50:09 2025 -0400
Fix critical issues: script loading, entity types, and color properties
- Issue #37: Fix Windows scripts subdirectory not checked
- Updated executeScript() to use executable_path() from platform.h
- Scripts now load correctly when working directory differs from executable
- Issue #76: Fix UIEntityCollection returns wrong type
- Updated UIEntityCollectionIter::next() to check for stored Python object
- Derived Entity classes now preserve their type when retrieved from collections
- Issue #9: Recreate RenderTexture when resized (already fixed)
- Confirmed RenderTexture recreation already implemented in set_size() and set_float_member()
- Uses 1.5x padding and 4096 max size limit
- Issue #79: Fix Color r, g, b, a properties return None
- Implemented get_member() and set_member() in PyColor.cpp
- Color component properties now work correctly with proper validation
- Additional fix: Grid.at() method signature
- Changed from METH_O to METH_VARARGS to accept two arguments
All fixes include comprehensive tests to verify functionality.
closes #37, closes #76, closes #9, closes #79
82 lines
2.8 KiB
C++
82 lines
2.8 KiB
C++
#pragma once
|
|
#include "Common.h"
|
|
#include "Python.h"
|
|
#include "structmember.h"
|
|
#include "IndexTexture.h"
|
|
#include "Resources.h"
|
|
#include <list>
|
|
|
|
#include "PyCallable.h"
|
|
#include "PyTexture.h"
|
|
#include "PyColor.h"
|
|
#include "PyVector.h"
|
|
#include "PyFont.h"
|
|
|
|
#include "UIGridPoint.h"
|
|
#include "UIDrawable.h"
|
|
#include "UIBase.h"
|
|
#include "UISprite.h"
|
|
|
|
class UIGrid;
|
|
|
|
//class UIEntity;
|
|
//typedef struct {
|
|
// PyObject_HEAD
|
|
// std::shared_ptr<UIEntity> data;
|
|
//} PyUIEntityObject;
|
|
|
|
// helper methods with no namespace requirement
|
|
static PyObject* sfVector2f_to_PyObject(sf::Vector2f vector);
|
|
static sf::Vector2f PyObject_to_sfVector2f(PyObject* obj);
|
|
static PyObject* UIGridPointState_to_PyObject(const UIGridPointState& state);
|
|
static PyObject* UIGridPointStateVector_to_PyList(const std::vector<UIGridPointState>& vec);
|
|
|
|
// TODO: make UIEntity a drawable
|
|
class UIEntity//: public UIDrawable
|
|
{
|
|
public:
|
|
PyObject* self = nullptr; // Reference to the Python object (if created from Python)
|
|
std::shared_ptr<UIGrid> grid;
|
|
std::vector<UIGridPointState> gridstate;
|
|
UISprite sprite;
|
|
sf::Vector2f position; //(x,y) in grid coordinates; float for animation
|
|
sf::Vector2i collision_pos; //(x, y) in grid coordinates: int for collision
|
|
//void render(sf::Vector2f); //override final;
|
|
|
|
UIEntity();
|
|
UIEntity(UIGrid&);
|
|
|
|
// Property system for animations
|
|
bool setProperty(const std::string& name, float value);
|
|
bool setProperty(const std::string& name, int value);
|
|
bool getProperty(const std::string& name, float& value) const;
|
|
|
|
static PyObject* at(PyUIEntityObject* self, PyObject* o);
|
|
static PyObject* index(PyUIEntityObject* self, PyObject* Py_UNUSED(ignored));
|
|
static int init(PyUIEntityObject* self, PyObject* args, PyObject* kwds);
|
|
|
|
static PyObject* get_position(PyUIEntityObject* self, void* closure);
|
|
static int set_position(PyUIEntityObject* self, PyObject* value, void* closure);
|
|
static PyObject* get_gridstate(PyUIEntityObject* self, void* closure);
|
|
static PyObject* get_spritenumber(PyUIEntityObject* self, void* closure);
|
|
static int set_spritenumber(PyUIEntityObject* self, PyObject* value, void* closure);
|
|
static PyMethodDef methods[];
|
|
static PyGetSetDef getsetters[];
|
|
static PyObject* repr(PyUIEntityObject* self);
|
|
};
|
|
|
|
namespace mcrfpydef {
|
|
static PyTypeObject PyUIEntityType = {
|
|
.ob_base = {.ob_base = {.ob_refcnt = 1, .ob_type = NULL}, .ob_size = 0},
|
|
.tp_name = "mcrfpy.Entity",
|
|
.tp_basicsize = sizeof(PyUIEntityObject),
|
|
.tp_itemsize = 0,
|
|
.tp_repr = (reprfunc)UIEntity::repr,
|
|
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
|
|
.tp_doc = "UIEntity objects",
|
|
.tp_methods = UIEntity::methods,
|
|
.tp_getset = UIEntity::getsetters,
|
|
.tp_init = (initproc)UIEntity::init,
|
|
.tp_new = PyType_GenericNew,
|
|
};
|
|
}
|