MCPcopy Create free account
hub / github.com/esengine/esengine / TilemapLoader

Class TilemapLoader

packages/tilemap/src/loaders/TilemapLoader.ts:54–93  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

52 * 瓦片地图加载器实现
53 */
54export class TilemapLoader implements IAssetLoader<ITilemapAsset> {
55 readonly supportedType = TilemapAssetType;
56 readonly supportedExtensions = ['.tilemap.json', '.tilemap'];
57 readonly contentType: AssetContentType = 'text';
58
59 /**
60 * Parse tilemap asset from text content
61 * 从文本内容解析瓦片地图资产
62 */
63 async parse(content: IAssetContent, _context: IAssetParseContext): Promise<ITilemapAsset> {
64 if (!content.text) {
65 throw new Error('Tilemap content is empty');
66 }
67
68 const jsonData = JSON.parse(content.text) as ITilemapAsset;
69
70 // 验证必要字段
71 // Validate required fields
72 if (!jsonData.width || !jsonData.height || !jsonData.data) {
73 throw new Error('Invalid tilemap format: missing required fields');
74 }
75
76 return jsonData;
77 }
78
79 /**
80 * Dispose loaded asset
81 * 释放已加载的资产
82 */
83 dispose(asset: ITilemapAsset): void {
84 // 清理瓦片数据 | Clean up tile data
85 asset.data.length = 0;
86 if (asset.layers) {
87 asset.layers.length = 0;
88 }
89 if (asset.collisionData) {
90 asset.collisionData.length = 0;
91 }
92 }
93}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected