| 1568 | //////////// |
| 1569 | |
| 1570 | Ref<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 | |
| 1606 | void ResourceFormatLoaderJSON::get_recognized_extensions(List<String> *p_extensions) const { |
| 1607 | p_extensions->push_back("json"); |