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

Class ParticleLoader

packages/particle/src/loaders/ParticleLoader.ts:207–243  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

205 * Particle effect loader implementation
206 */
207export class ParticleLoader implements IAssetLoader<IParticleAsset> {
208 readonly supportedType = ParticleAssetType;
209 readonly supportedExtensions = ['.particle', '.particle.json'];
210 readonly contentType: AssetContentType = 'text';
211
212 /**
213 * 从文本内容解析粒子资源
214 * Parse particle asset from text content
215 */
216 async parse(content: IAssetContent, _context: IAssetParseContext): Promise<IParticleAsset> {
217 if (!content.text) {
218 throw new Error('Particle content is empty');
219 }
220
221 const jsonData = JSON.parse(content.text) as IParticleAsset;
222
223 // 验证必要字段 | Validate required fields
224 if (jsonData.maxParticles === undefined) {
225 throw new Error('Invalid particle format: missing maxParticles');
226 }
227
228 // 填充默认值 | Fill default values
229 const defaults = createDefaultParticleAsset();
230 return { ...defaults, ...jsonData };
231 }
232
233 /**
234 * 释放已加载的资源
235 * Dispose loaded asset
236 */
237 dispose(asset: IParticleAsset): void {
238 // 清理模块引用 | Clean up module references
239 if (asset.modules) {
240 asset.modules.length = 0;
241 }
242 }
243}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected