Skip to content

Commit

Permalink
fromSb3: don't re-run getBlockScript redundantly
Browse files Browse the repository at this point in the history
getBlockScript returns a function which is useful for getting any
top-level script, and getBlockScript only operates on the total
list of the target's blocks, which doesn't change dependant on the
script you are trying to access. So use it like the currying
function it presents itself as and don't re-run getBlockScript
for every script in the target.
  • Loading branch information
towerofnix committed May 30, 2024
1 parent 5c6c6b9 commit 89c55d2
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/io/sb3/fromSb3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,8 @@ export async function fromSb3JSON(json: sb3.ProjectJSON, options: { getAsset: Ge
extractSounds(target, options.getAsset)
]);

const getScript = getBlockScript(target.blocks);

return {
name: target.name,
isStage: target.isStage,
Expand All @@ -402,7 +404,7 @@ export async function fromSb3JSON(json: sb3.ProjectJSON, options: { getAsset: Ge
.map(
([id, block]) =>
new Script({
blocks: getBlockScript(target.blocks)(id),
blocks: getScript(id),
x: block.x,
y: block.y
})
Expand Down

0 comments on commit 89c55d2

Please sign in to comment.