Skip to content

Commit

Permalink
ensure script property is at the top
Browse files Browse the repository at this point in the history
  • Loading branch information
nikitalita committed Nov 5, 2024
1 parent c789196 commit dfd73d3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions compat/resource_compat_binary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2589,6 +2589,8 @@ Error ResourceFormatSaverCompatBinaryInstance::save(const String &p_path, const
List<PropertyInfo> property_list;
E->get_property_list(&property_list);

// COMPAT: if the script property isn't at the top, resources that are script instances will have their script properties stripped upon loading in the editor.
CompatFormatLoader::move_script_property_to_top(&property_list);
for (const PropertyInfo &F : property_list) {
if (skip_editor && F.name.begins_with("__editor")) {
continue;
Expand Down
3 changes: 3 additions & 0 deletions compat/resource_compat_text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2559,6 +2559,9 @@ Error ResourceFormatSaverCompatTextInstance::save(const String &p_path, const Re

List<PropertyInfo> property_list;
res->get_property_list(&property_list);

// COMPAT: if the script property isn't at the top, resources that are script instances will have their script properties stripped upon loading in the editor.
CompatFormatLoader::move_script_property_to_top(&property_list);
for (List<PropertyInfo>::Element *PE = property_list.front(); PE; PE = PE->next()) {
if (skip_editor && PE->get().name.begins_with("__editor")) {
continue;
Expand Down
12 changes: 12 additions & 0 deletions compat/resource_loader_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,18 @@ class CompatFormatLoader : public ResourceFormatLoader {
}
return ResourceInfo::LoadType::REAL_LOAD;
}

static void move_script_property_to_top(List<PropertyInfo> *p_properties) {
// TODO: remove this when we get proper script loaders
ERR_FAIL_COND(!p_properties);
for (List<PropertyInfo>::Element *E = p_properties->front(); E; E = E->next()) {
if (E->get().name == "script") {
p_properties->move_to_front(E);
return;
}
}
}

static Ref<Resource> create_missing_external_resource(const String &path, const String &type, const ResourceUID::ID uid, const String &scene_id = "") {
Ref<MissingResource> res{ memnew(MissingResource) };
res->set_original_class(type);
Expand Down

0 comments on commit dfd73d3

Please sign in to comment.