Skip to content

Commit e686aef

Browse files
committed
Implement template for javascript and typescript language
1 parent 37f400d commit e686aef

8 files changed

+37
-26
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ __MACOSX
2121
# auto-generated sources
2222
/jsb.gen.h
2323
/jsb_project_preset.gen.cpp
24-
/weaver-editor/templates/templates.gen.h
24+
/weaver-editor/templates/templates.ts.gen.h
25+
/weaver-editor/templates/templates.js.gen.h
2526

2627
.vscode

weaver-editor/templates/SCsub

+4-5
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,10 @@ else:
4242
src_suffix = ".ts",
4343
)
4444

45-
language = "ts" if env["use_typescript"] else "js"
46-
print("generate templates for", language)
47-
4845
# Template files
4946
# the suffix should be `.ts`, but `editor/template_builders.py` hardcoded the delimiter with `.cs`
50-
templates_sources = Glob(f"*/*.{language}.cs")
47+
templates_ts_sources = Glob(f"*/*.ts.cs")
48+
env.Alias("editor_template_ts", [env.MakeGodotJSTemplateBuilder("templates.ts.gen.h", templates_ts_sources)])
5149

52-
env.Alias("editor_template_ts", [env.MakeGodotJSTemplateBuilder("templates.gen.h", templates_sources)])
50+
templates_js_sources = Glob(f"*/*.js.cs")
51+
env.Alias("editor_template_js", [env.MakeGodotJSTemplateBuilder("templates.js.gen.h", templates_js_sources)])

weaver/jsb_script_language.cpp

-17
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@
1212

1313
#include "modules/regex/regex.h"
1414

15-
#ifdef TOOLS_ENABLED
16-
#include "../weaver-editor/templates/templates.gen.h"
17-
#endif
18-
1915
int GodotJSScriptLanguageBase::prevent_environment_dispose_ = 0;
2016
std::shared_ptr<jsb::Environment> GodotJSScriptLanguageBase::environment_ = nullptr;
2117

@@ -191,19 +187,6 @@ Ref<Script> GodotJSScriptLanguageBase::make_template(const String& p_template, c
191187
return spt;
192188
}
193189

194-
Vector<ScriptLanguage::ScriptTemplate> GodotJSScriptLanguageBase::get_built_in_templates(ConstStringNameRefCompat p_object)
195-
{
196-
Vector<ScriptTemplate> templates;
197-
#ifdef TOOLS_ENABLED
198-
for (int i = 0; i < TEMPLATES_ARRAY_SIZE; i++) {
199-
if (TEMPLATES[i].inherit == p_object) {
200-
templates.append(TEMPLATES[i]);
201-
}
202-
}
203-
#endif
204-
return templates;
205-
}
206-
207190
#if GODOT_4_3_OR_NEWER
208191
void GodotJSScriptLanguageBase::reload_scripts(const Array& p_scripts, bool p_soft_reload)
209192
{

weaver/jsb_script_language.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class GodotJSScriptLanguageBase : public ScriptLanguage
6464
virtual void thread_exit() override;
6565

6666
virtual bool is_control_flow_keyword(ConstStringRefCompat p_keyword) const override;
67-
virtual Vector<ScriptTemplate> get_built_in_templates(ConstStringNameRefCompat p_object) override;
67+
virtual Vector<ScriptTemplate> get_built_in_templates(ConstStringNameRefCompat p_object) = 0;
6868

6969
virtual void get_reserved_words(List<String>* p_words) const override;
7070
virtual void get_doc_comment_delimiters(List<String>* p_delimiters) const override;

weaver/jsb_script_language_js.cpp

+14-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include "modules/regex/regex.h"
1414

1515
#ifdef TOOLS_ENABLED
16-
#include "../weaver-editor/templates/templates.gen.h"
16+
#include "../weaver-editor/templates/templates.js.gen.h"
1717
#endif
1818

1919
GodotJavascriptLanguage * GodotJavascriptLanguage::singleton_ = nullptr;
@@ -44,3 +44,16 @@ String GodotJavascriptLanguage::get_type() const
4444
return jsb_typename(GodotJavaScript);
4545
}
4646

47+
Vector<ScriptLanguage::ScriptTemplate> GodotJavascriptLanguage::get_built_in_templates(ConstStringNameRefCompat p_object)
48+
{
49+
Vector<ScriptTemplate> templates;
50+
#ifdef TOOLS_ENABLED
51+
for (int i = 0; i < TEMPLATES_ARRAY_SIZE; i++) {
52+
if (TEMPLATES[i].inherit == p_object) {
53+
templates.append(TEMPLATES[i]);
54+
}
55+
}
56+
#endif
57+
return templates;
58+
}
59+

weaver/jsb_script_language_js.h

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class GodotJavascriptLanguage : public GodotJSScriptLanguageBase {
1515
virtual bool handles_global_class_type(const String& p_type) const override;
1616
virtual String get_name() const override;
1717
virtual String get_type() const override;
18+
virtual Vector<ScriptTemplate> get_built_in_templates(ConstStringNameRefCompat p_object) override;
1819

1920
};
2021

weaver/jsb_script_language_ts.cpp

+14-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include "modules/regex/regex.h"
1414

1515
#ifdef TOOLS_ENABLED
16-
#include "../weaver-editor/templates/templates.gen.h"
16+
#include "../weaver-editor/templates/templates.ts.gen.h"
1717
#endif
1818

1919
GodotJSScriptLanguage * GodotJSScriptLanguage::singleton_ = nullptr;
@@ -43,3 +43,16 @@ String GodotJSScriptLanguage::get_type() const
4343
return jsb_typename(GodotJSScript);
4444
}
4545

46+
Vector<ScriptLanguage::ScriptTemplate> GodotJSScriptLanguage::get_built_in_templates(ConstStringNameRefCompat p_object)
47+
{
48+
Vector<ScriptTemplate> templates;
49+
#ifdef TOOLS_ENABLED
50+
for (int i = 0; i < TEMPLATES_ARRAY_SIZE; i++) {
51+
if (TEMPLATES[i].inherit == p_object) {
52+
templates.append(TEMPLATES[i]);
53+
}
54+
}
55+
#endif
56+
return templates;
57+
}
58+

weaver/jsb_script_language_ts.h

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class GodotJSScriptLanguage : public GodotJSScriptLanguageBase {
1515
virtual bool handles_global_class_type(const String& p_type) const override;
1616
virtual String get_name() const override;
1717
virtual String get_type() const override;
18+
virtual Vector<ScriptTemplate> get_built_in_templates(ConstStringNameRefCompat p_object) override;
1819

1920
};
2021

0 commit comments

Comments
 (0)