Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/forty-dancers-obey.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@godot-js/editor": minor
---

feat: Add ability to filter files for generating resources dts and scene dts.
65 changes: 65 additions & 0 deletions internal/jsb_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ namespace jsb::internal
static constexpr char kRtPackagingIncludeDirectories[] = JSB_MODULE_NAME_STRING "/editor/packaging/include_directories";
static constexpr char kRtPackagingReferencedNodeModules[] = JSB_MODULE_NAME_STRING "/editor/packaging/referenced_node_modules";

static constexpr char kRtResourceDTSIncludePathWildcards[] = JSB_MODULE_NAME_STRING "/codegen/resource_dts/include_path_wildcards";
static constexpr char kRtResourceDTSExcludePathWildcards[] = JSB_MODULE_NAME_STRING "/codegen/resource_dts/exclude_path_wildcards";
static constexpr char kRtSceneDTSIncludePathWildcards[] = JSB_MODULE_NAME_STRING "/codegen/scene_dts/include_path_wildcards";
static constexpr char kRtSceneDTSExcludePathWildcards[] = JSB_MODULE_NAME_STRING "/codegen/scene_dts/exclude_path_wildcards";

#ifdef TOOLS_ENABLED
bool init_editor_settings()
{
Expand Down Expand Up @@ -124,6 +129,42 @@ namespace jsb::internal
}

_GLOBAL_DEF(kRtPackagingReferencedNodeModules, true, false);

{
PropertyInfo ResourceDTSIncludePathWildcards;
ResourceDTSIncludePathWildcards.type = Variant::PACKED_STRING_ARRAY;
ResourceDTSIncludePathWildcards.name = kRtResourceDTSIncludePathWildcards;
ResourceDTSIncludePathWildcards.hint = PROPERTY_HINT_ARRAY_TYPE;
ResourceDTSIncludePathWildcards.hint_string = vformat("%s/%s:", Variant::STRING, PROPERTY_HINT_DIR);
_GLOBAL_DEF(ResourceDTSIncludePathWildcards, PackedStringArray{"res://"}, false, JSB_SET_IGNORE_DOCS(false), JSB_SET_BASIC(true), JSB_SET_INTERNAL(false));
}

{
PropertyInfo ResourceDTSExcludePathWildcards;
ResourceDTSExcludePathWildcards.type = Variant::PACKED_STRING_ARRAY;
ResourceDTSExcludePathWildcards.name = kRtResourceDTSExcludePathWildcards;
ResourceDTSExcludePathWildcards.hint = PROPERTY_HINT_ARRAY_TYPE;
ResourceDTSExcludePathWildcards.hint_string = vformat("%s/%s:", Variant::STRING, PROPERTY_HINT_DIR);
_GLOBAL_DEF(ResourceDTSExcludePathWildcards, PackedStringArray(), false, JSB_SET_IGNORE_DOCS(false), JSB_SET_BASIC(true), JSB_SET_INTERNAL(false));
}

{
PropertyInfo SceneDTSIncludePathWildcards;
SceneDTSIncludePathWildcards.type = Variant::PACKED_STRING_ARRAY;
SceneDTSIncludePathWildcards.name = kRtSceneDTSIncludePathWildcards;
SceneDTSIncludePathWildcards.hint = PROPERTY_HINT_ARRAY_TYPE;
SceneDTSIncludePathWildcards.hint_string = vformat("%s/%s:", Variant::STRING, PROPERTY_HINT_DIR);
_GLOBAL_DEF(SceneDTSIncludePathWildcards, PackedStringArray{"res://"}, false, JSB_SET_IGNORE_DOCS(false), JSB_SET_BASIC(true), JSB_SET_INTERNAL(false));
}

{
PropertyInfo SceneDTSExcludePathWildcards;
SceneDTSExcludePathWildcards.type = Variant::PACKED_STRING_ARRAY;
SceneDTSExcludePathWildcards.name = kRtSceneDTSExcludePathWildcards;
SceneDTSExcludePathWildcards.hint = PROPERTY_HINT_ARRAY_TYPE;
SceneDTSExcludePathWildcards.hint_string = vformat("%s/%s:", Variant::STRING, PROPERTY_HINT_DIR);
_GLOBAL_DEF(SceneDTSExcludePathWildcards, PackedStringArray(), false, JSB_SET_IGNORE_DOCS(false), JSB_SET_BASIC(true), JSB_SET_INTERNAL(false));
}
}
}

Expand Down Expand Up @@ -202,6 +243,30 @@ namespace jsb::internal
return GLOBAL_GET(kRtPackagingReferencedNodeModules);
}

PackedStringArray Settings::get_resource_dts_include_path_wildcards()
{
init_settings();
return (PackedStringArray) GLOBAL_GET(kRtResourceDTSIncludePathWildcards);
}

PackedStringArray Settings::get_resource_dts_exclude_path_wildcards()
{
init_settings();
return (PackedStringArray) GLOBAL_GET(kRtResourceDTSExcludePathWildcards);
}

PackedStringArray Settings::get_scene_dts_include_path_wildcards()
{
init_settings();
return (PackedStringArray) GLOBAL_GET(kRtSceneDTSIncludePathWildcards);
}

PackedStringArray Settings::get_scene_dts_exclude_path_wildcards()
{
init_settings();
return (PackedStringArray) GLOBAL_GET(kRtSceneDTSExcludePathWildcards);
}

uint16_t Settings::get_debugger_port()
{
#ifdef TOOLS_ENABLED
Expand Down
5 changes: 5 additions & 0 deletions internal/jsb_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ namespace jsb::internal

static bool is_packaging_referenced_node_modules();

static PackedStringArray get_resource_dts_include_path_wildcards();
static PackedStringArray get_resource_dts_exclude_path_wildcards();
static PackedStringArray get_scene_dts_include_path_wildcards();
static PackedStringArray get_scene_dts_exclude_path_wildcards();

#ifdef TOOLS_ENABLED
// [EDITOR ONLY]
static bool editor_settings_available();
Expand Down
76 changes: 74 additions & 2 deletions weaver-editor/jsb_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,62 @@ void GodotJSEditorPlugin::_generate_imported_resource_dts(const Vector<String>&
generate_resource_types(p_resource);
}

bool GodotJSEditorPlugin::_is_path_matchn(const PackedStringArray& p_wildcards, const String& p_path)
{
for (const String& wildcard: p_wildcards)
{
if ((wildcard.contains_char('*') || wildcard.contains_char('?')) && p_path.match(wildcard))
{
return true;
}
else
{
const String& lower_case_path = p_path.to_lower();
String lower_case_wildcard = wildcard.to_lower();
if (lower_case_path == lower_case_wildcard){
return true; // Exact match file.
}
else
{
if (!lower_case_wildcard.ends_with("/"))
{
// Cheat as directory.
lower_case_wildcard += "/";
}

if (lower_case_path.begins_with(lower_case_wildcard))
{
return true; // Match directory.
}
}
}
}

return false;
}

Vector<String> GodotJSEditorPlugin::_filter_resource_paths(const PackedStringArray& p_exclude_wildcards, const PackedStringArray& p_include_wildcards, const Vector<String>& p_paths)
{
Vector<String> filtered_paths;
if (!p_include_wildcards.is_empty())
{
for (const String& path: p_paths)
{
if (!p_exclude_wildcards.is_empty() && _is_path_matchn(p_exclude_wildcards, path))
{
continue;
}

if (_is_path_matchn(p_include_wildcards, path))
{
filtered_paths.push_back(path);
}
}
}

return filtered_paths;
}

void GodotJSEditorPlugin::generate_godot_dts()
{
if (GodotJSEditorPlugin* editor_plugin = GodotJSEditorPlugin::get_singleton())
Expand Down Expand Up @@ -568,14 +624,22 @@ void GodotJSEditorPlugin::generate_scene_nodes_types(const Vector<String>& p_pat
return;
}

PackedStringArray exclude_wildcards = jsb::internal::Settings::get_scene_dts_exclude_path_wildcards();
PackedStringArray include_wildcards = jsb::internal::Settings::get_scene_dts_include_path_wildcards();
Vector<String> filtered_paths = _filter_resource_paths(exclude_wildcards, include_wildcards, p_paths);
if (filtered_paths.is_empty())
{
return;
}
Comment thread
Daylily-Zeleen marked this conversation as resolved.

GodotJSScriptLanguage* lang = GodotJSScriptLanguage::get_singleton();
jsb_check(lang);
Error err;

const String code = jsb_format(
R"--((function(){const mod = require("jsb.editor.codegen"); (new mod.SceneTSDCodeGen("%s", ["%s"])).emit();})())--",
"./" + jsb::internal::Settings::get_autogen_path(),
String("\", \"").join(p_paths)
String("\", \"").join(filtered_paths)
);
lang->eval_source(code, err).ignore();
ERR_FAIL_COND_MSG(err != OK, "failed to evaluate jsb.editor.codegen");
Expand All @@ -591,14 +655,22 @@ void GodotJSEditorPlugin::generate_resource_types(const Vector<String>& p_paths)
return;
}

PackedStringArray exclude_wildcards = jsb::internal::Settings::get_resource_dts_exclude_path_wildcards();
PackedStringArray include_wildcards = jsb::internal::Settings::get_resource_dts_include_path_wildcards();
Vector<String> filtered_paths = _filter_resource_paths(exclude_wildcards, include_wildcards, p_paths);
if (filtered_paths.is_empty())
{
return;
}

GodotJSScriptLanguage* lang = GodotJSScriptLanguage::get_singleton();
jsb_check(lang);
Error err;

const String code = jsb_format(
R"--((function(){const mod = require("jsb.editor.codegen"); (new mod.ResourceTSDCodeGen("%s", ["%s"])).emit();})())--",
"./" + jsb::internal::Settings::get_autogen_path(),
String("\", \"").join(p_paths)
String("\", \"").join(filtered_paths)
);
lang->eval_source(code, err).ignore();
ERR_FAIL_COND_MSG(err != OK, "failed to evaluate jsb.editor.codegen");
Expand Down
3 changes: 3 additions & 0 deletions weaver-editor/jsb_editor_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ class GodotJSEditorPlugin : public EditorPlugin
void _on_resource_saved(const Ref<Resource>& p_resource);
void _generate_imported_resource_dts(const Vector<String>& p_resources);

static bool _is_path_matchn(const PackedStringArray& p_wildcards, const String& p_path);
static Vector<String> _filter_resource_paths(const PackedStringArray& p_exclude_wildcards, const PackedStringArray& p_include_wildcards, const Vector<String>& p_paths);

protected:
static void _bind_methods();

Expand Down
Loading