MCPcopy Create free account
hub / github.com/GDRETools/gdsdecomp / _parse_ext_resource

Method _parse_ext_resource

compat/resource_compat_text.cpp:153–214  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

151}
152
153Error ResourceLoaderCompatText::_parse_ext_resource(VariantParser::Stream *p_stream, Ref<Resource> &r_res, int &line, String &r_err_str) {
154 VariantParser::Token token;
155 VariantParser::get_token(p_stream, token, line, r_err_str);
156 if (token.type != VariantParser::TK_NUMBER && token.type != VariantParser::TK_STRING) {
157 r_err_str = "Expected number (old style sub-resource index) or String (ext-resource ID)";
158 return ERR_PARSE_ERROR;
159 }
160
161 String id = token.value;
162 Error err = OK;
163
164 if (!ignore_resource_parsing) {
165 if (!ext_resources.has(id)) {
166 r_err_str = "Can't load cached ext-resource id: " + id;
167 return ERR_PARSE_ERROR;
168 }
169
170 String path = ext_resources[id].path;
171 String type = ext_resources[id].type;
172 Ref<ResourceLoader::LoadToken> &load_token = ext_resources[id].load_token;
173
174 if (load_token.is_valid()) { // If not valid, it's OK since then we know this load accepts broken dependencies.
175 Ref<Resource> res = finish_ext_load(load_token, &err);
176 if (res.is_null()) {
177 ERR_FAIL_COND_V_MSG(!is_real_load(), ERR_FILE_MISSING_DEPENDENCIES, "WE SHOULD NEVER GET HERE!!!!!!!!!!!!!!!!!!!!!!!!! : [ext_resource] referenced non-existent resource at: " + path);
178 if (!ResourceLoader::is_cleaning_tasks()) {
179 if (ResourceLoader::get_abort_on_missing_resources()) {
180 error = ERR_FILE_MISSING_DEPENDENCIES;
181 error_text = "[ext_resource] referenced non-existent resource at: " + path;
182 _printerr();
183 err = error;
184 } else {
185 ResourceLoader::notify_dependency_error(local_path, path, type);
186 }
187 }
188 } else {
189#ifdef TOOLS_ENABLED
190 //remember ID for saving
191 res->set_id_for_path(local_path, id);
192#endif
193 r_res = res;
194 }
195 } else {
196 r_res = Ref<Resource>();
197 }
198#ifdef TOOLS_ENABLED
199 if (r_res.is_null()) {
200 // Hack to allow checking original path.
201 r_res.instantiate();
202 r_res->set_meta("__load_path__", ext_resources[id].path);
203 }
204#endif
205 }
206
207 VariantParser::get_token(p_stream, token, line, r_err_str);
208 if (token.type != VariantParser::TK_PARENTHESIS_CLOSE) {
209 r_err_str = "Expected ')'";
210 return ERR_PARSE_ERROR;

Callers 1

_parse_ext_resourcesMethod · 0.80

Calls 1

is_validMethod · 0.45

Tested by

no test coverage detected