Builtin script template loading improvements
This commit is contained in:
parent
056b5f9e56
commit
2ab512a07b
1 changed files with 36 additions and 10 deletions
|
@ -216,17 +216,43 @@ Variant _EDITOR_DEF(const String &p_var, const Variant &p_default) {
|
|||
return p_default;
|
||||
}
|
||||
|
||||
static Dictionary _get_builtin_script_templates() {
|
||||
Dictionary templates;
|
||||
|
||||
//No Comments
|
||||
templates["no_comments.gd"] =
|
||||
"extends %BASE%\n"
|
||||
"\n"
|
||||
"func _ready():\n"
|
||||
"%TS%pass\n";
|
||||
|
||||
//Empty
|
||||
templates["empty.gd"] =
|
||||
"extends %BASE%"
|
||||
"\n"
|
||||
"\n";
|
||||
|
||||
return templates;
|
||||
}
|
||||
|
||||
static void _create_script_templates(const String &p_path) {
|
||||
|
||||
FileAccess *file = FileAccess::open(p_path.plus_file("no_comments.gd"), FileAccess::WRITE);
|
||||
ERR_FAIL_COND(!file);
|
||||
String script = String("extends %BASE%\n\nfunc _ready():\n%TS%pass\n");
|
||||
file->store_string(script);
|
||||
file->close();
|
||||
file->reopen(p_path.plus_file("empty.gd"), FileAccess::WRITE);
|
||||
script = "extends %BASE%\n\n";
|
||||
file->store_string(script);
|
||||
file->close();
|
||||
Dictionary templates = _get_builtin_script_templates();
|
||||
List<Variant> keys;
|
||||
templates.get_key_list(&keys);
|
||||
FileAccess *file = FileAccess::create(FileAccess::ACCESS_FILESYSTEM);
|
||||
|
||||
DirAccess *dir = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
|
||||
dir->change_dir(p_path);
|
||||
for (int i = 0; i < keys.size(); i++) {
|
||||
if (!dir->file_exists(keys[i])) {
|
||||
file->reopen(p_path.plus_file((String)keys[i]), FileAccess::WRITE);
|
||||
ERR_FAIL_COND(!file);
|
||||
file->store_string(templates[keys[i]]);
|
||||
file->close();
|
||||
}
|
||||
}
|
||||
|
||||
memdelete(file);
|
||||
}
|
||||
|
||||
|
@ -308,10 +334,10 @@ void EditorSettings::create() {
|
|||
|
||||
if (dir->change_dir("script_templates") != OK) {
|
||||
dir->make_dir("script_templates");
|
||||
_create_script_templates(dir->get_current_dir() + "/script_templates");
|
||||
} else {
|
||||
dir->change_dir("..");
|
||||
}
|
||||
_create_script_templates(dir->get_current_dir() + "/script_templates");
|
||||
|
||||
if (dir->change_dir("tmp") != OK) {
|
||||
dir->make_dir("tmp");
|
||||
|
|
Loading…
Reference in a new issue