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

Method load

core/io/json.cpp:1570–1604  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1568////////////
1569
1570Ref<Resource> ResourceFormatLoaderJSON::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_cache_mode) {
1571 if (r_error) {
1572 *r_error = ERR_FILE_CANT_OPEN;
1573 }
1574
1575 if (!FileAccess::exists(p_path)) {
1576 *r_error = ERR_FILE_NOT_FOUND;
1577 return Ref<Resource>();
1578 }
1579
1580 Ref<JSON> json;
1581 json.instantiate();
1582
1583 Error err = json->parse(FileAccess::get_file_as_string(p_path), Engine::get_singleton()->is_editor_hint());
1584 if (err != OK) {
1585 String err_text = "Error parsing JSON file at '" + p_path + "', on line " + itos(json->get_error_line()) + ": " + json->get_error_message();
1586
1587 if (Engine::get_singleton()->is_editor_hint()) {
1588 // If running on editor, still allow opening the JSON so the code editor can edit it.
1589 WARN_PRINT(err_text);
1590 } else {
1591 if (r_error) {
1592 *r_error = err;
1593 }
1594 ERR_PRINT(err_text);
1595 return Ref<Resource>();
1596 }
1597 }
1598
1599 if (r_error) {
1600 *r_error = OK;
1601 }
1602
1603 return json;
1604}
1605
1606void ResourceFormatLoaderJSON::get_recognized_extensions(List<String> *p_extensions) const {
1607 p_extensions->push_back("json");

Callers 15

lockMethod · 0.45
insertMethod · 0.45
eraseMethod · 0.45
beginMethod · 0.45
maybe_cleanupMethod · 0.45
flush_if_pendingMethod · 0.45
get_or_nullMethod · 0.45
getMethod · 0.45
exchange_if_greaterMethod · 0.45
conditional_incrementMethod · 0.45
is_setMethod · 0.45
lockstepMethod · 0.45

Calls 6

itosFunction · 0.85
get_error_messageMethod · 0.80
instantiateMethod · 0.45
parseMethod · 0.45
is_editor_hintMethod · 0.45
get_error_lineMethod · 0.45

Tested by 3

lockstepMethod · 0.36
~RID_OwnerTesterMethod · 0.36
testMethod · 0.36