extensions cleanup

This commit is contained in:
scawful
2024-08-20 22:40:14 -04:00
parent 7b33313281
commit d85530b14b
11 changed files with 70 additions and 250 deletions

91
src/base/extension.h Normal file
View File

@@ -0,0 +1,91 @@
#ifndef EXTENSION_INTERFACE_H
#define EXTENSION_INTERFACE_H
#ifdef __cplusplus
extern "C" {
#endif
#include "yaze.h"
typedef void (*yaze_initialize_func)(yaze_editor_context* context);
typedef void (*yaze_cleanup_func)(void);
typedef void (*yaze_extend_ui_func)(yaze_editor_context* context);
typedef void (*yaze_manipulate_rom_func)(z3_rom* rom);
typedef void (*yaze_command_func)(void);
typedef void (*yaze_event_hook_func)(void);
typedef enum {
YAZE_EVENT_ROM_LOADED,
YAZE_EVENT_ROM_SAVED,
YAZE_EVENT_SPRITE_MODIFIED,
YAZE_EVENT_PALETTE_CHANGED,
} yaze_event_type;
/**
* @brief Extension interface for Yaze.
*
* @details Yaze extensions can be written in C or Python.
*/
typedef struct yaze_extension {
const char* name;
const char* version;
/**
* @brief Function to initialize the extension.
*
* @details This function is called when the extension is loaded. It can be
* used to set up any resources or state needed by the extension.
*/
yaze_initialize_func initialize;
/**
* @brief Function to clean up the extension.
*
* @details This function is called when the extension is unloaded. It can be
* used to clean up any resources or state used by the extension.
*/
yaze_cleanup_func cleanup;
/**
* @brief Function to manipulate the ROM.
*
* @param rom The ROM to manipulate.
*
*/
yaze_manipulate_rom_func manipulate_rom;
/**
* @brief Function to extend the UI.
*
* @param context The editor context.
*
* @details This function is called when the extension is loaded. It can be
* used to add custom UI elements to the editor. The context parameter
* provides access to the project, command registry, event dispatcher, and
* ImGui context.
*/
yaze_extend_ui_func extend_ui;
/**
* @brief Register commands in the yaze_command_registry.
*/
yaze_command_func register_commands;
/**
* @brief Register custom tools in the yaze_command_registry.
*/
yaze_command_func register_custom_tools;
/**
* @brief Register event hooks in the yaze_event_dispatcher.
*/
void (*register_event_hooks)(yaze_event_type event,
yaze_event_hook_func hook);
} yaze_extension;
#ifdef __cplusplus
}
#endif
#endif // EXTENSION_INTERFACE_H

View File

@@ -0,0 +1,48 @@
#include <stdio.h>
#include "base/extension.h"
#include "yaze.h"
void my_extension_initialize(yaze_editor_context* context) {
printf("My Extension Initialized\n");
}
void my_extension_cleanup(void) { printf("My Extension Cleaned Up\n"); }
void my_extension_extend_ui(yaze_editor_context* context) {
// Add a custom tab or panel to the editor
}
void my_extension_manipulate_rom(z3_rom* rom) {
// Modify ROM data
}
void my_extension_register_commands(void) {
// Register custom commands
}
void my_extension_handle_file_format(void) {
// Handle custom file formats
}
void my_extension_register_event_hooks(yaze_event_type event,
yaze_event_hook_func hook) {
// Register event hooks for specific events
}
void my_extension_register_custom_tools(void) {
// Register custom tools or editors
}
yaze_extension* get_yaze_extension(void) {
static yaze_extension ext = {"My Extension",
"1.0",
my_extension_initialize,
my_extension_cleanup,
my_extension_manipulate_rom,
my_extension_extend_ui,
my_extension_register_commands,
my_extension_register_custom_tools,
my_extension_register_event_hooks};
return &ext;
}