MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / ChangeId

Method ChangeId

Source/Engine/Content/Storage/JsonStorageProxy.cpp:94–147  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

92#endif
93
94bool JsonStorageProxy::ChangeId(const StringView& path, const Guid& newId)
95{
96#if USE_EDITOR
97 PROFILE_CPU();
98
99 // Load file
100 Array<byte> fileData;
101 if (File::ReadAllBytes(path, fileData))
102 return false;
103
104 // Parse data
105 rapidjson_flax::Document document;
106 {
107 PROFILE_CPU_NAMED("Json.Parse");
108 document.Parse((const char*)fileData.Get(), fileData.Count());
109 }
110 if (document.HasParseError())
111 {
112 Log::JsonParseException(document.GetParseError(), document.GetErrorOffset(), path);
113 return false;
114 }
115
116 // Get all IDs inside the file
117 HashSet<Guid> ids;
118 FindObjectIds(document, document, ids);
119
120 // Remap into a unique IDs
121 Dictionary<Guid, Guid> remap;
122 remap.EnsureCapacity(ids.Count());
123 for (const auto& id : ids)
124 remap.Add(id.Item, Guid::New());
125
126 // Remap asset ID using the provided value
127 auto idNode = document.FindMember("ID");
128 if (idNode == document.MemberEnd())
129 return true;
130 remap[JsonTools::GetGuid(idNode->value)] = newId;
131
132 // Change IDs of asset and objects inside asset
133 JsonTools::ChangeIds(document, remap);
134
135 // Save to file
136 rapidjson_flax::StringBuffer buffer;
137 PrettyJsonWriter writer(buffer);
138 document.Accept(writer.GetWriter());
139 if (File::WriteAllBytes(path, (byte*)buffer.GetString(), (int32)buffer.GetSize()))
140 return true;
141
142 return false;
143#else
144 LOG(Warning, "Editing cooked content is invalid.");
145 return true;
146#endif
147}

Callers

nothing calls this directly

Calls 15

JsonParseExceptionClass · 0.85
FindObjectIdsFunction · 0.85
GetGuidFunction · 0.85
ChangeIdsFunction · 0.85
GetParseErrorMethod · 0.80
FindMemberMethod · 0.80
MemberEndMethod · 0.80
NewFunction · 0.50
ParseMethod · 0.45
GetMethod · 0.45
CountMethod · 0.45
HasParseErrorMethod · 0.45

Tested by

no test coverage detected