diff --git a/src/io/sb3/interfaces.ts b/src/io/sb3/interfaces.ts index 0a0c8fca..ba123044 100644 --- a/src/io/sb3/interfaces.ts +++ b/src/io/sb3/interfaces.ts @@ -331,14 +331,7 @@ export type BlockInputValue = Readonly< // (which could imply special handling for the other INPUT_BLOCK_* values, // when none such is required and whose values are never specified in this // mapping). -export const inputPrimitiveOrShadowMap: { - // Custom procedure blocks should be serialized separately from how normal - // blocks are, since most of their data is stored on a "mutation" field not - // accounted for here. - [opcode in Exclude]: { - [fieldName: string]: number | OpCode; - }; -} = { +export const inputPrimitiveOrShadowMap = { [OpCode.motion_movesteps]: { STEPS: BIS.MATH_NUM_PRIMITIVE }, [OpCode.motion_turnright]: { DEGREES: BIS.MATH_NUM_PRIMITIVE }, [OpCode.motion_turnleft]: { DEGREES: BIS.MATH_NUM_PRIMITIVE }, @@ -524,4 +517,11 @@ export const inputPrimitiveOrShadowMap: { [OpCode.data_hidelist]: {}, [OpCode.argument_reporter_boolean]: {}, [OpCode.argument_reporter_string_number]: {} +} as const satisfies { + // Custom procedure blocks should be serialized separately from how normal + // blocks are, since most of their data is stored on a "mutation" field not + // accounted for here. + [opcode in Exclude]: { + [fieldName: string]: number | OpCode; + }; }; diff --git a/src/io/sb3/toSb3.ts b/src/io/sb3/toSb3.ts index 5f38f31d..bfcc78bb 100644 --- a/src/io/sb3/toSb3.ts +++ b/src/io/sb3/toSb3.ts @@ -4,7 +4,6 @@ import Target, { Sprite, Stage } from "../../Target"; import * as BlockInput from "../../BlockInput"; import * as sb3 from "./interfaces"; import { OpCode } from "../../OpCode"; -import { prop } from "../../util/ts-util"; const BIS = sb3.BlockInputStatus; @@ -506,13 +505,10 @@ export default function toSb3(project: Project, options: Partial = for (const arg of args) { const shadowId = arg.id + "-prototype-shadow"; blockData[shadowId] = { - opcode: prop( - { - boolean: OpCode.argument_reporter_boolean, - numberOrString: OpCode.argument_reporter_string_number - }, - arg.type - ), + opcode: { + boolean: OpCode.argument_reporter_boolean, + numberOrString: OpCode.argument_reporter_string_number + }[arg.type], next: null, parent: prototypeId, @@ -617,7 +613,7 @@ export default function toSb3(project: Project, options: Partial = } default: { - const inputEntries = prop(sb3.inputPrimitiveOrShadowMap, block.opcode); + const inputEntries = sb3.inputPrimitiveOrShadowMap[block.opcode]; const initialValues: Record> = {}; for (const key of Object.keys(inputEntries)) { @@ -843,13 +839,10 @@ export default function toSb3(project: Project, options: Partial = id, name, type, - default: prop( - { - boolean: "false", - numberOrString: "" - }, - type - ) + default: { + boolean: "false", + numberOrString: "" + }[type] }); } diff --git a/src/util/ts-util.ts b/src/util/ts-util.ts deleted file mode 100644 index e0bd5873..00000000 --- a/src/util/ts-util.ts +++ /dev/null @@ -1,11 +0,0 @@ -// General-purpose utility functions for TypeScript - -// Gets a property from an object, asserting that the property exists within -// that object. Useful for cases where an undefined property should error, -// since those cases will be caught at compile rather than runtime. -// -// From: -// https://mariusschulz.com/blog/keyof-and-lookup-types-in-typescript -export function prop(obj: T, key: K): T[K] { - return obj[key]; -}