Skip to content

Commit

Permalink
Plugin fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
luboslenco committed Jan 17, 2025
1 parent 348ea60 commit 303f941
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 17 deletions.
18 changes: 13 additions & 5 deletions armorlab/sources/nodes_brush.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {
Expand Down
8 changes: 8 additions & 0 deletions armorpaint/sources/nodes_brush.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 8 additions & 8 deletions base/assets/plugins/export_gpl.js
Original file line number Diff line number Diff line change
@@ -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");
});
6 changes: 3 additions & 3 deletions base/assets/plugins/import_gpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
Expand Down Expand Up @@ -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");
});
2 changes: 1 addition & 1 deletion base/assets/plugins/import_txt.js
Original file line number Diff line number Diff line change
@@ -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);
}
Expand Down
2 changes: 2 additions & 0 deletions base/sources/plugin_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 303f941

Please sign in to comment.