From 303f941abec78e05d6f22877cd94b5ad1bfe9838 Mon Sep 17 00:00:00 2001 From: luboslenco Date: Fri, 17 Jan 2025 09:51:53 +0100 Subject: [PATCH] Plugin fixes --- armorlab/sources/nodes_brush.ts | 18 +++++++++++++----- armorpaint/sources/nodes_brush.ts | 8 ++++++++ base/assets/plugins/export_gpl.js | 16 ++++++++-------- base/assets/plugins/import_gpl.js | 6 +++--- base/assets/plugins/import_txt.js | 2 +- base/sources/plugin_api.c | 2 ++ 6 files changed, 35 insertions(+), 17 deletions(-) diff --git a/armorlab/sources/nodes_brush.ts b/armorlab/sources/nodes_brush.ts index bbc2941eb..4d4b2760e 100644 --- a/armorlab/sources/nodes_brush.ts +++ b/armorlab/sources/nodes_brush.ts @@ -26,6 +26,19 @@ function nodes_brush_init() { map_set(nodes_brush_creates, "vector_node", vector_node_create); map_set(nodes_brush_creates, "color_node", color_node_create); + nodes_brush_list_init(); + + map_set(ui_nodes_custom_buttons, "inpaint_node_button", inpaint_node_button); + map_set(ui_nodes_custom_buttons, "text_to_photo_node_button", text_to_photo_node_button); + map_set(ui_nodes_custom_buttons, "tiling_node_button", tiling_node_button); + map_set(ui_nodes_custom_buttons, "variance_node_button", variance_node_button); +} + +function nodes_brush_list_init() { + if (nodes_brush_list != null) { + return; + } + nodes_brush_input = [ image_texture_node_def, rgb_node_def, @@ -44,11 +57,6 @@ function nodes_brush_init() { nodes_brush_input, nodes_brush_model ]; - - map_set(ui_nodes_custom_buttons, "inpaint_node_button", inpaint_node_button); - map_set(ui_nodes_custom_buttons, "text_to_photo_node_button", text_to_photo_node_button); - map_set(ui_nodes_custom_buttons, "tiling_node_button", tiling_node_button); - map_set(ui_nodes_custom_buttons, "variance_node_button", variance_node_button); } function nodes_brush_create_node(node_type: string): ui_node_t { diff --git a/armorpaint/sources/nodes_brush.ts b/armorpaint/sources/nodes_brush.ts index a1b92766c..fa0bf0bcc 100644 --- a/armorpaint/sources/nodes_brush.ts +++ b/armorpaint/sources/nodes_brush.ts @@ -22,6 +22,14 @@ function nodes_brush_init() { map_set(nodes_brush_creates, "vector_node", vector_node_create); map_set(nodes_brush_creates, "vector_math_node", vector_math_node_create); + nodes_brush_list_init(); +} + +function nodes_brush_list_init() { + if (nodes_brush_list != null) { + return; + } + nodes_brush_category0 = [ tex_image_node_def, input_node_def, diff --git a/base/assets/plugins/export_gpl.js b/base/assets/plugins/export_gpl.js index 193e8b7c3..a210b394d 100644 --- a/base/assets/plugins/export_gpl.js +++ b/base/assets/plugins/export_gpl.js @@ -1,24 +1,24 @@ function export_gpl(path, name, swatches) { - let o: string = ""; - o += "GIMP Palette\n"; - o += "Name: " + name + "\n"; - o += "# armorpaint.org\n"; - o += "#\n"; + let o = ""; + o += "GIMP Palette\\n"; + o += "Name: " + name + "\\n"; + o += "# armorpaint.org\\n"; + o += "#\\n"; for (let i = 0; i < swatches.length; ++i) { let swatch = swatches[i]; let rb = color_get_rb(swatch.base); let gb = color_get_gb(swatch.base); let bb = color_get_bb(swatch.base); - o += rb + " " + gb + " " + bb + "\n"; + o += rb + " " + gb + " " + bb + "\\n"; } iron_file_save_bytes(path, sys_string_to_buffer(o), o.length); } let plugin = plugin_create(); -path_swatch_exporters_set("gpl", export_gpl); +// path_swatch_exporters_set("gpl", export_gpl); plugin_notify_on_delete(plugin, function() { - path_swatch_exporters_delete("gpl"); + // path_swatch_exporters_delete("gpl"); }); diff --git a/base/assets/plugins/import_gpl.js b/base/assets/plugins/import_gpl.js index f879ee655..4ed537e8f 100644 --- a/base/assets/plugins/import_gpl.js +++ b/base/assets/plugins/import_gpl.js @@ -4,7 +4,7 @@ function import_gpl(path, replace_existing) { // let swatches: TSwatchColor[] = []; // let str: string = sys_buffer_to_string(b); - // let lines: string[] = string_split(str, "\n"); + // let lines: string[] = string_split(str, "\\n"); // // GIMP's color palette importer: https://gitlab.gnome.org/GNOME/gimp/-/blob/gimp-2-10/app/core/gimppalette-load.c#L39 // if (!starts_with(lines[0], "GIMP Palette")) { @@ -41,7 +41,7 @@ function import_gpl(path, replace_existing) { } let plugin = plugin_create(); -path_swatch_importers_set("gpl", import_gpl); +// path_swatch_importers_set("gpl", import_gpl); plugin_notify_on_delete(plugin, function() { - path_swatch_importers_delete("gpl"); + // path_swatch_importers_delete("gpl"); }); diff --git a/base/assets/plugins/import_txt.js b/base/assets/plugins/import_txt.js index cda164c53..1beaf6ef9 100644 --- a/base/assets/plugins/import_txt.js +++ b/base/assets/plugins/import_txt.js @@ -1,7 +1,7 @@ function import_txt(path) { let b = data_get_blob(path); - let filename = path.split("\\").pop().split("/").pop(); + let filename = path.split("\\\\").pop().split("/").pop(); ui_box_show_message(filename, buffer_to_string(b)); data_delete_blob(path); } diff --git a/base/sources/plugin_api.c b/base/sources/plugin_api.c index cedad6f91..43636fe16 100644 --- a/base/sources/plugin_api.c +++ b/base/sources/plugin_api.c @@ -654,12 +654,14 @@ FN(parser_material_parse_value_input) { extern any_array_t *nodes_brush_categories; extern any_array_t *nodes_brush_list; +void nodes_brush_list_init(); FN(nodes_brush_category_add) { char *category_name = (char *)JS_ToCString(ctx, argv[0]); any_array_push(nodes_brush_categories, category_name); size_t len; void *ab = JS_GetArrayBuffer(ctx, &len, argv[1]); buffer_t b = { .buffer = ab, .length = len, .capacity = len }; + nodes_brush_list_init(); any_array_push(nodes_brush_list, armpack_decode(&b)); return JS_UNDEFINED; }