Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fromSb3: Fix loading undefined sb3Block.next #146

Merged
merged 2 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/io/sb3/fromSb3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,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 @@ -302,7 +302,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 @@ -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
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
Loading