| 240 | #endif |
| 241 | |
| 242 | Asset::LoadResult JsonAssetBase::loadAsset() |
| 243 | { |
| 244 | if (IsVirtual() || _isVirtualDocument) |
| 245 | return LoadResult::Ok; |
| 246 | PROFILE_MEM(ContentAssets); |
| 247 | |
| 248 | // Load data (raw json file in editor, cooked asset in build game) |
| 249 | #if USE_EDITOR |
| 250 | BytesContainer data; |
| 251 | if (File::ReadAllBytes(_path, data)) |
| 252 | { |
| 253 | LOG(Warning, "Filed to load json asset data. {0}", ToString()); |
| 254 | return LoadResult::CannotLoadData; |
| 255 | } |
| 256 | if (data.Length() == 0) |
| 257 | { |
| 258 | return LoadResult::MissingDataChunk; |
| 259 | } |
| 260 | #else |
| 261 | // Get the asset storage container but don't load it now |
| 262 | const auto storage = ContentStorageManager::GetStorage(_path, true); |
| 263 | if (!storage) |
| 264 | return LoadResult::CannotLoadStorage; |
| 265 | |
| 266 | // Load header |
| 267 | AssetInitData initData; |
| 268 | if (storage->LoadAssetHeader(GetID(), initData)) |
| 269 | return LoadResult::CannotLoadInitData; |
| 270 | |
| 271 | // Load the actual data |
| 272 | auto chunk = initData.Header.Chunks[0]; |
| 273 | if (chunk == nullptr) |
| 274 | return LoadResult::MissingDataChunk; |
| 275 | if (storage->LoadAssetChunk(chunk)) |
| 276 | return LoadResult::CannotLoadData; |
| 277 | auto& data = chunk->Data; |
| 278 | #endif |
| 279 | |
| 280 | // Parse json document |
| 281 | { |
| 282 | PROFILE_CPU_NAMED("Json.Parse"); |
| 283 | Document.Parse(data.Get<char>(), data.Length()); |
| 284 | } |
| 285 | if (Document.HasParseError()) |
| 286 | { |
| 287 | Log::JsonParseException(Document.GetParseError(), Document.GetErrorOffset()); |
| 288 | return LoadResult::CannotLoadData; |
| 289 | } |
| 290 | |
| 291 | // Gather information from the header |
| 292 | const auto id = JsonTools::GetGuid(Document, "ID"); |
| 293 | if (id != _id) |
| 294 | { |
| 295 | LOG(Warning, "Invalid json asset id. Asset: {0}, serialized: {1}.", _id, id); |
| 296 | return LoadResult::InvalidData; |
| 297 | } |
| 298 | DataTypeName = JsonTools::GetString(Document, "TypeName"); |
| 299 | DataEngineBuild = JsonTools::GetInt(Document, "EngineBuild", FLAXENGINE_VERSION_BUILD); |
nothing calls this directly
no test coverage detected