Pixel-Composer/objects/_addon_custom/Create_0.gml

87 lines
2.0 KiB
Plaintext
Raw Normal View History

2023-05-03 21:42:17 +02:00
/// @description
event_inherited();
#region init
2023-06-17 14:30:49 +02:00
alarm[0] = 1;
2023-05-07 20:55:13 +02:00
function init(directory, _openDialog = true) {
2023-05-03 21:42:17 +02:00
ID = UUID_generate();
global.ADDON_ID[? ID] = self;
ready = false;
name = filename_name_only(directory);
thread = lua_create();
__addon_lua_setup(thread, self);
self.directory = directory;
var propPath = directory + "/meta.json";
2023-05-03 21:42:17 +02:00
context_menus = {};
panels = {};
2024-05-17 15:25:01 +02:00
2023-12-08 03:50:09 +01:00
if(file_exists_empty(propPath)) {
2023-05-03 21:42:17 +02:00
var meta = json_load_struct(propPath);
if(struct_has(meta, "panels")) {
panels = meta.panels;
2023-05-07 20:55:13 +02:00
if(_openDialog) {
var arr = variable_struct_get_names(panels);
2023-07-25 20:12:40 +02:00
for( var i = 0, n = array_length(arr); i < n; i++ ) {
2023-05-07 20:55:13 +02:00
var _key = arr[i];
var pane = panels[$ _key];
2023-05-03 21:42:17 +02:00
2023-05-07 20:55:13 +02:00
if(struct_has(pane, "main") && pane.main)
dialogPanelCall(new addonPanel(self, pane));
2023-05-03 21:42:17 +02:00
}
}
}
if(struct_has(meta, "context_menu_callbacks")) {
context_menus = meta.context_menu_callbacks;
var arr = variable_struct_get_names(context_menus);
2023-07-25 20:12:40 +02:00
for( var i = 0, n = array_length(arr); i < n; i++ ) {
2023-05-03 21:42:17 +02:00
var _call = ds_map_try_get(CONTEXT_MENU_CALLBACK, arr[i], []);
var _fnk = context_menus[$ arr[i]];
var _generator = new addonContextGenerator(self, _fnk);
array_push(_call, _generator);
CONTEXT_MENU_CALLBACK[? arr[i]] = _call;
}
}
}
scriptPath = directory + "/script.lua";
2023-12-08 03:50:09 +01:00
if(!file_exists_empty(scriptPath)) {
2023-05-03 21:42:17 +02:00
noti_warning(title + " Addon error: script.lua not found.");
return self;
}
lua_add_file(thread, scriptPath);
var runResult = lua_call(thread, "init");
array_push(ANIMATION_PRE, animationPreStep);
array_push(ANIMATION_POST, animationPostStep);
}
function animationPreStep() {
2024-03-15 13:38:08 +01:00
INLINE
2023-05-03 21:42:17 +02:00
if(!ready) return;
2024-03-15 13:38:08 +01:00
2023-05-03 21:42:17 +02:00
var runResult = lua_call(thread, "animationPreStep");
}
function animationPostStep() {
2024-03-15 13:38:08 +01:00
INLINE
2023-05-03 21:42:17 +02:00
if(!ready) return;
2024-03-15 13:38:08 +01:00
2023-05-03 21:42:17 +02:00
var runResult = lua_call(thread, "animationPostStep");
}
function callFunctions(fn) {
2024-03-15 13:38:08 +01:00
INLINE
if(!ready) return;
2023-05-03 21:42:17 +02:00
lua_call(thread, fn);
}
#endregion