| 12 | namespace asset |
| 13 | { |
| 14 | void* SJsonConfigImporter::Import(skr_io_ram_service_t* ioService, SCookContext* context) |
| 15 | { |
| 16 | const auto assetRecord = context->GetAssetRecord(); |
| 17 | auto type = skr::rttr::get_type_from_guid(configType); |
| 18 | if (type == nullptr) |
| 19 | { |
| 20 | SKR_LOG_ERROR(u8"import resource %s failed, rtti is not load", assetRecord->path.u8string().c_str()); |
| 21 | return nullptr; |
| 22 | } |
| 23 | |
| 24 | skr::BlobId blob = nullptr; |
| 25 | context->AddFileDependencyAndLoad(ioService, assetPath.c_str(), blob); |
| 26 | SKR_DEFER({blob.reset();}); |
| 27 | |
| 28 | auto jsonString = simdjson::padded_string((char*)blob->get_data(), blob->get_size()); |
| 29 | simdjson::ondemand::parser parser; |
| 30 | auto doc = parser.iterate(jsonString); |
| 31 | if(doc.error()) |
| 32 | { |
| 33 | SKR_LOG_FMT_ERROR(u8"Import config asset {} from {} failed, json parse error {}", assetRecord->guid, assetPath, simdjson::error_message(doc.error())); |
| 34 | return nullptr; |
| 35 | } |
| 36 | |
| 37 | //skr::resource::SConfigFactory::NewConfig(configType); |
| 38 | skr_config_resource_t* resource = SkrNew<skr_config_resource_t>(); |
| 39 | resource->SetType(configType); |
| 40 | type->read_json(resource->configData, doc.get_value().value_unsafe()); |
| 41 | return resource; //导入具体数据 |
| 42 | } |
| 43 | |
| 44 | void SJsonConfigImporter::Destroy(void* resource) |
| 45 | { |
no test coverage detected