more python cleanup
This commit is contained in:
@@ -7,25 +7,12 @@ extern "C" {
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Sprite action.
|
|
||||||
*/
|
|
||||||
struct z3_sprite_action {
|
|
||||||
const char* name; /**< Name of the action. */
|
|
||||||
uint8_t id; /**< ID of the action. */
|
|
||||||
|
|
||||||
const char** instructions; /**< Pointer to the instructions of the action. */
|
|
||||||
};
|
|
||||||
typedef struct z3_sprite_action z3_sprite_action;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Primitive of a sprite.
|
* @brief Primitive of a sprite.
|
||||||
*/
|
*/
|
||||||
struct z3_sprite {
|
struct z3_sprite {
|
||||||
const char* name; /**< Name of the sprite. */
|
const char* name; /**< Name of the sprite. */
|
||||||
uint8_t id; /**< ID of the sprite. */
|
uint8_t id; /**< ID of the sprite. */
|
||||||
|
|
||||||
z3_sprite_action* actions; /**< Pointer to the actions of the sprite. */
|
|
||||||
};
|
};
|
||||||
typedef struct z3_sprite z3_sprite;
|
typedef struct z3_sprite z3_sprite;
|
||||||
|
|
||||||
|
|||||||
@@ -1,141 +1,14 @@
|
|||||||
#include <boost/python.hpp>
|
#include <boost/python.hpp>
|
||||||
|
|
||||||
|
#include "base/extension.h"
|
||||||
#include "base/overworld.h"
|
#include "base/overworld.h"
|
||||||
#include "base/snes_color.h"
|
#include "base/snes_color.h"
|
||||||
#include "base/sprite.h"
|
#include "base/sprite.h"
|
||||||
#include "base/extension.h"
|
|
||||||
#include "yaze.h"
|
#include "yaze.h"
|
||||||
|
|
||||||
class PythonYazeExtensionWrapper {
|
|
||||||
public:
|
|
||||||
PythonYazeExtensionWrapper() : ext_() {
|
|
||||||
// Initialize function pointers to nullptr or default implementations
|
|
||||||
ext_.initialize = nullptr;
|
|
||||||
ext_.cleanup = nullptr;
|
|
||||||
ext_.manipulate_rom = nullptr;
|
|
||||||
ext_.extend_ui = nullptr;
|
|
||||||
ext_.register_commands = nullptr;
|
|
||||||
ext_.register_custom_tools = nullptr;
|
|
||||||
ext_.register_event_hooks = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* getName() const { return ext_.name; }
|
|
||||||
|
|
||||||
const char* getVersion() const { return ext_.version; }
|
|
||||||
|
|
||||||
void setName(const std::string& name) { ext_.name = name.c_str(); }
|
|
||||||
|
|
||||||
void setVersion(const std::string& version) {
|
|
||||||
ext_.version = version.c_str();
|
|
||||||
}
|
|
||||||
|
|
||||||
void setInitialize(boost::python::object func) {
|
|
||||||
ext_.initialize = &PythonYazeExtensionWrapper::initialize;
|
|
||||||
initializeFunc_ = func;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setCleanup(boost::python::object func) {
|
|
||||||
ext_.cleanup = &PythonYazeExtensionWrapper::cleanup;
|
|
||||||
cleanupFunc_ = func;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setManipulateRom(boost::python::object func) {
|
|
||||||
ext_.manipulate_rom = &PythonYazeExtensionWrapper::manipulate_rom;
|
|
||||||
manipulateRomFunc_ = func;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setExtendUI(boost::python::object func) {
|
|
||||||
ext_.extend_ui = &PythonYazeExtensionWrapper::extend_ui;
|
|
||||||
extendUIFunc_ = func;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setRegisterCommands(boost::python::object func) {
|
|
||||||
ext_.register_commands = &PythonYazeExtensionWrapper::register_commands;
|
|
||||||
registerCommandsFunc_ = func;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setRegisterCustomTools(boost::python::object func) {
|
|
||||||
ext_.register_custom_tools =
|
|
||||||
&PythonYazeExtensionWrapper::register_custom_tools;
|
|
||||||
registerCustomToolsFunc_ = func;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setRegisterEventHooks(boost::python::object func) {
|
|
||||||
ext_.register_event_hooks =
|
|
||||||
&PythonYazeExtensionWrapper::register_event_hooks;
|
|
||||||
registerEventHooksFunc_ = func;
|
|
||||||
}
|
|
||||||
|
|
||||||
yaze_extension* getExtension() { return &ext_; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
static void initialize(yaze_editor_context* context) {
|
|
||||||
boost::python::call<void>(initializeFunc_.ptr(), boost::python::ptr(context));
|
|
||||||
}
|
|
||||||
|
|
||||||
static void cleanup() { boost::python::call<void>(cleanupFunc_.ptr()); }
|
|
||||||
|
|
||||||
static void manipulate_rom(z3_rom* rom) {
|
|
||||||
boost::python::call<void>(manipulateRomFunc_.ptr(), boost::python::ptr(rom));
|
|
||||||
}
|
|
||||||
|
|
||||||
static void extend_ui(yaze_editor_context* context) {
|
|
||||||
boost::python::call<void>(extendUIFunc_.ptr(), boost::python::ptr(context));
|
|
||||||
}
|
|
||||||
|
|
||||||
static void register_commands() {
|
|
||||||
boost::python::call<void>(registerCommandsFunc_.ptr());
|
|
||||||
}
|
|
||||||
|
|
||||||
static void register_custom_tools() {
|
|
||||||
boost::python::call<void>(registerCustomToolsFunc_.ptr());
|
|
||||||
}
|
|
||||||
|
|
||||||
static void register_event_hooks(yaze_event_type event,
|
|
||||||
yaze_event_hook_func hook) {
|
|
||||||
boost::python::call<void>(registerEventHooksFunc_.ptr(), event, hook);
|
|
||||||
}
|
|
||||||
|
|
||||||
yaze_extension ext_;
|
|
||||||
static boost::python::object initializeFunc_;
|
|
||||||
static boost::python::object cleanupFunc_;
|
|
||||||
static boost::python::object manipulateRomFunc_;
|
|
||||||
static boost::python::object extendUIFunc_;
|
|
||||||
static boost::python::object registerCommandsFunc_;
|
|
||||||
static boost::python::object registerCustomToolsFunc_;
|
|
||||||
static boost::python::object registerEventHooksFunc_;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Static members initialization
|
|
||||||
boost::python::object PythonYazeExtensionWrapper::initializeFunc_;
|
|
||||||
boost::python::object PythonYazeExtensionWrapper::cleanupFunc_;
|
|
||||||
boost::python::object PythonYazeExtensionWrapper::manipulateRomFunc_;
|
|
||||||
boost::python::object PythonYazeExtensionWrapper::extendUIFunc_;
|
|
||||||
boost::python::object PythonYazeExtensionWrapper::registerCommandsFunc_;
|
|
||||||
boost::python::object PythonYazeExtensionWrapper::registerCustomToolsFunc_;
|
|
||||||
boost::python::object PythonYazeExtensionWrapper::registerEventHooksFunc_;
|
|
||||||
|
|
||||||
BOOST_PYTHON_MODULE(yaze_py) {
|
BOOST_PYTHON_MODULE(yaze_py) {
|
||||||
using namespace boost::python;
|
using namespace boost::python;
|
||||||
|
|
||||||
class_<PythonYazeExtensionWrapper>("YazeExtension")
|
|
||||||
.add_property("name", &PythonYazeExtensionWrapper::getName,
|
|
||||||
&PythonYazeExtensionWrapper::setName)
|
|
||||||
.add_property("version", &PythonYazeExtensionWrapper::getVersion,
|
|
||||||
&PythonYazeExtensionWrapper::setVersion)
|
|
||||||
.def("setInitialize", &PythonYazeExtensionWrapper::setInitialize)
|
|
||||||
.def("setCleanup", &PythonYazeExtensionWrapper::setCleanup)
|
|
||||||
.def("setManipulateRom", &PythonYazeExtensionWrapper::setManipulateRom)
|
|
||||||
.def("setExtendUI", &PythonYazeExtensionWrapper::setExtendUI)
|
|
||||||
.def("setRegisterCommands",
|
|
||||||
&PythonYazeExtensionWrapper::setRegisterCommands)
|
|
||||||
.def("setRegisterCustomTools",
|
|
||||||
&PythonYazeExtensionWrapper::setRegisterCustomTools)
|
|
||||||
.def("setRegisterEventHooks",
|
|
||||||
&PythonYazeExtensionWrapper::setRegisterEventHooks)
|
|
||||||
.def("getExtension", &PythonYazeExtensionWrapper::getExtension,
|
|
||||||
return_value_policy<reference_existing_object>());
|
|
||||||
|
|
||||||
class_<z3_rom>("z3_rom")
|
class_<z3_rom>("z3_rom")
|
||||||
.def_readonly("filename", &z3_rom::filename)
|
.def_readonly("filename", &z3_rom::filename)
|
||||||
.def_readonly("data", &z3_rom::data)
|
.def_readonly("data", &z3_rom::data)
|
||||||
@@ -152,14 +25,9 @@ BOOST_PYTHON_MODULE(yaze_py) {
|
|||||||
.def_readonly("size", &snes_palette::size)
|
.def_readonly("size", &snes_palette::size)
|
||||||
.def_readonly("colors", &snes_palette::colors);
|
.def_readonly("colors", &snes_palette::colors);
|
||||||
|
|
||||||
class_<z3_sprite_action>("z3_sprite_action")
|
|
||||||
.def_readonly("name", &z3_sprite_action::name)
|
|
||||||
.def_readonly("id", &z3_sprite_action::id);
|
|
||||||
|
|
||||||
class_<z3_sprite>("sprite")
|
class_<z3_sprite>("sprite")
|
||||||
.def_readonly("name", &z3_sprite::name)
|
.def_readonly("name", &z3_sprite::name)
|
||||||
.def_readonly("id", &z3_sprite::id)
|
.def_readonly("id", &z3_sprite::id);
|
||||||
.def_readonly("actions", &z3_sprite::actions);
|
|
||||||
|
|
||||||
class_<yaze_flags>("yaze_flags")
|
class_<yaze_flags>("yaze_flags")
|
||||||
.def_readwrite("debug", &yaze_flags::debug)
|
.def_readwrite("debug", &yaze_flags::debug)
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
find_package(PythonLibs REQUIRED)
|
||||||
find_package(Boost COMPONENTS python3 REQUIRED)
|
find_package(Boost COMPONENTS python3 REQUIRED)
|
||||||
|
|
||||||
# target x86_64 for module
|
# target x86_64 for module
|
||||||
|
|||||||
Reference in New Issue
Block a user