diff --git a/objects/obj_test/Create_0.gml b/objects/obj_test/Create_0.gml index 504b9bb..c8f45cf 100644 --- a/objects/obj_test/Create_0.gml +++ b/objects/obj_test/Create_0.gml @@ -1,5 +1,9 @@ -show_debug_message("struct version:"); -show_debug_message(gumshoe("", "txt", true)); show_debug_message("array version:"); show_debug_message(gumshoe("", "txt", false)); +show_debug_message("struct version:"); +show_debug_message(gumshoe("", "txt", true)); +show_debug_message("struct version with value generator:"); +show_debug_message(gumshoe("", "txt", true, , function(directory, file, extension, index) { + return directory + file; // the full path to the file +})); show_debug_message("end."); \ No newline at end of file diff --git a/objects/obj_test/Draw_64.gml b/objects/obj_test/Draw_64.gml new file mode 100644 index 0000000..241e4c2 --- /dev/null +++ b/objects/obj_test/Draw_64.gml @@ -0,0 +1,3 @@ +/// @description + +draw_text(10, 10, "See output log for test cases."); diff --git a/objects/obj_test/obj_test.yy b/objects/obj_test/obj_test.yy index bb3e099..2a77907 100644 --- a/objects/obj_test/obj_test.yy +++ b/objects/obj_test/obj_test.yy @@ -18,7 +18,8 @@ "physicsKinematic": false, "physicsShapePoints": [], "eventList": [ - {"isDnD":false,"eventNum":0,"eventType":0,"collisionObjectId":null,"parent":{"name":"obj_test","path":"objects/obj_test/obj_test.yy",},"resourceVersion":"1.0","name":"","tags":[],"resourceType":"GMEvent",}, + {"isDnD":false,"eventNum":0,"eventType":0,"collisionObjectId":null,"resourceVersion":"1.0","name":"","tags":[],"resourceType":"GMEvent",}, + {"isDnD":false,"eventNum":64,"eventType":8,"collisionObjectId":null,"resourceVersion":"1.0","name":"","tags":[],"resourceType":"GMEvent",}, ], "properties": [], "overriddenProperties": [], diff --git a/scripts/gumshoe/gumshoe.gml b/scripts/gumshoe/gumshoe.gml index ab8c597..680ba48 100644 --- a/scripts/gumshoe/gumshoe.gml +++ b/scripts/gumshoe/gumshoe.gml @@ -33,7 +33,8 @@ On Microsoft platforms this flag does nothing as the file system is not case sen /// @param fileExtension /// @param returnStruct /// @param [forceLCNames] Force lowercase names on non-MSFT platforms, see comment(s) above for an explanation. -function gumshoe() +/// @param [structValueGenerator] when returnStruct = true, function that generates the value for the file (params: directiory, file, extension, index) +function gumshoe(_directory, _extension, _return_struct = false, _force_lcnames = true, _generator = undefined) { //Microsoft platforms handle wildcards and patterns slightly different than others (Linux or web based). static _is_microsoft = @@ -53,10 +54,9 @@ function gumshoe() //(see comments above for more ramblings) static _match_all_mask = _is_microsoft? "*.*" : "*"; - var _directory = argument[0]; - var _extension = argument[1]; - var _return_struct = argument[2]; - var _force_lcnames = (argument_count > 3)? argument[3] : true; + if (_return_struct == false && _generator != undefined) { + throw "Gumshoe: structValueGenerator can only be specified when returning a struct"; + } //The JS export does not support file search at all. if (os_browser != browser_not_a_browser) @@ -87,7 +87,7 @@ function gumshoe() if (_return_struct) { global.__gumshoe_count = 0; - return __gumshoe_struct(_directory, _extension, _match_all_mask, _path_separator); + return __gumshoe_struct(_directory, _extension, _match_all_mask, _path_separator, _generator); } else { @@ -131,7 +131,7 @@ function __gumshoe_array(_directory, _extension, _result, _match_all_mask, _path var _i = 0; repeat(array_length(_directories)) { - __gumshoe_array(_directories[_i], _extension, _result); + __gumshoe_array(_directories[_i], _extension, _result, _match_all_mask, _path_sep); ++_i; } @@ -142,7 +142,8 @@ function __gumshoe_array(_directory, _extension, _result, _match_all_mask, _path /// @param fileExtension /// @param matchAllMask /// @param pathSeparator -function __gumshoe_struct(_directory, _extension, _match_all_mask, _path_sep) +/// @param structValueGenerator +function __gumshoe_struct(_directory, _extension, _match_all_mask, _path_sep, _generator) { var _directories = []; var _result = {}; @@ -162,7 +163,8 @@ function __gumshoe_struct(_directory, _extension, _match_all_mask, _path_sep) else if ((_extension == ".*") || (filename_ext(_file) == _extension)) { //Add this matching file to the output array - variable_struct_set(_result, _file, global.__gumshoe_count); + var value = _generator ? _generator(_directory, _file, _extension, global.__gumshoe_count) : global.__gumshoe_count; + variable_struct_set(_result, _file, value); ++global.__gumshoe_count; } } @@ -173,9 +175,9 @@ function __gumshoe_struct(_directory, _extension, _match_all_mask, _path_sep) var _i = 0; repeat(array_length(_directories)) { - variable_struct_set(_result, _directories[_i], __gumshoe_struct(_directory + _directories[_i] + _path_sep, _extension)); + variable_struct_set(_result, _directories[_i], __gumshoe_struct(_directory + _directories[_i] + _path_sep, _extension, _match_all_mask, _path_sep, _generator)); ++_i; } return _result; -} +} \ No newline at end of file