MCPcopy Create free account
hub / github.com/Redot-Engine/redot-engine / get_script_icon

Method get_script_icon

editor/editor_data.cpp:1126–1190  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1124}
1125
1126Ref<Texture2D> EditorData::get_script_icon(const String &p_script_path) {
1127 // Take from the local cache, if available.
1128 {
1129 Ref<Texture2D> *icon = _script_icon_cache.getptr(p_script_path);
1130 if (icon) {
1131 // Can be an empty value if we can't resolve any icon for this script.
1132 // An empty value is still cached to avoid unnecessary attempts at resolving it again.
1133 return *icon;
1134 }
1135 }
1136
1137 // Fast path in case the whole hierarchy is made of global classes.
1138 StringName class_name = script_class_get_name(p_script_path);
1139 {
1140 if (class_name != StringName()) {
1141 bool icon_valid = false;
1142 String icon_path = script_class_get_icon_path(class_name, &icon_valid);
1143 if (icon_valid) {
1144 Ref<Texture2D> icon = _load_script_icon(icon_path);
1145 _script_icon_cache[p_script_path] = icon;
1146 return icon;
1147 }
1148 }
1149 }
1150
1151 Ref<Script> base_scr = ResourceLoader::load(p_script_path, "Script");
1152 while (base_scr.is_valid()) {
1153 // Check for scripted classes.
1154 String icon_path;
1155 StringName base_class_name = script_class_get_name(base_scr->get_path());
1156 if (base_scr->is_built_in() || base_class_name == StringName()) {
1157 icon_path = base_scr->get_class_icon_path();
1158 } else {
1159 icon_path = script_class_get_icon_path(base_class_name);
1160 }
1161
1162 Ref<Texture2D> icon = _load_script_icon(icon_path);
1163 if (icon.is_valid()) {
1164 _script_icon_cache[p_script_path] = icon;
1165 return icon;
1166 }
1167
1168 /// Check for legacy custom classes defined by plugins.
1169 /// @todo Should probably be deprecated in 4.x
1170 const EditorData::CustomType *ctype = get_custom_type_by_path(base_scr->get_path());
1171 if (ctype && ctype->icon.is_valid()) {
1172 _script_icon_cache[p_script_path] = ctype->icon;
1173 return ctype->icon;
1174 }
1175
1176 // Move to the base class.
1177 base_scr = base_scr->get_base_script();
1178 }
1179
1180 // Check if the base type is an extension-defined type.
1181 Ref<Texture2D> ext_icon = extension_class_get_icon(class_name);
1182 if (ext_icon.is_valid()) {
1183 _script_icon_cache[p_script_path] = ext_icon;

Callers 2

update_treeMethod · 0.80

Calls 7

is_built_inMethod · 0.80
StringNameClass · 0.50
getptrMethod · 0.45
is_validMethod · 0.45
get_pathMethod · 0.45
get_class_icon_pathMethod · 0.45
get_base_scriptMethod · 0.45

Tested by

no test coverage detected