mirror of
https://github.com/Ttanasart-pt/Pixel-Composer.git
synced 2024-11-13 05:53:53 +01:00
- New Directory Search node.
This commit is contained in:
parent
b39707b415
commit
d576d2e43c
@ -768,6 +768,7 @@
|
|||||||
{"name":"node_image_grid","order":3,"path":"scripts/node_image_grid/node_image_grid.yy",},
|
{"name":"node_image_grid","order":3,"path":"scripts/node_image_grid/node_image_grid.yy",},
|
||||||
{"name":"node_image_sequence","order":1,"path":"scripts/node_image_sequence/node_image_sequence.yy",},
|
{"name":"node_image_sequence","order":1,"path":"scripts/node_image_sequence/node_image_sequence.yy",},
|
||||||
{"name":"node_image_sheet","order":4,"path":"scripts/node_image_sheet/node_image_sheet.yy",},
|
{"name":"node_image_sheet","order":4,"path":"scripts/node_image_sheet/node_image_sheet.yy",},
|
||||||
|
{"name":"node_directory_search","order":23,"path":"scripts/node_directory_search/node_directory_search.yy",},
|
||||||
{"name":"node_interpret_number","order":3,"path":"scripts/node_interpret_number/node_interpret_number.yy",},
|
{"name":"node_interpret_number","order":3,"path":"scripts/node_interpret_number/node_interpret_number.yy",},
|
||||||
{"name":"node_invert","order":6,"path":"scripts/node_invert/node_invert.yy",},
|
{"name":"node_invert","order":6,"path":"scripts/node_invert/node_invert.yy",},
|
||||||
{"name":"node_isosurf","order":3,"path":"scripts/node_isosurf/node_isosurf.yy",},
|
{"name":"node_isosurf","order":3,"path":"scripts/node_isosurf/node_isosurf.yy",},
|
||||||
|
@ -1190,6 +1190,7 @@
|
|||||||
{"id":{"name":"node_image_sequence","path":"scripts/node_image_sequence/node_image_sequence.yy",},},
|
{"id":{"name":"node_image_sequence","path":"scripts/node_image_sequence/node_image_sequence.yy",},},
|
||||||
{"id":{"name":"node_image_sheet","path":"scripts/node_image_sheet/node_image_sheet.yy",},},
|
{"id":{"name":"node_image_sheet","path":"scripts/node_image_sheet/node_image_sheet.yy",},},
|
||||||
{"id":{"name":"node_image","path":"scripts/node_image/node_image.yy",},},
|
{"id":{"name":"node_image","path":"scripts/node_image/node_image.yy",},},
|
||||||
|
{"id":{"name":"node_directory_search","path":"scripts/node_directory_search/node_directory_search.yy",},},
|
||||||
{"id":{"name":"node_interpret_number","path":"scripts/node_interpret_number/node_interpret_number.yy",},},
|
{"id":{"name":"node_interpret_number","path":"scripts/node_interpret_number/node_interpret_number.yy",},},
|
||||||
{"id":{"name":"node_invert","path":"scripts/node_invert/node_invert.yy",},},
|
{"id":{"name":"node_invert","path":"scripts/node_invert/node_invert.yy",},},
|
||||||
{"id":{"name":"node_isosurf","path":"scripts/node_isosurf/node_isosurf.yy",},},
|
{"id":{"name":"node_isosurf","path":"scripts/node_isosurf/node_isosurf.yy",},},
|
||||||
|
@ -19,7 +19,7 @@ if(winMan_isMinimized()) exit;
|
|||||||
case VALUE_TYPE.text :
|
case VALUE_TYPE.text :
|
||||||
case VALUE_TYPE.struct :
|
case VALUE_TYPE.struct :
|
||||||
case VALUE_TYPE.path :
|
case VALUE_TYPE.path :
|
||||||
draw_tooltip_text(string_real(content));
|
draw_tooltip_text(content);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VALUE_TYPE.boolean :
|
case VALUE_TYPE.boolean :
|
||||||
|
169
scripts/node_directory_search/node_directory_search.gml
Normal file
169
scripts/node_directory_search/node_directory_search.gml
Normal file
@ -0,0 +1,169 @@
|
|||||||
|
function Node_create_Directory_Search(_x, _y, _group = noone) { #region
|
||||||
|
var path = "";
|
||||||
|
if(NODE_NEW_MANUAL) {
|
||||||
|
path = get_directory("");
|
||||||
|
key_release();
|
||||||
|
if(path == "") return noone;
|
||||||
|
}
|
||||||
|
|
||||||
|
var node = new Node_Directory_Search(_x, _y, _group);
|
||||||
|
node.inputs[| 0].setValue(path);
|
||||||
|
if(NODE_NEW_MANUAL) node.doUpdate();
|
||||||
|
|
||||||
|
return node;
|
||||||
|
} #endregion
|
||||||
|
|
||||||
|
function Node_Directory_Search(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
|
||||||
|
name = "Directory Search";
|
||||||
|
color = COLORS.node_blend_input;
|
||||||
|
|
||||||
|
inputs[| 0] = nodeValue("Path", self, JUNCTION_CONNECT.input, VALUE_TYPE.path, "")
|
||||||
|
.setDisplay(VALUE_DISPLAY.path_load, { filter: "dir" });
|
||||||
|
|
||||||
|
inputs[| 1] = nodeValue("Extensions", self, JUNCTION_CONNECT.input, VALUE_TYPE.text, ".png");
|
||||||
|
|
||||||
|
inputs[| 2] = nodeValue("Type", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0)
|
||||||
|
.setDisplay(VALUE_DISPLAY.enum_scroll, [ "Surface", "Text" ]);
|
||||||
|
|
||||||
|
outputs[| 0] = nodeValue("Outputs", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, [])
|
||||||
|
.setVisible(true, true);
|
||||||
|
|
||||||
|
outputs[| 1] = nodeValue("Paths", self, JUNCTION_CONNECT.output, VALUE_TYPE.path, [""])
|
||||||
|
.setVisible(true, true);
|
||||||
|
|
||||||
|
attribute_surface_depth();
|
||||||
|
|
||||||
|
path_current = "";
|
||||||
|
paths = {};
|
||||||
|
|
||||||
|
attributes.file_checker = true;
|
||||||
|
array_push(attributeEditors, [ "File Watcher", function() { return attributes.file_checker; },
|
||||||
|
new checkBox(function() { attributes.file_checker = !attributes.file_checker; }) ]);
|
||||||
|
|
||||||
|
function deleteSprite(pathObj) { #region
|
||||||
|
if(sprite_exists(pathObj.spr))
|
||||||
|
sprite_delete(pathObj.spr);
|
||||||
|
} #endregion
|
||||||
|
|
||||||
|
function refreshSprite(pathObj) { #region
|
||||||
|
var path = pathObj.path;
|
||||||
|
var ext = string_lower(filename_ext(path));
|
||||||
|
|
||||||
|
switch(ext) {
|
||||||
|
case ".png":
|
||||||
|
case ".jpg":
|
||||||
|
case ".jpeg":
|
||||||
|
case ".gif":
|
||||||
|
if(sprite_exists(pathObj.spr))
|
||||||
|
sprite_delete(pathObj.spr);
|
||||||
|
|
||||||
|
pathObj.spr = sprite_add(path, 1, false, false, 0, 0);
|
||||||
|
|
||||||
|
if(pathObj.spr == -1) {
|
||||||
|
noti_warning($"Image node: File not a valid image.");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
pathObj.edit_time = file_get_modify_s(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
return pathObj;
|
||||||
|
} #endregion
|
||||||
|
|
||||||
|
function refreshText(pathObj) { #region
|
||||||
|
var path = pathObj.path;
|
||||||
|
var ext = string_lower(filename_ext(path));
|
||||||
|
|
||||||
|
pathObj.content = file_read_all(path);
|
||||||
|
pathObj.edit_time = file_get_modify_s(path);
|
||||||
|
|
||||||
|
return pathObj;
|
||||||
|
} #endregion
|
||||||
|
|
||||||
|
function updatePaths() { #region
|
||||||
|
var path = getInputData(0);
|
||||||
|
var filter = getInputData(1);
|
||||||
|
var type = getInputData(2);
|
||||||
|
|
||||||
|
var _paths = struct_get_names(paths);
|
||||||
|
for (var i = 0, n = array_length(_paths); i < n; i++)
|
||||||
|
deleteSprite(paths[$ _paths[i]]);
|
||||||
|
paths = {};
|
||||||
|
|
||||||
|
var _paths = paths_to_array_ext(path, filter);
|
||||||
|
print(array_length(_paths));
|
||||||
|
|
||||||
|
for (var i = 0, n = array_length(_paths); i < n; i++) {
|
||||||
|
var _path = _paths[i];
|
||||||
|
paths[$ _path] = { path: _path, spr: -1, edit_time: 0 };
|
||||||
|
|
||||||
|
if(type == 0) refreshSprite(paths[$ _path]);
|
||||||
|
else if(type == 1) refreshText(paths[$ _path]);
|
||||||
|
}
|
||||||
|
} #endregion
|
||||||
|
|
||||||
|
insp1UpdateTooltip = __txt("Refresh");
|
||||||
|
insp1UpdateIcon = [ THEME.refresh_icon, 1, COLORS._main_value_positive ];
|
||||||
|
|
||||||
|
static onInspector1Update = function() { #region
|
||||||
|
updatePaths();
|
||||||
|
triggerRender();
|
||||||
|
} #endregion
|
||||||
|
|
||||||
|
static step = function() { #region
|
||||||
|
if(attributes.file_checker) {
|
||||||
|
var _update = false;
|
||||||
|
var _paths = struct_get_names(paths);
|
||||||
|
|
||||||
|
for (var i = 0, n = array_length(_paths); i < n; i++) {
|
||||||
|
var _pathObj = paths[$ _paths[i]];
|
||||||
|
if(file_get_modify_s(_pathObj.path) > _pathObj.edit_time) {
|
||||||
|
refreshSprite(_pathObj);
|
||||||
|
_update = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(_update) triggerRender();
|
||||||
|
}
|
||||||
|
|
||||||
|
} #endregion
|
||||||
|
|
||||||
|
static update = function(frame = CURRENT_FRAME) { #region
|
||||||
|
updatePaths();
|
||||||
|
var type = getInputData(2);
|
||||||
|
|
||||||
|
var _outsurf = outputs[| 0].getValue();
|
||||||
|
if(!is_array(_outsurf)) _outsurf = [ _outsurf ];
|
||||||
|
|
||||||
|
var _paths = struct_get_names(paths);
|
||||||
|
var _ind = 0;
|
||||||
|
var _imgPaths = [];
|
||||||
|
|
||||||
|
for (var i = 0, n = array_length(_paths); i < n; i++) {
|
||||||
|
var _pathObj = paths[$ _paths[i]];
|
||||||
|
var _spr = _pathObj.spr;
|
||||||
|
|
||||||
|
if(!sprite_exists(_spr)) continue;
|
||||||
|
|
||||||
|
var ww = sprite_get_width(_spr);
|
||||||
|
var hh = sprite_get_height(_spr);
|
||||||
|
|
||||||
|
var _surf = array_safe_get_fast(_outsurf, i);
|
||||||
|
_surf = surface_verify(_surf, ww, hh, attrDepth());
|
||||||
|
|
||||||
|
surface_set_shader(_surf, noone);
|
||||||
|
draw_sprite(_spr, 0, 0, 0);
|
||||||
|
surface_reset_shader();
|
||||||
|
|
||||||
|
_imgPaths[_ind] = _pathObj.path;
|
||||||
|
_outsurf[_ind++] = _surf;
|
||||||
|
}
|
||||||
|
|
||||||
|
array_resize(_imgPaths, _ind);
|
||||||
|
array_resize(_outsurf, _ind);
|
||||||
|
|
||||||
|
outputs[| 0].setType(type == 0? VALUE_TYPE.surface : VALUE_TYPE.text);
|
||||||
|
outputs[| 0].setValue(_outsurf);
|
||||||
|
outputs[| 1].setValue(_imgPaths);
|
||||||
|
} #endregion
|
||||||
|
}
|
13
scripts/node_directory_search/node_directory_search.yy
Normal file
13
scripts/node_directory_search/node_directory_search.yy
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"$GMScript":"",
|
||||||
|
"%Name":"node_directory_search",
|
||||||
|
"isCompatibility":false,
|
||||||
|
"isDnD":false,
|
||||||
|
"name":"node_directory_search",
|
||||||
|
"parent":{
|
||||||
|
"name":"io",
|
||||||
|
"path":"folders/nodes/data/io.yy",
|
||||||
|
},
|
||||||
|
"resourceType":"GMScript",
|
||||||
|
"resourceVersion":"2.0",
|
||||||
|
}
|
@ -508,6 +508,7 @@ function __initNodes() {
|
|||||||
addNodeObject(input, "WAV File Out", s_node_wav_file_write, "Node_WAV_File_Write", [1, Node_WAV_File_Write],, "Save wav audio file.").setVersion(1145);
|
addNodeObject(input, "WAV File Out", s_node_wav_file_write, "Node_WAV_File_Write", [1, Node_WAV_File_Write],, "Save wav audio file.").setVersion(1145);
|
||||||
addNodeObject(input, "Byte File In", s_node_byte_file_read, "Node_Byte_File_Read", [1, Node_Byte_File_Read],, "Load any file to buffer.").setVersion(11670);
|
addNodeObject(input, "Byte File In", s_node_byte_file_read, "Node_Byte_File_Read", [1, Node_Byte_File_Read],, "Load any file to buffer.").setVersion(11670);
|
||||||
addNodeObject(input, "Byte File Out", s_node_byte_file_write, "Node_Byte_File_Write", [1, Node_Byte_File_Write],, "Save buffer content to a file.").setVersion(11670);
|
addNodeObject(input, "Byte File Out", s_node_byte_file_write, "Node_Byte_File_Write", [1, Node_Byte_File_Write],, "Save buffer content to a file.").setVersion(11670);
|
||||||
|
addNodeObject(input, "Directory Search", s_node_directory, "Node_Directory_Search", [0, Node_create_Directory_Search],, "Search for files in directory.").setVersion(11710);
|
||||||
|
|
||||||
ds_list_add(input, "External");
|
ds_list_add(input, "External");
|
||||||
addNodeObject(input, "Websocket Receiver", s_node_websocket_receive, "Node_Websocket_Receiver", [1, Node_Websocket_Receiver],, "Create websocket server to receive data from the network.").setVersion(1145);
|
addNodeObject(input, "Websocket Receiver", s_node_websocket_receive, "Node_Websocket_Receiver", [1, Node_Websocket_Receiver],, "Create websocket server to receive data from the network.").setVersion(1145);
|
||||||
|
@ -1206,7 +1206,7 @@ function NodeValue(_name, _node, _connect, _type, _value, _tooltip = "") constru
|
|||||||
|
|
||||||
editWidget.align = fa_left;
|
editWidget.align = fa_left;
|
||||||
editWidget.side_button = button(function() {
|
editWidget.side_button = button(function() {
|
||||||
var path = get_open_filename(display_data.filter, "");
|
var path = display_data.filter == "dir"? get_directory("") : get_open_filename(display_data.filter, "");
|
||||||
key_release();
|
key_release();
|
||||||
if(path == "") return noone;
|
if(path == "") return noone;
|
||||||
return setValueInspector(path);
|
return setValueInspector(path);
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
function __path_get(path) {
|
function __path_get(path) {
|
||||||
INLINE
|
INLINE
|
||||||
|
|
||||||
|
if(directory_exists(path)) return path;
|
||||||
if(file_exists_empty(path)) return path;
|
if(file_exists_empty(path)) return path;
|
||||||
|
|
||||||
var local_path = $"{filename_dir(PROJECT.path)}/{path}";
|
var local_path = $"{filename_dir(PROJECT.path)}/{path}";
|
||||||
|
@ -1,19 +1,20 @@
|
|||||||
function path_search(paths, recur = false, _filter = "") {
|
function path_search(paths, recur = false, _filter = "") {
|
||||||
var _paths = [];
|
var _paths = [];
|
||||||
for( var i = 0, n = array_length(paths); i < n; i++ ) {
|
for( var i = 0, n = array_length(paths); i < n; i++ )
|
||||||
array_append(_paths, paths_to_array(paths[i], recur, _filter));
|
array_append(_paths, paths_to_array(paths[i], recur, _filter));
|
||||||
}
|
|
||||||
return _paths;
|
return _paths;
|
||||||
}
|
}
|
||||||
|
|
||||||
function paths_to_array(paths, recur = false, _filter = "") {
|
function paths_to_array(paths, recur = false, _filter = "") {
|
||||||
|
paths = string_trim_end(paths, ["/", "\\"]);
|
||||||
|
|
||||||
var _paths = [];
|
var _paths = [];
|
||||||
var in = 0;
|
var in = 0;
|
||||||
|
var regx = new regex_tree(_filter);
|
||||||
|
|
||||||
if(directory_exists(paths)) {
|
if(directory_exists(paths)) {
|
||||||
var st = ds_stack_create();
|
var st = ds_stack_create();
|
||||||
ds_stack_push(st, paths);
|
ds_stack_push(st, paths);
|
||||||
var regx = new regex_tree(_filter);
|
|
||||||
|
|
||||||
while(!ds_stack_empty(st)) {
|
while(!ds_stack_empty(st)) {
|
||||||
var curr_path = ds_stack_pop(st);
|
var curr_path = ds_stack_pop(st);
|
||||||
@ -33,7 +34,7 @@ function paths_to_array(paths, recur = false, _filter = "") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ds_stack_destroy(st);
|
ds_stack_destroy(st);
|
||||||
} else if(file_exists_empty(paths))
|
} else if(file_exists_empty(paths) && regx.isMatch(paths))
|
||||||
array_push(_paths, paths);
|
array_push(_paths, paths);
|
||||||
|
|
||||||
return _paths;
|
return _paths;
|
||||||
@ -51,4 +52,37 @@ function path_is_image(path) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function paths_to_array_ext(paths, _extension = "") {
|
||||||
|
paths = string_trim_end(paths, ["/", "\\"]);
|
||||||
|
var _ext = string_splice(_extension, ";", false, false);
|
||||||
|
var _paths = [];
|
||||||
|
|
||||||
|
if(!directory_exists(paths)) return [];
|
||||||
|
|
||||||
|
var st = ds_stack_create();
|
||||||
|
ds_stack_push(st, paths);
|
||||||
|
|
||||||
|
while(!ds_stack_empty(st)) {
|
||||||
|
var curr_path = ds_stack_pop(st);
|
||||||
|
var file = file_find_first(curr_path + "/*", fa_none);
|
||||||
|
|
||||||
|
while(file != "") {
|
||||||
|
var file_full = curr_path + "/" + file;
|
||||||
|
|
||||||
|
if(directory_exists(file_full))
|
||||||
|
ds_stack_push(st, file_full);
|
||||||
|
|
||||||
|
else if(array_exists(_ext, filename_ext(file)))
|
||||||
|
array_push(_paths, file_full);
|
||||||
|
|
||||||
|
file = file_find_next();
|
||||||
|
}
|
||||||
|
file_find_close();
|
||||||
|
}
|
||||||
|
|
||||||
|
ds_stack_destroy(st);
|
||||||
|
|
||||||
|
return _paths;
|
||||||
}
|
}
|
@ -14,42 +14,15 @@ function regex_node(val, accept = false) constructor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function regex_tree(regx) constructor {
|
function regex_tree(regx) constructor {
|
||||||
static delim = ["*", "(", ")", "|", "+", "?", "[", "]", "{", "}", "^", "-"];
|
regs = string_splice(regx, ";", false, false);
|
||||||
|
|
||||||
self.regx = regx;
|
|
||||||
nodes = [];
|
|
||||||
|
|
||||||
var prev = noone;
|
|
||||||
var delm = "";
|
|
||||||
var len = string_length(regx);
|
|
||||||
|
|
||||||
for( var i = 1; i <= len; i++ ) {
|
|
||||||
var _chr = string_char_at(regx, i);
|
|
||||||
|
|
||||||
if(array_exists(_chr, delim)) {
|
|
||||||
if(prev != noone)
|
|
||||||
switch(_chr) {
|
|
||||||
case "*" : prev.setNext(_chr, prev); break;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
var node = new regex_node(_chr, i == len);
|
|
||||||
if(prev != noone)
|
|
||||||
prev.setNext(_chr, node);
|
|
||||||
prev = node;
|
|
||||||
array_push(nodes, node);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static isMatch = function(str) {
|
static isMatch = function(str) {
|
||||||
if(array_length(nodes) == 0) return true;
|
for (var i = 0, n = array_length(regs); i < n; i++) {
|
||||||
var pntr = nodes[0];
|
var rgx = regs[i];
|
||||||
var len = string_length(str);
|
if(RegexMatch(str, rgx))
|
||||||
|
return true;
|
||||||
for( var i = 1; i <= len; i++ ) {
|
|
||||||
var _chr = string_char_at(str, i);
|
|
||||||
pntr = pntr.consume(_chr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return pntr.accept;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user