From a01a979bb3c058997abacf02d01cd2485535d5a1 Mon Sep 17 00:00:00 2001 From: Tanasart Date: Thu, 16 May 2024 15:37:44 +0700 Subject: [PATCH] file watcher crash --- objects/o_main/Step_1.gml | 1 - scripts/file_functions/file_functions.gml | 2 +- scripts/node_data/node_data.gml | 4 - scripts/node_image/node_image.gml | 91 +++++++------------ .../panel_file_explorer.gml | 23 +++-- scripts/path_parser/path_parser.gml | 2 +- 6 files changed, 51 insertions(+), 72 deletions(-) diff --git a/objects/o_main/Step_1.gml b/objects/o_main/Step_1.gml index 1c462f6ca..50dcc5abe 100644 --- a/objects/o_main/Step_1.gml +++ b/objects/o_main/Step_1.gml @@ -154,7 +154,6 @@ _HOVERING_ELEMENT = noone; else if(UPDATE & RENDER_TYPE.partial) Render(true); - } } } diff --git a/scripts/file_functions/file_functions.gml b/scripts/file_functions/file_functions.gml index d82ca6b1f..2f04a91ca 100644 --- a/scripts/file_functions/file_functions.gml +++ b/scripts/file_functions/file_functions.gml @@ -25,7 +25,7 @@ function get_open_filenames_compat(ext, sel) { #region function file_get_modify_s(path) { #region INLINE - if(!file_exists(path)) return 0; + if(!file_exists_empty(path)) return 0; var _y = file_datetime_modified_year(path); var _m = file_datetime_modified_month(path); diff --git a/scripts/node_data/node_data.gml b/scripts/node_data/node_data.gml index 77d0db58f..4fe66c2dc 100644 --- a/scripts/node_data/node_data.gml +++ b/scripts/node_data/node_data.gml @@ -659,8 +659,6 @@ function Node(_x, _y, _group = noone) : __Node_Base(_x, _y) constructor { if(cached_manual || (use_cache == CACHE_USE.auto && recoverCache())) { render_cached = true; - // if(_updateRender) setRenderStatus(true); - } else { render_cached = false; getInputs(frame); @@ -668,8 +666,6 @@ function Node(_x, _y, _group = noone) : __Node_Base(_x, _y) constructor { LOG_BLOCK_START(); LOG_IF(global.FLAG.render == 1, $">>>>>>>>>> DoUpdate called from {INAME} <<<<<<<<<<"); - // if(_updateRender) setRenderStatus(true); - var sBase = surface_get_target(); try { diff --git a/scripts/node_image/node_image.gml b/scripts/node_image/node_image.gml index 71cac01b5..abe1ed85f 100644 --- a/scripts/node_image/node_image.gml +++ b/scripts/node_image/node_image.gml @@ -38,11 +38,10 @@ function Node_Image(_x, _y, _group = noone) : Node(_x, _y, _group) constructor { attribute_surface_depth(); - first_update = false; - spr = []; - path_current = []; - edit_time = 0; + spr = noone; + edit_time = 0; + attributes.check_splice = true; attributes.file_checker = true; array_push(attributeEditors, [ "File Watcher", function() { return attributes.file_checker; }, new checkBox(function() { attributes.file_checker = !attributes.file_checker; }) ]); @@ -59,7 +58,8 @@ function Node_Image(_x, _y, _group = noone) : Node(_x, _y, _group) constructor { } #endregion function createSprite(path) { #region - if(path == -1) return noone; + if(!file_exists(path)) + return noone; var ext = string_lower(filename_ext(path)); var _name = filename_name_only(path); @@ -70,35 +70,26 @@ function Node_Image(_x, _y, _group = noone) : Node(_x, _y, _group) constructor { case ".jpeg": case ".gif": setDisplayName(_name); - var spr = sprite_add(path, 1, false, false, 0, 0); + var _spr = sprite_add(path, 1, false, false, 0, 0); - if(spr == -1) { + if(_spr == -1) { noti_warning($"Image node: File not a valid image."); break; } - edit_time = max(edit_time, file_get_modify_s(path)); - return spr; + edit_time = file_get_modify_s(path); + return _spr; } return noone; } #endregion - function updatePaths(path = path_current) { #region - if(array_empty(path_current)) first_update = true; + function updatePaths(path) { #region - for( var i = 0, n = array_length(spr); i < n; i++ ) - sprite_delete(spr[i]); - spr = []; + if(sprite_exists(spr)) + sprite_delete(spr); - if(!is_array(path)) path = [ path ]; - - for( var i = 0, n = array_length(path); i < n; i++ ) { - path_current[i] = path_get(path[i]); - - var s = createSprite(path[i]); - if(s) array_push(spr, s); - } + spr = createSprite(path); } #endregion insp1UpdateTooltip = __txt("Refresh"); @@ -110,54 +101,42 @@ function Node_Image(_x, _y, _group = noone) : Node(_x, _y, _group) constructor { } #endregion static step = function() { #region - if(attributes.file_checker) - for( var i = 0, n = array_length(path_current); i < n; i++ ) { - if(file_get_modify_s(path_current[i]) > edit_time) { - updatePaths(); - triggerRender(); - break; - } + var path = path_get(getInputData(0)); + + if(!file_exists_empty(path)) return; + + if(attributes.file_checker && file_get_modify_s(path) > edit_time) { + updatePaths(path); + triggerRender(); } } #endregion static update = function(frame = CURRENT_FRAME) { #region + var path = path_get(getInputData(0)); var pad = getInputData(1); outputs[| 1].setValue(path); - if(!array_equals(path_current, path)) - updatePaths(path); + updatePaths(path); - if(array_empty(spr)) return; + if(!sprite_exists(spr)) return; - var _arr = array_length(spr) > 1; var _outsurf = outputs[| 0].getValue(); - if(!is_array(_outsurf)) _outsurf = [ _outsurf ]; + var ww = sprite_get_width(spr) + pad[0] + pad[2]; + var hh = sprite_get_height(spr) + pad[1] + pad[3]; - for( var i = 0, n = array_length(spr); i < n; i++ ) { - var _spr = spr[i]; - - if(!sprite_exists(_spr)) continue; - - var ww = sprite_get_width(_spr) + pad[0] + pad[2]; - var hh = sprite_get_height(_spr) + pad[1] + pad[3]; - - var _surf = array_safe_get_fast(_outsurf, i); - _surf = surface_verify(_surf, ww, hh, attrDepth()); - - surface_set_shader(_surf, noone); - draw_sprite(_spr, 0, pad[2], pad[1]); - surface_reset_shader(); - - _outsurf[i] = _surf; - } + _outsurf = surface_verify(_outsurf, ww, hh, attrDepth()); - outputs[| 0].setValue(_arr? _outsurf : _outsurf[0]); + surface_set_shader(_outsurf, noone); + draw_sprite(spr, 0, pad[2], pad[1]); + surface_reset_shader(); + + outputs[| 0].setValue(_outsurf); #region splice - if(!first_update) return; - first_update = false; + if(!attributes.check_splice) return; + attributes.check_splice = false; if(LOADING || APPENDING) return; if(string_pos("strip", display_name) == 0) return; @@ -168,8 +147,8 @@ function Node_Image(_x, _y, _group = noone) : Node(_x, _y, _group) constructor { if(amo == 0) return; - var ww = sprite_get_width(spr[0]) / amo; - var hh = sprite_get_height(spr[0]); + var ww = sprite_get_width(spr) / amo; + var hh = sprite_get_height(spr); var _splice = nodeBuild("Node_Image_Sheet", x + w + 64, y); _splice.inputs[| 0].setFrom(outputs[| 0], false); diff --git a/scripts/panel_file_explorer/panel_file_explorer.gml b/scripts/panel_file_explorer/panel_file_explorer.gml index 7e5635c28..73dfbe49f 100644 --- a/scripts/panel_file_explorer/panel_file_explorer.gml +++ b/scripts/panel_file_explorer/panel_file_explorer.gml @@ -185,14 +185,13 @@ function Panel_File_Explorer() : PanelContent() constructor { contentPane = new scrollPane(w - padding - padding - cntPad * 2, h - padding - top_bar - cntPad * 2, function(_y, _m, _r) { draw_clear_alpha(COLORS.panel_bg_clear, 0); - if(frame_dragging) { - draw_sprite_stretched_points_clamp(THEME.ui_selection, 0, frame_drag_mx, frame_drag_my, _m[0], _m[1], COLORS._main_accent); - file_selectings = []; - } + if(frame_dragging) file_selectings = []; file_hovering = noone; var _h = drawDir(rootFile, 0, _y, contentPane.surface_w, _m); + if(frame_dragging) draw_sprite_stretched_points_clamp(THEME.ui_selection, 0, frame_drag_mx, frame_drag_my, _m[0], _m[1], COLORS._main_accent); + if(mouse_press(mb_left, pFOCUS)) { if(file_hovering == noone) { file_selectings = []; @@ -221,11 +220,10 @@ function Panel_File_Explorer() : PanelContent() constructor { } if(mouse_release(mb_left)) { - file_dragging = false; - - if(path_dragging != -1) + if(path_dragging != -1 && !pHOVER) o_main.load_file_path(path_dragging); - + + file_dragging = false; path_dragging = -1; } } @@ -260,6 +258,13 @@ function Panel_File_Explorer() : PanelContent() constructor { var _ind = 0; var _ppw = _pw; + if(point_in_rectangle(_m[0], _m[1], _px, _py, _px + _pw, _py + _ph)) { + if(buttonInstant(THEME.button_hide, _px + _ppw - _ph, _py, _ph, _ph, _m, pFOCUS, pHOVER, "", THEME.path_open_20) == 2) { + setRoot(_dir.path); + } + _ppw -= _ph + ui(4); + } + if(contentPane.hover && point_in_rectangle(_m[0], _m[1], _px, _py, _px + _ppw, _py + _ph)) { file_hovering = _dir; _ind = 3; @@ -271,7 +276,7 @@ function Panel_File_Explorer() : PanelContent() constructor { } } - draw_sprite_stretched(THEME.ui_panel_bg, _ind, _px, _py, _pw, _ph); + draw_sprite_stretched(THEME.ui_panel_bg, _ind, _px, _py, _ppw, _ph); var _tx = _px + ui(2); var _ty = _py + ui(2); diff --git a/scripts/path_parser/path_parser.gml b/scripts/path_parser/path_parser.gml index 1b6123eb2..aaaf0bba5 100644 --- a/scripts/path_parser/path_parser.gml +++ b/scripts/path_parser/path_parser.gml @@ -8,7 +8,7 @@ function __path_get(path) { if(file_exists_empty(local_path)) return local_path; - return -1; + return ""; } function path_get(path) {