summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2017-06-14 23:11:41 +0200
committerGitHub <noreply@github.com>2017-06-14 23:11:41 +0200
commit19017a760cbddee9bf0b40824ae9fbf5ca6d9042 (patch)
treec0338f78ed6a476261f16ee684f0654471eae5d5 /modules
parent80de0c35df3aea7155c6e8026448896c3c749126 (diff)
parent8361b1ce07266350ef6b6a2d34411030b7e587b2 (diff)
Merge pull request #9158 from Hinsbart/script_templates
Add ability to use custom script templates.
Diffstat (limited to 'modules')
-rw-r--r--modules/gdscript/gd_editor.cpp13
-rw-r--r--modules/gdscript/gd_script.cpp5
-rw-r--r--modules/gdscript/gd_script.h2
-rw-r--r--modules/visual_script/visual_script.cpp11
-rw-r--r--modules/visual_script/visual_script.h2
5 files changed, 33 insertions, 0 deletions
diff --git a/modules/gdscript/gd_editor.cpp b/modules/gdscript/gd_editor.cpp
index eea5b15236..5e3ce31dd6 100644
--- a/modules/gdscript/gd_editor.cpp
+++ b/modules/gdscript/gd_editor.cpp
@@ -69,6 +69,19 @@ Ref<Script> GDScriptLanguage::get_template(const String &p_class_name, const Str
return script;
}
+bool GDScriptLanguage::is_using_templates() {
+
+ return true;
+}
+
+void GDScriptLanguage::make_template(const String &p_class_name, const String &p_base_class_name, Ref<Script> &p_script) {
+
+ String src = p_script->get_source_code();
+ src = src.replace("%BASE%", p_base_class_name);
+ src = src.replace("%TS%", _get_indentation());
+ p_script->set_source_code(src);
+}
+
bool GDScriptLanguage::validate(const String &p_script, int &r_line_error, int &r_col_error, String &r_test_error, const String &p_path, List<String> *r_functions) const {
GDParser parser;
diff --git a/modules/gdscript/gd_script.cpp b/modules/gdscript/gd_script.cpp
index dcc0e24098..1dcc442234 100644
--- a/modules/gdscript/gd_script.cpp
+++ b/modules/gdscript/gd_script.cpp
@@ -615,6 +615,11 @@ Error GDScript::reload(bool p_keep_state) {
if (basedir != "")
basedir = basedir.get_base_dir();
+ if (basedir.find("res://") == -1 && basedir.find("user://") == -1) {
+ //loading a template, don't parse
+ return OK;
+ }
+
valid = false;
GDParser parser;
Error err = parser.parse(source, basedir, false, path);
diff --git a/modules/gdscript/gd_script.h b/modules/gdscript/gd_script.h
index 00ae136790..ebef4fed74 100644
--- a/modules/gdscript/gd_script.h
+++ b/modules/gdscript/gd_script.h
@@ -381,6 +381,8 @@ public:
virtual void get_comment_delimiters(List<String> *p_delimiters) const;
virtual void get_string_delimiters(List<String> *p_delimiters) const;
virtual Ref<Script> get_template(const String &p_class_name, const String &p_base_class_name) const;
+ virtual bool is_using_templates();
+ virtual void make_template(const String &p_class_name, const String &p_base_class_name, Ref<Script> &p_script);
virtual bool validate(const String &p_script, int &r_line_error, int &r_col_error, String &r_test_error, const String &p_path = "", List<String> *r_functions = NULL) const;
virtual Script *create_script() const;
virtual bool has_named_classes() const;
diff --git a/modules/visual_script/visual_script.cpp b/modules/visual_script/visual_script.cpp
index aec60391d3..bb8111ce99 100644
--- a/modules/visual_script/visual_script.cpp
+++ b/modules/visual_script/visual_script.cpp
@@ -2369,6 +2369,17 @@ Ref<Script> VisualScriptLanguage::get_template(const String &p_class_name, const
script->set_instance_base_type(p_base_class_name);
return script;
}
+
+bool VisualScriptLanguage::is_using_templates() {
+
+ return true;
+}
+
+void VisualScriptLanguage::make_template(const String &p_class_name, const String &p_base_class_name, Ref<Script> &p_script) {
+ Ref<VisualScript> script = p_script;
+ script->set_instance_base_type(p_base_class_name);
+}
+
bool VisualScriptLanguage::validate(const String &p_script, int &r_line_error, int &r_col_error, String &r_test_error, const String &p_path, List<String> *r_functions) const {
return false;
diff --git a/modules/visual_script/visual_script.h b/modules/visual_script/visual_script.h
index 72843099c7..1ccc358342 100644
--- a/modules/visual_script/visual_script.h
+++ b/modules/visual_script/visual_script.h
@@ -564,6 +564,8 @@ public:
virtual void get_comment_delimiters(List<String> *p_delimiters) const;
virtual void get_string_delimiters(List<String> *p_delimiters) const;
virtual Ref<Script> get_template(const String &p_class_name, const String &p_base_class_name) const;
+ virtual bool is_using_templates();
+ virtual void make_template(const String &p_class_name, const String &p_base_class_name, Ref<Script> &p_script);
virtual bool validate(const String &p_script, int &r_line_error, int &r_col_error, String &r_test_error, const String &p_path = "", List<String> *r_functions = NULL) const;
virtual Script *create_script() const;
virtual bool has_named_classes() const;