| 3123 | Ref<PackedScene> _ensure_resource_is_packed_scene(const Ref<Resource> &p_resource, HashMap<String, Ref<Resource>> &p_seen_resources, HashSet<Object *> &seen_objects, int recursion_depth); |
| 3124 | |
| 3125 | Variant scan_variant(const Variant &v, HashMap<String, Ref<Resource>> &p_seen_resources, HashSet<Object *> &seen_objects, int recursion_depth) { |
| 3126 | ERR_FAIL_COND_V_MSG(recursion_depth > 1024, Variant(), "Recursion depth exceeded"); |
| 3127 | recursion_depth++; |
| 3128 | Variant result = v; |
| 3129 | switch (v.get_type()) { |
| 3130 | case Variant::OBJECT: { |
| 3131 | Ref<Resource> res = v; |
| 3132 | if (is_packed_scene(res)) { |
| 3133 | Ref<PackedScene> sub_scene; |
| 3134 | if (!p_seen_resources.has(res->get_path())) { |
| 3135 | if (_resource_get_class(res) == "PackedScene") { |
| 3136 | sub_scene = _ensure_resource_is_packed_scene(res, p_seen_resources, seen_objects, recursion_depth); |
| 3137 | } |
| 3138 | } else { |
| 3139 | sub_scene = p_seen_resources.get(res->get_path()); |
| 3140 | } |
| 3141 | if (sub_scene.is_valid()) { |
| 3142 | p_seen_resources[res->get_path()] = sub_scene; |
| 3143 | result = sub_scene; |
| 3144 | } else { |
| 3145 | p_seen_resources[res->get_path()] = res; |
| 3146 | result = res; |
| 3147 | } |
| 3148 | } else if (res.is_valid()) { |
| 3149 | if (!p_seen_resources.has(res->get_path())) { |
| 3150 | List<PropertyInfo> property_list; |
| 3151 | res->get_property_list(&property_list); |
| 3152 | for (const PropertyInfo &pi : property_list) { |
| 3153 | Variant v = scan_variant(res->get(pi.name), p_seen_resources, seen_objects, recursion_depth); |
| 3154 | res->set(pi.name, v); |
| 3155 | } |
| 3156 | p_seen_resources[res->get_path()] = res; |
| 3157 | } |
| 3158 | } else if (Object *obj = v.operator Object *(); obj != nullptr && !seen_objects.has(obj)) { |
| 3159 | seen_objects.insert(obj); |
| 3160 | List<PropertyInfo> property_list; |
| 3161 | obj->get_property_list(&property_list); |
| 3162 | for (const PropertyInfo &pi : property_list) { |
| 3163 | if (pi.usage & PROPERTY_USAGE_STORAGE) { |
| 3164 | Variant v = scan_variant(obj->get(pi.name), p_seen_resources, seen_objects, recursion_depth); |
| 3165 | obj->set(pi.name, v); |
| 3166 | } |
| 3167 | } |
| 3168 | } |
| 3169 | } break; |
| 3170 | case Variant::ARRAY: { |
| 3171 | Array a = v; |
| 3172 | for (int j = 0; j < a.size(); j++) { |
| 3173 | a[j] = scan_variant(a[j], p_seen_resources, seen_objects, recursion_depth); |
| 3174 | } |
| 3175 | result = a; |
| 3176 | } break; |
| 3177 | case Variant::DICTIONARY: { |
| 3178 | Dictionary d; |
| 3179 | for (const KeyValue<Variant, Variant> &kv : v.operator Dictionary()) { |
| 3180 | Variant key = scan_variant(kv.key, p_seen_resources, seen_objects, recursion_depth); |
| 3181 | Variant value = scan_variant(kv.value, p_seen_resources, seen_objects, recursion_depth); |
| 3182 | d[key] = value; |
no test coverage detected