* Preload all assets in a block
(blockId: string)
| 349 | * Preload all assets in a block |
| 350 | */ |
| 351 | private async preloadBlock(blockId: string): Promise<void> { |
| 352 | const block = Preload._blocks[blockId]; |
| 353 | if (!block) { |
| 354 | console.warn(`Preload: Block "${blockId}" not found`); |
| 355 | return; |
| 356 | } |
| 357 | |
| 358 | const promises: Promise<void>[] = []; |
| 359 | |
| 360 | for (const [category, assets] of Object.entries(block)) { |
| 361 | // Handle characters separately (nested structure) |
| 362 | if (category === 'characters' && typeof assets === 'object' && !Array.isArray(assets)) { |
| 363 | for (const [charId, sprites] of Object.entries(assets as Record<string, string[]>)) { |
| 364 | for (const spriteName of sprites) { |
| 365 | promises.push(this.preloadCharacterSprite(charId, spriteName)); |
| 366 | } |
| 367 | } |
| 368 | continue; |
| 369 | } |
| 370 | |
| 371 | if (!Array.isArray(assets)) continue; |
| 372 | |
| 373 | // Use registered loader for this category |
| 374 | if (Preload.hasLoader(category)) { |
| 375 | for (const assetName of assets) { |
| 376 | promises.push(this.preloadAsset(category, assetName)); |
| 377 | } |
| 378 | } else { |
| 379 | console.warn(`Preload: No loader registered for category "${category}" in block "${blockId}"`); |
| 380 | } |
| 381 | } |
| 382 | |
| 383 | await Promise.all(promises); |
| 384 | } |
| 385 | |
| 386 | override async apply(): Promise<void> { |
| 387 | // Start the preload operation |
no test coverage detected