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

Method _write_resource

compat/resource_compat_text.cpp:1927–1979  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1925}
1926
1927String ResourceFormatSaverCompatTextInstance::_write_resource(const Ref<Resource> &res) {
1928 if (res->get_meta(SNAME("_skip_save_"), false)) {
1929 return "null";
1930 }
1931
1932 String prefix;
1933 String id;
1934 String suffix = format_version >= 3 ? "\")" : " )";
1935 // Godot 3.x had a format like this (note the spaces):
1936 // ExtResource( 1 )
1937 // Godot 4.x has a format like this:
1938 // ExtResource("2_dhasdh")
1939 if (external_resources.has(res)) {
1940 prefix = "ExtResource(" + String(format_version >= 3 ? "\"" : " ");
1941 id = external_resources[res];
1942 } else if (internal_resources.has(res)) {
1943 prefix = "SubResource(" + String(format_version >= 3 ? "\"" : " ");
1944 id = internal_resources[res];
1945 } else if (!res->is_built_in()) {
1946 if (res->get_path() == local_path) { //circular reference attempt
1947 return "null";
1948 }
1949 //external resource
1950 String path = relative_paths ? local_path.path_to_file(res->get_path()) : res->get_path();
1951 prefix = "Resource(" + String(format_version >= 3 ? "" : " ");
1952 suffix = format_version >= 3 ? suffix : " )";
1953 id = "\"" + path + "\"";
1954 } else {
1955 ERR_FAIL_V_MSG("null", "Resource was not pre cached for the resource section, bug?");
1956 //internal resource
1957 }
1958
1959 return prefix + id + suffix;
1960#if 0
1961 if (external_resources.has(res)) {
1962 return "ExtResource(\"" + external_resources[res] + "\")";
1963 } else {
1964 if (internal_resources.has(res)) {
1965 return "SubResource(\"" + internal_resources[res] + "\")";
1966 } else if (!res->is_built_in()) {
1967 if (res->get_path() == local_path) { //circular reference attempt
1968 return "null";
1969 }
1970 //external resource
1971 String path = relative_paths ? local_path.path_to_file(res->get_path()) : res->get_path();
1972 return "Resource(\"" + path + "\")";
1973 } else {
1974 ERR_FAIL_V_MSG("null", "Resource was not pre cached for the resource section, bug?");
1975 //internal resource
1976 }
1977 }
1978#endif
1979}
1980
1981String ResourceFormatSaverCompatTextInstance::get_id_for_ext_resource(Ref<Resource> res, int ext_resources_size) {
1982 Ref<ResourceInfo> compat = ResourceInfo::get_info_from_resource(res);

Callers 1

_write_resourcesMethod · 0.80

Calls 1

get_pathMethod · 0.45

Tested by

no test coverage detected