| 12 | * JSON加载器实现 |
| 13 | */ |
| 14 | export class JsonLoader implements IAssetLoader<IJsonAsset> { |
| 15 | readonly supportedType = AssetType.Json; |
| 16 | readonly supportedExtensions = ['.json', '.jsonc']; |
| 17 | readonly contentType: AssetContentType = 'text'; |
| 18 | |
| 19 | /** |
| 20 | * Parse JSON from text content. |
| 21 | * 从文本内容解析JSON。 |
| 22 | */ |
| 23 | async parse(content: IAssetContent, _context: IAssetParseContext): Promise<IJsonAsset> { |
| 24 | if (!content.text) { |
| 25 | throw new Error('JSON content is empty'); |
| 26 | } |
| 27 | |
| 28 | return { |
| 29 | data: JSON.parse(content.text) |
| 30 | }; |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * Dispose loaded asset |
| 35 | * 释放已加载的资产 |
| 36 | */ |
| 37 | dispose(asset: IJsonAsset): void { |
| 38 | // 清空 JSON 数据 | Clear JSON data |
| 39 | asset.data = null; |
| 40 | } |
| 41 | } |
nothing calls this directly
no outgoing calls
no test coverage detected