Skip to content

Commit

Permalink
Format in MakeCode style to prevent pointless workspace saves
Browse files Browse the repository at this point in the history
  • Loading branch information
microbit-robert committed Dec 3, 2024
1 parent 5e062f1 commit 23a991d
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/makecode/generate-main-scripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ interface BlockPos {
y: number;
}

const onMLEventBlock = (name: string, children: string, pos: BlockPos) => `
<block type="ml_on_event_start" x="${pos.x}" y="${pos.y}">
<field name="event">ml.event.${name}</field>
<statement name="HANDLER">
${children}
</statement>
</block>
`;
const onMLEventBlock = (name: string, children: string, pos: BlockPos) => {
let code = "";
code += `<block type="ml_on_event_start" x="${pos.x}" y="${pos.y}">`;
code += `<field name="event">ml.event.${name}</field>`;
code += '<statement name="HANDLER">';
code += children;
code += "</statement>";
code += "</block>";
return code;
};

type Language = "blocks" | "javascript";

Expand All @@ -38,7 +40,7 @@ const statements: Record<Language, LanguageStatements> = {
javascript: {
wrapper: (children) => children + "\n",
showLeds: (ledPattern) => `basic.showLeds(\`${ledPattern}\`)`,
showIcon: (iconName) => `basic.showIcon(IconNames.${iconName})`,
showIcon: (iconName) => `\n basic.showIcon(IconNames.${iconName})\n`,
clearDisplay: () => "basic.clearScreen()",
onMLEvent: (name, children) => {
return `ml.onStart(ml.event.${name}, function () {${children}})`;
Expand Down Expand Up @@ -80,6 +82,6 @@ export const getMainScript = (actions: Action[], lang: Language) => {
y: initPos.y + idx * 180,
})
)
.join("\n")
.join(lang === "javascript" ? "\n" : "")
);
};

0 comments on commit 23a991d

Please sign in to comment.