From 3fe4f266bfed5d8f56104a01856b7193a099fff8 Mon Sep 17 00:00:00 2001 From: Tanasart <22589759+Ttanasart-pt@users.noreply.github.com> Date: Fri, 31 Mar 2023 11:59:08 +0700 Subject: [PATCH] Splice, Image replace update --- PixelComposer.resource_order | 1 + PixelComposer.yyp | 1 + .../o_dialog_file_name_collection/Draw_64.gml | 3 +- objects/o_dialog_scrollbox/Create_0.gml | 34 +++--- objects/o_main/Step_1.gml | 4 +- scripts/GmlLua/GmlLua.gml | 4 +- .../animation_controller.gml | 2 +- scripts/append_function/append_function.gml | 2 +- .../distribution_function.gml | 2 +- scripts/globals/globals.gml | 2 +- scripts/load_function/load_function.gml | 2 +- scripts/node_average/node_average.gml | 4 +- .../node_color_sampler/node_color_sampler.gml | 2 +- .../node_crop_content/node_crop_content.gml | 4 +- scripts/node_find_pixel/node_find_pixel.gml | 2 +- scripts/node_flood_fill/node_flood_fill.gml | 2 +- .../node_image_splice_sheet.gml | 31 +++-- scripts/node_registry/node_registry.gml | 12 +- .../node_seperate_shapes.gml | 4 +- .../node_surface_replace.gml | 8 +- scripts/node_value/node_value.gml | 6 +- scripts/node_wrap_mesh/node_wrap_mesh.gml | 8 +- scripts/panel_preview/panel_preview.gml | 4 +- scripts/string_eval/string_eval.gml | 4 +- scripts/string_eval_tree/string_eval_tree.gml | 107 ++++++++++++++++++ scripts/string_eval_tree/string_eval_tree.yy | 11 ++ .../string_hexadecimal/string_hexadecimal.gml | 9 +- .../surface_functions/surface_functions.gml | 37 ++++-- .../sh_surface_replace_fast_find.fsh | 13 ++- .../sh_surface_replace_find.fsh | 13 ++- 30 files changed, 255 insertions(+), 83 deletions(-) create mode 100644 scripts/string_eval_tree/string_eval_tree.gml create mode 100644 scripts/string_eval_tree/string_eval_tree.yy diff --git a/PixelComposer.resource_order b/PixelComposer.resource_order index b6cc0573b..c8f2618b2 100644 --- a/PixelComposer.resource_order +++ b/PixelComposer.resource_order @@ -1142,6 +1142,7 @@ {"name":"node_3d_prim_sphere","order":13,"path":"scripts/node_3d_prim_sphere/node_3d_prim_sphere.yy",}, {"name":"dialog_management","order":2,"path":"scripts/dialog_management/dialog_management.yy",}, {"name":"draw_shapes","order":10,"path":"scripts/draw_shapes/draw_shapes.yy",}, + {"name":"string_eval_tree","order":2,"path":"scripts/string_eval_tree/string_eval_tree.yy",}, {"name":"sh_surface_replace_fast_replace","order":3,"path":"shaders/sh_surface_replace_fast_replace/sh_surface_replace_fast_replace.yy",}, {"name":"node_solid","order":14,"path":"scripts/node_solid/node_solid.yy",}, {"name":"sh_blend_luma","order":19,"path":"shaders/sh_blend_luma/sh_blend_luma.yy",}, diff --git a/PixelComposer.yyp b/PixelComposer.yyp index de8516bb5..863034cc3 100644 --- a/PixelComposer.yyp +++ b/PixelComposer.yyp @@ -1688,6 +1688,7 @@ {"id":{"name":"dialog_management","path":"scripts/dialog_management/dialog_management.yy",},}, {"id":{"name":"draw_shapes","path":"scripts/draw_shapes/draw_shapes.yy",},}, {"id":{"name":"node_channels","path":"scripts/node_channels/node_channels.yy",},}, + {"id":{"name":"string_eval_tree","path":"scripts/string_eval_tree/string_eval_tree.yy",},}, {"id":{"name":"sh_surface_replace_fast_replace","path":"shaders/sh_surface_replace_fast_replace/sh_surface_replace_fast_replace.yy",},}, {"id":{"name":"node_solid","path":"scripts/node_solid/node_solid.yy",},}, {"id":{"name":"sh_blend_luma","path":"shaders/sh_blend_luma/sh_blend_luma.yy",},}, diff --git a/objects/o_dialog_file_name_collection/Draw_64.gml b/objects/o_dialog_file_name_collection/Draw_64.gml index 24434d547..d4d9f4ca4 100644 --- a/objects/o_dialog_file_name_collection/Draw_64.gml +++ b/objects/o_dialog_file_name_collection/Draw_64.gml @@ -87,9 +87,8 @@ bx += bw + ui(4); var txt = get_text("new_collection_meta_edit", "Edit metadata"); - if(buttonInstant(THEME.button_hide, bx, by, bw, bh, mouse_ui, sFOCUS, sHOVER, txt, THEME.hamburger) == 2) { + if(buttonInstant(THEME.button_hide, bx, by, bw, bh, mouse_ui, sFOCUS, sHOVER, txt, THEME.hamburger) == 2) doExpand(); - } #endregion #region metadata diff --git a/objects/o_dialog_scrollbox/Create_0.gml b/objects/o_dialog_scrollbox/Create_0.gml index 3b9f0d3af..e8e91e0c0 100644 --- a/objects/o_dialog_scrollbox/Create_0.gml +++ b/objects/o_dialog_scrollbox/Create_0.gml @@ -70,10 +70,14 @@ event_inherited(); var _dw = sc_content.surface_w; var _h = 0; var _ly = _y; - - var hovering = ""; + var hovering = ""; for(var i = 0; i < array_length(data); i++) { + var txt = data[i]; + var clickable = !string_starts_with(txt, "-"); + if(!clickable) + txt = string_delete(txt, 1, 1); + if(data[i] == -1) { draw_sprite_stretched(THEME.menu_separator, 0, ui(8), _ly, _dw - ui(16), ui(6)); _ly += ui(8); @@ -82,25 +86,27 @@ event_inherited(); continue; } - if(sc_content.hover && point_in_rectangle(_m[0], _m[1], 0, _ly + 1, _dw, _ly + hght - 1)) { - selecting = i; - hovering = data[i]; - } + if(clickable) { + if(sc_content.hover && point_in_rectangle(_m[0], _m[1], 0, _ly + 1, _dw, _ly + hght - 1)) { + selecting = i; + hovering = data[i]; + } - if(selecting == i) { - draw_sprite_stretched_ext(THEME.textbox, 3, 0, _ly, _dw, hght, COLORS.dialog_menubox_highlight, 1); + if(selecting == i) { + draw_sprite_stretched_ext(THEME.textbox, 3, 0, _ly, _dw, hght, COLORS.dialog_menubox_highlight, 1); - if(sc_content.active && (mouse_press(mb_left) || keyboard_check_pressed(vk_enter))) { - initVal = i; - instance_destroy(); + if(sc_content.active && (mouse_press(mb_left) || keyboard_check_pressed(vk_enter))) { + initVal = i; + instance_destroy(); + } } } - draw_set_text(f_p0, align, fa_center, COLORS._main_text); + draw_set_text(f_p0, align, fa_center, clickable? COLORS._main_text : COLORS._main_text_sub); if(align == fa_center) - draw_text_cut(_dw / 2, _ly + hght / 2, data[i], _dw); + draw_text_cut(_dw / 2, _ly + hght / 2, txt, _dw); else if(align == fa_left) - draw_text_cut(ui(8), _ly + hght / 2, data[i], _dw); + draw_text_cut(ui(8), _ly + hght / 2, txt, _dw); _ly += hght; _h += hght; diff --git a/objects/o_main/Step_1.gml b/objects/o_main/Step_1.gml index 0e81efcce..3d1697ccd 100644 --- a/objects/o_main/Step_1.gml +++ b/objects/o_main/Step_1.gml @@ -84,9 +84,9 @@ Render(true); ANIMATOR.frame_progress = false; } else { - if(UPDATE & RENDER_TYPE.full) { + if(UPDATE & RENDER_TYPE.full) Render(); - } else if(UPDATE & RENDER_TYPE.partial) + else if(UPDATE & RENDER_TYPE.partial) Render(true); } UPDATE = RENDER_TYPE.none; diff --git a/scripts/GmlLua/GmlLua.gml b/scripts/GmlLua/GmlLua.gml index 30024a6bc..a5ff554b7 100644 --- a/scripts/GmlLua/GmlLua.gml +++ b/scripts/GmlLua/GmlLua.gml @@ -66,11 +66,11 @@ function __lua_set_color_alpha(color = c_white, alpha = 1) { function __lua_get_color(_x, _y) { var surf = surface_get_target(); if(!is_surface(surf)) return 0; - return surface_getpixel_ext(surf, _x, _y); + return surface_get_pixel_ext(surf, _x, _y); } function __lua_get_color_surface(surface, _x, _y) { if(!is_surface(surface)) return; - return surface_getpixel_ext(surface, _x, _y); + return surface_get_pixel_ext(surface, _x, _y); } function __lua_color_make_rgb(r, g, b, normalize = false) { diff --git a/scripts/animation_controller/animation_controller.gml b/scripts/animation_controller/animation_controller.gml index c0d03907e..1b9240cf3 100644 --- a/scripts/animation_controller/animation_controller.gml +++ b/scripts/animation_controller/animation_controller.gml @@ -29,7 +29,7 @@ if(_c != current_frame) { frame_progress = true; time_since_last_frame = 0; - UPDATE = RENDER_TYPE.full; + UPDATE |= RENDER_TYPE.full; } else frame_progress = false; } diff --git a/scripts/append_function/append_function.gml b/scripts/append_function/append_function.gml index 32869f6be..2543c4e5b 100644 --- a/scripts/append_function/append_function.gml +++ b/scripts/append_function/append_function.gml @@ -129,7 +129,7 @@ function __APPEND_MAP(_map, context = PANEL_GRAPH.getCurrentContext()) { APPENDING = false; PANEL_ANIMATION.updatePropertyList(); - UPDATE = RENDER_TYPE.full; + UPDATE |= RENDER_TYPE.full; if(ds_map_exists(_map, "metadata")) { var meta = _map[? "metadata"]; diff --git a/scripts/distribution_function/distribution_function.gml b/scripts/distribution_function/distribution_function.gml index dd5cb16d1..c3c6eb24c 100644 --- a/scripts/distribution_function/distribution_function.gml +++ b/scripts/distribution_function/distribution_function.gml @@ -10,7 +10,7 @@ function get_point_from_dist(distMap, attempt = 4) { var _x = irandom(w - 1); var _y = irandom(h - 1); - var p = surface_getpixel(distMap, _x, _y); + var p = surface_get_pixel(distMap, _x, _y); var r = color_get_red(p); if(r > v) { diff --git a/scripts/globals/globals.gml b/scripts/globals/globals.gml index ba4674f64..5d45e023b 100644 --- a/scripts/globals/globals.gml +++ b/scripts/globals/globals.gml @@ -33,7 +33,7 @@ globalvar VERSION, SAVEFILE_VERSION, VERSION_STRING; VERSION = 1140; SAVEFILE_VERSION = 1400; - VERSION_STRING = "1.14.0pr7"; + VERSION_STRING = "1.14.0pr8"; globalvar NODES, NODE_MAP, APPEND_MAP, HOTKEYS, HOTKEY_CONTEXT, NODE_INSTANCES; diff --git a/scripts/load_function/load_function.gml b/scripts/load_function/load_function.gml index 943c02ca6..03f613805 100644 --- a/scripts/load_function/load_function.gml +++ b/scripts/load_function/load_function.gml @@ -183,7 +183,7 @@ function __LOAD_PATH(path, readonly = false, safe_mode = false) { log_warning("LOAD, connect", exception_print(e)); } - UPDATE = RENDER_TYPE.full; + UPDATE |= RENDER_TYPE.full; LOADING = false; MODIFIED = false; diff --git a/scripts/node_average/node_average.gml b/scripts/node_average/node_average.gml index 7a8c48981..34be116e6 100644 --- a/scripts/node_average/node_average.gml +++ b/scripts/node_average/node_average.gml @@ -63,12 +63,12 @@ function Node_Average(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) c } shader_reset(); - cc = surface_getpixel(_Surf[!_ind], 0, 0); + cc = surface_get_pixel(_Surf[!_ind], 0, 0); surface_free(_Surf[0]); surface_free(_Surf[1]); } else - cc = surface_getpixel(inSurf, 0, 0); + cc = surface_get_pixel(inSurf, 0, 0); surface_set_target(_outSurf); draw_clear(cc); diff --git a/scripts/node_color_sampler/node_color_sampler.gml b/scripts/node_color_sampler/node_color_sampler.gml index f96c45025..661b90335 100644 --- a/scripts/node_color_sampler/node_color_sampler.gml +++ b/scripts/node_color_sampler/node_color_sampler.gml @@ -66,7 +66,7 @@ function Node_Sampler(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) c if(px >= ww) continue; if(py >= hh) continue; - var cc = surface_getpixel(_surf, px, py); + var cc = surface_get_pixel(_surf, px, py); r += color_get_red(cc); g += color_get_green(cc); diff --git a/scripts/node_crop_content/node_crop_content.gml b/scripts/node_crop_content/node_crop_content.gml index 446c84bd5..c4dbbad0b 100644 --- a/scripts/node_crop_content/node_crop_content.gml +++ b/scripts/node_crop_content/node_crop_content.gml @@ -71,8 +71,8 @@ function Node_Crop_Content(_x, _y, _group = noone) : Node(_x, _y, _group) constr shader_reset(); } - var minBox = surface_getpixel_ext(temp_surface[DIMENSION.width] , 0, 0); - var maxBox = surface_getpixel_ext(temp_surface[DIMENSION.height], 0, 0); + var minBox = surface_get_pixel_ext(temp_surface[DIMENSION.width] , 0, 0); + var maxBox = surface_get_pixel_ext(temp_surface[DIMENSION.height], 0, 0); var _minx = max(0, color_get_red(minBox) * 256 + color_get_green(minBox) - 1); var _miny = max(0, color_get_blue(minBox) * 256 + color_get_alpha(minBox) - 1); diff --git a/scripts/node_find_pixel/node_find_pixel.gml b/scripts/node_find_pixel/node_find_pixel.gml index 78fde5700..ff70bd90c 100644 --- a/scripts/node_find_pixel/node_find_pixel.gml +++ b/scripts/node_find_pixel/node_find_pixel.gml @@ -34,7 +34,7 @@ function Node_Find_Pixel(_x, _y, _group = noone) : Node_Processor(_x, _y, _group shader_reset(); surface_reset_target(); - var pos = surface_getpixel(temp_surface[0], 0, 0); + var pos = surface_get_pixel(temp_surface[0], 0, 0); var _x = round(color_get_red(pos) / 255 * surface_get_width(_surf)); var _y = round(color_get_green(pos) / 255 * surface_get_height(_surf)); diff --git a/scripts/node_flood_fill/node_flood_fill.gml b/scripts/node_flood_fill/node_flood_fill.gml index 6c4f0f299..e808692a7 100644 --- a/scripts/node_flood_fill/node_flood_fill.gml +++ b/scripts/node_flood_fill/node_flood_fill.gml @@ -51,7 +51,7 @@ function Node_Flood_Fill(_x, _y, _group = noone) : Node_Processor(_x, _y, _group var _thr = _data[6]; var _dia = _data[7]; - var _filC = surface_getpixel_ext(inSurf, _pos[0], _pos[1]); + var _filC = surface_get_pixel_ext(inSurf, _pos[0], _pos[1]); var sw = surface_get_width(inSurf); var sh = surface_get_height(inSurf); diff --git a/scripts/node_image_splice_sheet/node_image_splice_sheet.gml b/scripts/node_image_splice_sheet/node_image_splice_sheet.gml index 254d83ac1..1aea7d195 100644 --- a/scripts/node_image_splice_sheet/node_image_splice_sheet.gml +++ b/scripts/node_image_splice_sheet/node_image_splice_sheet.gml @@ -29,7 +29,7 @@ function Node_Image_Sheet(_x, _y, _group = noone) : Node(_x, _y, _group) constru inputs[| 9] = nodeValue("Orientation", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0) .setDisplay(VALUE_DISPLAY.enum_scroll, [ "Horizontal", "Vertical"]); - inputs[| 10] = nodeValue("Auto fill", self, JUNCTION_CONNECT.input, VALUE_TYPE.trigger, 0) + inputs[| 10] = nodeValue("Auto fill", self, JUNCTION_CONNECT.input, VALUE_TYPE.trigger, 0, "Automatically set amount based on sprite size.") .setDisplay(VALUE_DISPLAY.button, [ function() { var _sur = inputs[| 0].getValue(); if(!is_surface(_sur) || _sur == DEF_SURFACE) return; @@ -62,11 +62,16 @@ function Node_Image_Sheet(_x, _y, _group = noone) : Node(_x, _y, _group) constru }, "Sync frames"] ); inputs[| 12] = nodeValue("Filter empty output", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false); + + inputs[| 13] = nodeValue("Filtered Pixel", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0) + .setDisplay(VALUE_DISPLAY.enum_scroll, [ "Transparent", "Color" ]); + + inputs[| 14] = nodeValue("Filtered Color", self, JUNCTION_CONNECT.input, VALUE_TYPE.color, c_black) input_display_list = [ - ["Sprite", false], 0, 1, 6, 10, - ["Sheet", false], 3, 9, 4, 5, - ["Output", false], 7, 8, 12, 11 + ["Sprite", false], 0, 1, 6, + ["Sheet", false], 3, 10, 9, 4, 5, + ["Output", false], 7, 8, 12, 13, 14, 11 ]; outputs[| 0] = nodeValue("Surface out", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone); @@ -256,9 +261,14 @@ function Node_Image_Sheet(_x, _y, _group = noone) : Node(_x, _y, _group) constru } static step = function() { - var _out = inputs[| 7].getValue(); + var _out = inputs[| 7].getValue(); + var _filt = inputs[| 12].getValue(); + var _flty = inputs[| 13].getValue(); + inputs[| 11].setVisible(!_out); inputs[| 8].setVisible(!_out); + inputs[| 13].setVisible(_filt); + inputs[| 14].setVisible(_filt && _flty); } static onInspector1Update = function() { @@ -284,6 +294,9 @@ function Node_Image_Sheet(_x, _y, _group = noone) : Node(_x, _y, _group) constru var hh = _dim[1] + _pad[1] + _pad[3]; var _filt = inputs[| 12].getValue(); + var _fltp = inputs[| 13].getValue(); + var _flcl = inputs[| 14].getValue(); + var cDep = attrDepth(); curr_dim = _dim; curr_amo = is_array(_amo)? _amo : [1, 1]; @@ -323,9 +336,13 @@ function Node_Image_Sheet(_x, _y, _group = noone) : Node(_x, _y, _group) constru buffer_get_surface(_buff, _empS, 0); buffer_seek(_buff, buffer_seek_start, 0); var empty = true; - var c0 = buffer_read(_buff, buffer_u32) & ~(0b11111111 << 24); + repeat(filSize * filSize - 1) { - if(buffer_read(_buff, buffer_u32) & ~(0b11111111 << 24) != c0) { + var c = buffer_read(_buff, buffer_u32); + if(_fltp == 0 && ((c & 0xFF000000) >> 24) != 0) { + empty = false; + break; + } else if(_fltp == 1 && (c & 0x00FFFFFF) != _flcl) { empty = false; break; } diff --git a/scripts/node_registry/node_registry.gml b/scripts/node_registry/node_registry.gml index 89ff39418..9a852baaa 100644 --- a/scripts/node_registry/node_registry.gml +++ b/scripts/node_registry/node_registry.gml @@ -653,11 +653,11 @@ function NodeObject(_name, _spr, _node, _create, tags = []) constructor { global.SURFACE_FORMAT_NAME = []; for( var i = 0; i < array_length(surface_format); i++ ) { - if(surface_format_is_supported(surface_format[i])) { - array_push(global.SURFACE_FORMAT, surface_format[i]); - array_push(global.SURFACE_FORMAT_NAME, surface_format_name[i]); - } else - log_message("WARNING", "Surface format [" + surface_format_name[i] + "] not supported in this device."); + var sup = surface_format_is_supported(surface_format[i]); + array_push(global.SURFACE_FORMAT, surface_format[i]); + array_push(global.SURFACE_FORMAT_NAME, (sup? "" : "-") + surface_format_name[i]); + + if(!sup) log_message("WARNING", "Surface format [" + surface_format_name[i] + "] not supported in this device."); } global.SURFACE_FORMAT_NAME_PROCESS = [ "Input" ]; @@ -665,8 +665,8 @@ function NodeObject(_name, _spr, _node, _create, tags = []) constructor { } function attribute_surface_depth(label = true) { - attributes[? "color_depth"] = inputs[| 0].type == VALUE_TYPE.surface? 0 : 1; depth_array = inputs[| 0].type == VALUE_TYPE.surface? global.SURFACE_FORMAT_NAME_PROCESS : global.SURFACE_FORMAT_NAME; + attributes[? "color_depth"] = array_find(depth_array, "8 bit RGBA"); if(label) array_push(attributeEditors, "Surface"); array_push(attributeEditors, ["Color depth", "color_depth", diff --git a/scripts/node_seperate_shapes/node_seperate_shapes.gml b/scripts/node_seperate_shapes/node_seperate_shapes.gml index 476786ace..e07fee953 100644 --- a/scripts/node_seperate_shapes/node_seperate_shapes.gml +++ b/scripts/node_seperate_shapes/node_seperate_shapes.gml @@ -122,7 +122,7 @@ function Node_Seperate_Shape(_x, _y, _group = noone) : Node(_x, _y, _group) cons BLEND_NORMAL; surface_reset_target(); - var px = surface_getpixel(_pixel_surface, 0, 0); + var px = surface_get_pixel(_pixel_surface, 0, 0); if(px == 0) return; @@ -144,7 +144,7 @@ function Node_Seperate_Shape(_x, _y, _group = noone) : Node(_x, _y, _group) cons DRAW_CLEAR BLEND_OVERRIDE; shader_set(sh_seperate_shape_sep); - var ccx = surface_getpixel_ext(_pixel_surface, 1 + i, 0); + var ccx = surface_get_pixel_ext(_pixel_surface, 1 + i, 0); var alpha = (ccx >> 24) & 255; var blue = (ccx >> 16) & 255; var green = (ccx >> 8) & 255; diff --git a/scripts/node_surface_replace/node_surface_replace.gml b/scripts/node_surface_replace/node_surface_replace.gml index e26baa8b4..d32120140 100644 --- a/scripts/node_surface_replace/node_surface_replace.gml +++ b/scripts/node_surface_replace/node_surface_replace.gml @@ -2,12 +2,12 @@ function Node_Surface_Replace(_x, _y, _group = noone) : Node_Processor(_x, _y, _ name = "Replace Image"; preview_channel = 1; - inputs[| 0] = nodeValue("Base image", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, noone ); + inputs[| 0] = nodeValue("Base Image", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, noone ); - inputs[| 1] = nodeValue("Target image", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, noone ) + inputs[| 1] = nodeValue("Target Image", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, noone ) .setArrayDepth(1); - inputs[| 2] = nodeValue("Replacement image", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, noone ) + inputs[| 2] = nodeValue("Replacement Image", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, noone ) .setArrayDepth(1); inputs[| 3] = nodeValue("Threshold", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0.1 ) @@ -17,7 +17,7 @@ function Node_Surface_Replace(_x, _y, _group = noone) : Node_Processor(_x, _y, _ inputs[| 5] = nodeValue("Fast Mode", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, true ) - outputs[| 0] = nodeValue("Surface out", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone); + outputs[| 0] = nodeValue("Surface Out", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone); input_display_list = [ ["Surface", true], 0, 1, 2, diff --git a/scripts/node_value/node_value.gml b/scripts/node_value/node_value.gml index f6e168af2..b869abd28 100644 --- a/scripts/node_value/node_value.gml +++ b/scripts/node_value/node_value.gml @@ -396,7 +396,7 @@ function NodeValue(_name, _node, _connect, _type, _value, _tooltip = "") constru global_edit = new textBox(TEXTBOX_INPUT.text, function(str) { global_key = str; node.triggerRender(); - UPDATE = RENDER_TYPE.partial; + UPDATE |= RENDER_TYPE.partial; }); global_edit.boxColor = COLORS._main_value_positive; global_edit.align = fa_left; @@ -1163,7 +1163,7 @@ function NodeValue(_name, _node, _connect, _type, _value, _tooltip = "") constru if(_update) node.valueUpdate(index); node.clearCacheForward(); - UPDATE = RENDER_TYPE.partial; + UPDATE |= RENDER_TYPE.partial; } cache_array[0] = false; @@ -1257,7 +1257,7 @@ function NodeValue(_name, _node, _connect, _type, _value, _tooltip = "") constru node.triggerRender(); node.clearCacheForward(); - UPDATE = RENDER_TYPE.partial; + UPDATE |= RENDER_TYPE.partial; } cache_array[0] = false; diff --git a/scripts/node_wrap_mesh/node_wrap_mesh.gml b/scripts/node_wrap_mesh/node_wrap_mesh.gml index 642d46f4c..8fe328c4a 100644 --- a/scripts/node_wrap_mesh/node_wrap_mesh.gml +++ b/scripts/node_wrap_mesh/node_wrap_mesh.gml @@ -308,10 +308,10 @@ function Node_Mesh_Warp(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) if(useArray) { fill = true; } else { - var c0 = surface_getpixel(cont, j * gw, i * gh); - var c1 = surface_getpixel(cont, j * gw - 1, i * gh); - var c2 = surface_getpixel(cont, j * gw, i * gh - 1); - var c3 = surface_getpixel(cont, j * gw - 1, i * gh - 1); + var c0 = surface_get_pixel(cont, j * gw, i * gh); + var c1 = surface_get_pixel(cont, j * gw - 1, i * gh); + var c2 = surface_get_pixel(cont, j * gw, i * gh - 1); + var c3 = surface_get_pixel(cont, j * gw - 1, i * gh - 1); fill = c0 + c1 + c2 + c3 > 0; } diff --git a/scripts/panel_preview/panel_preview.gml b/scripts/panel_preview/panel_preview.gml index de398b3c4..dc18d82a8 100644 --- a/scripts/panel_preview/panel_preview.gml +++ b/scripts/panel_preview/panel_preview.gml @@ -437,7 +437,7 @@ function Panel_Preview() : PanelContent() constructor { sample_y = floor((my - canvas_y) / canvas_s); var surf = getNodePreviewSurface(); if(is_surface(surf)) - sample_color = surface_getpixel_ext(surf, sample_x, sample_y); + sample_color = surface_get_pixel_ext(surf, sample_x, sample_y); } } @@ -716,7 +716,7 @@ function Panel_Preview() : PanelContent() constructor { var cy = ui(10); var cw = ui(32); var ch = scHeight - ui(16); - + if(sample_color != noone) { draw_set_color(sample_color); draw_rectangle(cx, cy, cx + cw, cy + ch, false); diff --git a/scripts/string_eval/string_eval.gml b/scripts/string_eval/string_eval.gml index 463de3d4b..f32731b9a 100644 --- a/scripts/string_eval/string_eval.gml +++ b/scripts/string_eval/string_eval.gml @@ -1,4 +1,4 @@ -#region evaluator +#region data global.EQUATION_PRES = ds_map_create(); global.EQUATION_PRES[? "+"] = 1; global.EQUATION_PRES[? "-"] = 1; @@ -12,7 +12,9 @@ global.EQUATION_PRES[? "round"] = 5; global.EQUATION_PRES[? "ceil"] = 5; global.EQUATION_PRES[? "floor"] = 5; +#endregion +#region evaluator function evaluateFunction(fx, params = {}) { var pres = global.EQUATION_PRES; var vl = ds_stack_create(); diff --git a/scripts/string_eval_tree/string_eval_tree.gml b/scripts/string_eval_tree/string_eval_tree.gml new file mode 100644 index 000000000..087ea1fee --- /dev/null +++ b/scripts/string_eval_tree/string_eval_tree.gml @@ -0,0 +1,107 @@ +#region evaluator + function __fucnTree(symbol, l = noone, r = noone) constructor { + self.symbol = symbol; + self.l = l; + self.r = r; + isFunc = false; + + static eval = function() { + var v1 = is_struct(l)? l.eval() : l; + var v2 = is_struct(r)? r.eval() : r; + + switch(symbol) { + case "+": return v1 + v2; + case "-": return v1 - v2; + case "*": return v1 * v2; + case "^": return power(v1, v2); + case "/": return v1 / v2; + + case "sin" : return sin(v1); + case "cos" : return cos(v1); + case "tan" : return tan(v1); + case "abs" : return abs(v1); + case "round" : return round(v1); + case "ceil" : return ceil(v1); + case "floor" : return floor(v1); + } + + return 0; + } + } + + function evaluateFunctionTree(fx, params = {}) { + var pres = global.EQUATION_PRES; + var vl = ds_stack_create(); + var op = ds_stack_create(); + + fx = string_replace_all(fx, " ", ""); + fx = string_replace_all(fx, "\n", ""); + + var len = string_length(fx); + var l = 1; + var ch, cch; + + while(l <= len) { + ch = string_char_at(fx, l); + + if(ds_map_exists(pres, ch)) { + if(ds_stack_empty(op)) ds_stack_push(op, ch); + else { + if(pres[? ch] > pres[? ds_stack_top(op)] || ds_stack_top(op) == "(") ds_stack_push(op, ch); + else { + while(pres[? ch] <= pres[? ds_stack_top(op)] && !ds_stack_empty(op)) { + ds_stack_push(vl, evalToken(ds_stack_pop(op), vl)); + } + ds_stack_push(op, ch); + } + } + + l++; + } else if (ch == "(") { + ds_stack_push(op, ch); + l++; + } else if (ch == ")") { + while(ds_stack_top(op) != "(" && !ds_stack_empty(op)) { + ds_stack_push(vl, evalToken(ds_stack_pop(op), vl)); + } + ds_stack_pop(op); + l++; + } else { + var vsl = ""; + + while(l <= len) { + cch = string_char_at(fx, l); + if(ds_map_exists(pres, cch) || cch == ")" || cch == "(") break; + + vsl += cch; + l++; + } + + if(vsl == "") continue; + + if(ds_map_exists(pres, vsl)) { + ds_stack_push(op, vsl); + } else { + switch(vsl) { + case "e": ds_stack_push(vl, 2.71828); break; + case "pi": ds_stack_push(vl, pi); break; + + default : + if(variable_struct_exists(params, vsl)) + ds_stack_push(vl, variable_struct_get(params, vsl)); + else + ds_stack_push(vl, toNumber(vsl)); + break; + } + } + } + } + + while(!ds_stack_empty(op)) { + ds_stack_push(vl, evalToken(ds_stack_pop(op), vl)); + } + ds_stack_destroy(op); + + return ds_stack_empty(vl)? 0 : ds_stack_pop(vl); + } +#endregion \ No newline at end of file diff --git a/scripts/string_eval_tree/string_eval_tree.yy b/scripts/string_eval_tree/string_eval_tree.yy new file mode 100644 index 000000000..770b33436 --- /dev/null +++ b/scripts/string_eval_tree/string_eval_tree.yy @@ -0,0 +1,11 @@ +{ + "resourceType": "GMScript", + "resourceVersion": "1.0", + "name": "string_eval_tree", + "isCompatibility": false, + "isDnD": false, + "parent": { + "name": "eval", + "path": "folders/functions/eval.yy", + }, +} \ No newline at end of file diff --git a/scripts/string_hexadecimal/string_hexadecimal.gml b/scripts/string_hexadecimal/string_hexadecimal.gml index 01a789960..011305de6 100644 --- a/scripts/string_hexadecimal/string_hexadecimal.gml +++ b/scripts/string_hexadecimal/string_hexadecimal.gml @@ -33,10 +33,11 @@ function number_to_hex(val) { } function color_get_hex(color, alpha = false) { - var r = color_get_red(color); - var g = color_get_green(color); - var b = color_get_blue(color); - var a = color_get_alpha(color); + var arr = is_array(color) && array_length(color) == 4; + var r = arr? round(color[0] * 256) : color_get_red(color); + var g = arr? round(color[1] * 256) : color_get_green(color); + var b = arr? round(color[2] * 256) : color_get_blue(color); + var a = arr? round(color[3] * 256) : color_get_alpha(color); var hex = number_to_hex(r) + number_to_hex(g) + number_to_hex(b) + (alpha? " " + number_to_hex(a) : ""); return hex; diff --git a/scripts/surface_functions/surface_functions.gml b/scripts/surface_functions/surface_functions.gml index a6b968ae2..8048ffa69 100644 --- a/scripts/surface_functions/surface_functions.gml +++ b/scripts/surface_functions/surface_functions.gml @@ -47,14 +47,17 @@ function surface_save_safe(surface, path) { var f = surface_get_format(surface); var w = surface_get_width(surface); var h = surface_get_height(surface); - var s = noone; + var s = surface_create(w, h, surface_rgba8unorm); switch(f) { case surface_rgba4unorm : case surface_rgba8unorm : case surface_rgba16float : case surface_rgba32float : - surface_save(surface, path); + surface_set_shader(s, sh_draw_normal); + draw_surface(surface, 0, 0); + surface_reset_shader(); + surface_save(s, path); return; case surface_r8unorm : s = surface_create(w, h, surface_rgba8unorm); @@ -69,14 +72,9 @@ function surface_save_safe(surface, path) { return; } - surface_set_target(s); - shader_set(sh_draw_single_channel); - DRAW_CLEAR - BLEND_OVERRIDE - draw_surface(s, 0, 0); - BLEND_NORMAL - shader_reset(); - surface_reset_target(); + surface_set_shader(s, sh_draw_single_channel); + draw_surface(surface, 0, 0); + surface_reset_shader(); surface_save(s, path); surface_free(s); @@ -105,6 +103,25 @@ function surface_verify(surf, w, h, format = surface_rgba8unorm) { return surface_size_to(surf, w, h, format); } +//get +function surface_get_pixel(surface, _x, _y) { + if(!is_surface(surface)) return; + var f = surface_get_format(surface); + var px = surface_getpixel(surface, _x, _y); + + if(is_real(px)) return px; + return round(px[0] * (255 * power(256, 0))) + round(px[1] * (255 * power(256, 1))) + round(px[2] * (255 * power(256, 2))); +} + +function surface_get_pixel_ext(surface, _x, _y) { + if(!is_surface(surface)) return; + var f = surface_get_format(surface); + var px = surface_getpixel_ext(surface, _x, _y); + + if(is_real(px)) return px; + return round(px[0] * (255 * power(256, 0))) + round(px[1] * (255 * power(256, 1))) + round(px[2] * (255 * power(256, 2))) + round(px[3] * (255 * power(256, 3))); +} + //create function surface_create_size(surface, format = surface_rgba8unorm) { var s = surface_create_valid(surface_get_width(surface), surface_get_height(surface), format); diff --git a/shaders/sh_surface_replace_fast_find/sh_surface_replace_fast_find.fsh b/shaders/sh_surface_replace_fast_find/sh_surface_replace_fast_find.fsh index e98b951fe..2971fa0af 100644 --- a/shaders/sh_surface_replace_fast_find/sh_surface_replace_fast_find.fsh +++ b/shaders/sh_surface_replace_fast_find/sh_surface_replace_fast_find.fsh @@ -20,6 +20,7 @@ void main() { vec2 px = v_vTexcoord * dimension; float pixels_count = target_dim.x * target_dim.y; float target_pixels = pixels_count * (1. - threshold); + float content_px = 0.; float match = 0.; vec2 baseTx = 1. / dimension; vec2 targTx = 1. / target_dim; @@ -28,11 +29,14 @@ void main() { for( float i = 0.; i < target_dim.x; i++ ) for( float j = 0.; j < target_dim.y; j++ ) { + vec4 targ = texture2D( target, vec2(i, j) * targTx ); + if(targ.a == 0.) continue; + vec2 bpx = px + vec2(i, j); vec4 base = texture2D( gm_BaseTexture, bpx * baseTx ); - vec4 targ = texture2D( target, vec2(i, j) * targTx ); - if(distance(base.rgb * base.a, targ.rgb * targ.a) <= threshold) { + content_px++; + if(distance(base, targ) <= 2. * threshold) { match++; if(match >= target_pixels) { gl_FragColor = vec4(1., index, 0., 1.); @@ -41,5 +45,8 @@ void main() { } } - //gl_FragColor = vec4(match / pixels_count, index, 0., 1.); + if(match / content_px >= (1. - threshold)) { + gl_FragColor = vec4(1., index, 0., 1.); + return; + } } diff --git a/shaders/sh_surface_replace_find/sh_surface_replace_find.fsh b/shaders/sh_surface_replace_find/sh_surface_replace_find.fsh index dfab41c5a..0f12fb618 100644 --- a/shaders/sh_surface_replace_find/sh_surface_replace_find.fsh +++ b/shaders/sh_surface_replace_find/sh_surface_replace_find.fsh @@ -18,18 +18,22 @@ float matchTemplate(vec2 pos) { float match = 0.; vec2 baseTx = 1. / dimension; vec2 targTx = 1. / target_dim; + float content_px = 0.; for( float i = 0.; i < target_dim.x; i++ ) for( float j = 0.; j < target_dim.y; j++ ) { + vec4 targ = texture2D( target, vec2(i, j) * targTx ); + if(targ.a == 0.) continue; + vec2 bpx = pos + vec2(i, j); vec4 base = texture2D( gm_BaseTexture, bpx * baseTx ); - vec4 targ = texture2D( target, vec2(i, j) * targTx ); - if(distance(base.rgb * base.a, targ.rgb * targ.a) <= threshold) + content_px++; + if(distance(base, targ) <= 2. * threshold) match++; } - return match; + return match / content_px; } void main() { @@ -41,7 +45,6 @@ void main() { vec2 px = v_vTexcoord * dimension; - float target_pixels = target_dim.x * target_dim.y * (1. - threshold); float match = 0.; vec2 matchPos = vec2(0., 0.); vec2 matchUv = vec2(0., 0.); @@ -60,5 +63,5 @@ void main() { } } - gl_FragColor = match >= target_pixels? vec4(matchPos, index, 1.) : vec4(vec3(0.), 0.); + gl_FragColor = match >= (1. - threshold)? vec4(matchPos, index, 1.) : vec4(vec3(0.), 0.); }