diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2018-08-15 15:16:29 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-15 15:16:29 +0200 |
commit | 040c6be426ea915a70eb7ded687c7618c33ad3ff (patch) | |
tree | d390ce325032a57568dc8d8730748602c9b9c812 /modules/gdscript/gdscript_parser.cpp | |
parent | 140b6db219c8b123ad3d5727df7f781f035fb399 (diff) | |
parent | 6d9cc032e71ccc768064bf908623b0954d01181c (diff) | |
download | redot-engine-040c6be426ea915a70eb7ded687c7618c33ad3ff.tar.gz |
Merge pull request #20560 from willnationsdev/class_icons
Add custom icons to script classes.
Diffstat (limited to 'modules/gdscript/gdscript_parser.cpp')
-rw-r--r-- | modules/gdscript/gdscript_parser.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp index e0ed2b332b..bec314866d 100644 --- a/modules/gdscript/gdscript_parser.cpp +++ b/modules/gdscript/gdscript_parser.cpp @@ -3429,6 +3429,32 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { tokenizer->advance(2); + if (tokenizer->get_token() == GDScriptTokenizer::TK_COMMA) { + tokenizer->advance(); + + if ((tokenizer->get_token() == GDScriptTokenizer::TK_CONSTANT && tokenizer->get_token_constant().get_type() == Variant::STRING)) { + Variant constant = tokenizer->get_token_constant(); + String icon_path = constant.operator String(); + + String abs_icon_path = icon_path.is_rel_path() ? self_path.get_base_dir().plus_file(icon_path).simplify_path() : icon_path; + if (!FileAccess::exists(abs_icon_path)) { + _set_error("No class icon found at: " + abs_icon_path); + return; + } + + p_class->icon_path = icon_path; + + tokenizer->advance(); + } else { + _set_error("Optional parameter after 'class_name' must be a string constant file path to an icon."); + return; + } + + } else if (tokenizer->get_token() == GDScriptTokenizer::TK_CONSTANT) { + _set_error("Class icon must be separated by a comma."); + return; + } + } break; case GDScriptTokenizer::TK_PR_TOOL: { |