Skip to content

Commit

Permalink
Merge pull request #146 from towerofnix/block-with-next
Browse files Browse the repository at this point in the history
fromSb3: Fix loading undefined sb3Block.next
  • Loading branch information
PullJosh authored Jun 17, 2024
2 parents 27ed1dc + 89c55d2 commit 9b0f978
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/io/sb3/fromSb3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ function getBlockScript(blocks: { [key: string]: sb3.Block }) {
}
}

function blockWithNext(blockId: string, parentId: string | undefined = undefined): Block[] {
function blockWithNext(blockId: string, parentId?: string): Block[] {
const sb3Block = blocks[blockId];
const block = new BlockBase({
opcode: sb3Block.opcode,
Expand All @@ -315,7 +315,7 @@ function getBlockScript(blocks: { [key: string]: sb3.Block }) {
next: sb3Block.next ?? undefined
}) as Block;
let next: Block[] = [];
if (sb3Block.next !== null) {
if (typeof sb3Block.next === "string") {
next = blockWithNext(sb3Block.next, blockId);
}
return [block, ...next];
Expand Down Expand Up @@ -404,6 +404,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 @@ -415,7 +417,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
4 changes: 2 additions & 2 deletions src/io/sb3/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ type MutationFor<Op extends OpCode> = Op extends OpCode.procedures_prototype
export interface Block<Op extends OpCode = OpCode> {
opcode: Op;

next: string | null;
parent: string | null;
next?: string | null;
parent?: string | null;

inputs: {
[key: string]: BlockInput;
Expand Down

0 comments on commit 9b0f978

Please sign in to comment.