From 322beeaf785418a3301516fe1e38f1ef952c7b94 Mon Sep 17 00:00:00 2001 From: John McCardle Date: Fri, 6 Feb 2026 21:43:52 -0500 Subject: [PATCH] add __ne__ support to enum types for input --- src/McRFPy_API.cpp | 16 ++++++++++++++++ src/PyInputState.cpp | 8 ++++++++ src/PyKey.cpp | 8 ++++++++ src/PyMouseButton.cpp | 8 ++++++++ tests/cookbook/cookbook_main.py | 12 ++++++------ 5 files changed, 46 insertions(+), 6 deletions(-) diff --git a/src/McRFPy_API.cpp b/src/McRFPy_API.cpp index ec4ffe1..d9e266c 100644 --- a/src/McRFPy_API.cpp +++ b/src/McRFPy_API.cpp @@ -37,6 +37,9 @@ #include "3d/Model3D.h" // 3D model resource #include "3d/Billboard.h" // Billboard sprites #include "3d/PyVoxelGrid.h" // Voxel grid for 3D structures (Milestone 9) +#include "tiled/PyTileSetFile.h" // Tiled tileset loading +#include "tiled/PyTileMapFile.h" // Tiled tilemap loading +#include "tiled/PyWangSet.h" // Wang auto-tile sets #include "McRogueFaceVersion.h" #include "GameEngine.h" // ImGui is only available for SFML builds @@ -486,6 +489,11 @@ PyObject* PyInit_mcrfpy() &mcrfpydef::PyPropertyBindingType, &mcrfpydef::PyCallableBindingType, + /*tiled map/tileset loading*/ + &mcrfpydef::PyTileSetFileType, + &mcrfpydef::PyTileMapFileType, + &mcrfpydef::PyWangSetType, + nullptr}; // Types that are used internally but NOT exported to module namespace (#189) @@ -559,6 +567,14 @@ PyObject* PyInit_mcrfpy() // Set up PyUniformCollectionType methods (#106) mcrfpydef::PyUniformCollectionType.tp_methods = ::PyUniformCollectionType::methods; + // Set up Tiled types methods and getsetters + mcrfpydef::PyTileSetFileType.tp_methods = PyTileSetFile::methods; + mcrfpydef::PyTileSetFileType.tp_getset = PyTileSetFile::getsetters; + mcrfpydef::PyTileMapFileType.tp_methods = PyTileMapFile::methods; + mcrfpydef::PyTileMapFileType.tp_getset = PyTileMapFile::getsetters; + mcrfpydef::PyWangSetType.tp_methods = PyWangSet::methods; + mcrfpydef::PyWangSetType.tp_getset = PyWangSet::getsetters; + // Set up weakref support for all types that need it PyTimerType.tp_weaklistoffset = offsetof(PyTimerObject, weakreflist); PyUIFrameType.tp_weaklistoffset = offsetof(PyUIFrameObject, weakreflist); diff --git a/src/PyInputState.cpp b/src/PyInputState.cpp index ea8fe55..ea7392f 100644 --- a/src/PyInputState.cpp +++ b/src/PyInputState.cpp @@ -69,6 +69,14 @@ def _InputState_eq(self, other): return int.__eq__(int(self), other) InputState.__eq__ = _InputState_eq + +def _InputState_ne(self, other): + result = type(self).__eq__(self, other) + if result is NotImplemented: + return result + return not result + +InputState.__ne__ = _InputState_ne InputState.__hash__ = lambda self: hash(int(self)) InputState.__repr__ = lambda self: f"{type(self).__name__}.{self.name}" InputState.__str__ = lambda self: self.name diff --git a/src/PyKey.cpp b/src/PyKey.cpp index 8cdefb3..54ea5ea 100644 --- a/src/PyKey.cpp +++ b/src/PyKey.cpp @@ -217,6 +217,14 @@ def _Key_eq(self, other): return int.__eq__(int(self), other) Key.__eq__ = _Key_eq + +def _Key_ne(self, other): + result = type(self).__eq__(self, other) + if result is NotImplemented: + return result + return not result + +Key.__ne__ = _Key_ne Key.__hash__ = lambda self: hash(int(self)) Key.__repr__ = lambda self: f"{type(self).__name__}.{self.name}" Key.__str__ = lambda self: self.name diff --git a/src/PyMouseButton.cpp b/src/PyMouseButton.cpp index 3f6ca74..95b85b4 100644 --- a/src/PyMouseButton.cpp +++ b/src/PyMouseButton.cpp @@ -89,6 +89,14 @@ def _MouseButton_eq(self, other): return int.__eq__(int(self), other) MouseButton.__eq__ = _MouseButton_eq + +def _MouseButton_ne(self, other): + result = type(self).__eq__(self, other) + if result is NotImplemented: + return result + return not result + +MouseButton.__ne__ = _MouseButton_ne MouseButton.__hash__ = lambda self: hash(int(self)) MouseButton.__repr__ = lambda self: f"{type(self).__name__}.{self.name}" MouseButton.__str__ = lambda self: self.name diff --git a/tests/cookbook/cookbook_main.py b/tests/cookbook/cookbook_main.py index c48c65b..b21150a 100644 --- a/tests/cookbook/cookbook_main.py +++ b/tests/cookbook/cookbook_main.py @@ -212,26 +212,26 @@ class CookbookLauncher: category = self.categories[self.selected_category] items = self.DEMOS[category] - if key == "Escape": + if key == mcrfpy.Key.ESCAPE: sys.exit(0) - elif key == "Left": + elif key == mcrfpy.Key.LEFT or key == mcrfpy.Key.A: self.selected_category = (self.selected_category - 1) % len(self.categories) # Clamp item selection to new category new_category = self.categories[self.selected_category] self.selected_item = min(self.selected_item, len(self.DEMOS[new_category]) - 1) self._update_selection() - elif key == "Right": + elif key == mcrfpy.Key.RIGHT or key == mcrfpy.Key.D: self.selected_category = (self.selected_category + 1) % len(self.categories) new_category = self.categories[self.selected_category] self.selected_item = min(self.selected_item, len(self.DEMOS[new_category]) - 1) self._update_selection() - elif key == "Up": + elif key == mcrfpy.Key.UP or key == mcrfpy.Key.W: self.selected_item = (self.selected_item - 1) % len(items) self._update_selection() - elif key == "Down": + elif key == mcrfpy.Key.DOWN or key == mcrfpy.Key.S: self.selected_item = (self.selected_item + 1) % len(items) self._update_selection() - elif key == "Enter": + elif key == mcrfpy.Key.ENTER or key == mcrfpy.Key.SPACE: self._run_selected_demo() def activate(self):