Skip to content

Commit

Permalink
Make costume/sound promises async fns
Browse files Browse the repository at this point in the history
  • Loading branch information
valadaptive committed May 29, 2024
1 parent 96a3d50 commit d4d18d1
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -676,21 +676,27 @@ const parseTarget = async(
lists.set(name, value);
}

const costumePromises = jsonTarget.costumes.map(costume => loader.loadAsset(
`${costume.assetId}.${costume.dataFormat}`,
contentTypeForDataFormat[costume.dataFormat],
)
.then(asset => runtime.loadCostume(costume.name, asset, {
rotationCenter: {x: costume.rotationCenterX, y: costume.rotationCenterY},
bitmapResolution: costume.bitmapResolution ?? 1,
type: costume.dataFormat === 'svg' ? 'svg' : 'bitmap',
})));

const soundPromises = jsonTarget.sounds.map(sound => loader.loadAsset(
`${sound.assetId}.${sound.dataFormat}`,
contentTypeForDataFormat[sound.dataFormat],
)
.then(asset => runtime.loadSound(sound.name, asset)));
const costumePromises = jsonTarget.costumes.map(async jsonCostume => {
const asset = await loader.loadAsset(
`${jsonCostume.assetId}.${jsonCostume.dataFormat}`,
contentTypeForDataFormat[jsonCostume.dataFormat],
);
const costume = await runtime.loadCostume(jsonCostume.name, asset, {
rotationCenter: {x: jsonCostume.rotationCenterX, y: jsonCostume.rotationCenterY},
bitmapResolution: jsonCostume.bitmapResolution ?? 1,
type: jsonCostume.dataFormat === 'svg' ? 'svg' : 'bitmap',
});
return costume;
});

const soundPromises = jsonTarget.sounds.map(async jsonSound => {
const asset = await loader.loadAsset(
`${jsonSound.assetId}.${jsonSound.dataFormat}`,
contentTypeForDataFormat[jsonSound.dataFormat],
);
const sound = await runtime.loadSound(jsonSound.name, asset);
return sound;
});

const [costumes, sounds] = await Promise.all([Promise.all(costumePromises), Promise.all(soundPromises)]);

Expand Down

0 comments on commit d4d18d1

Please sign in to comment.