UNPKG

sb-edit

Version:

Import, edit, and export Scratch project files

625 lines (624 loc) 21.7 kB
import { OpCode } from "../../OpCode"; import { TextToSpeechLanguage } from "../../Project"; import * as _BlockInput from "../../BlockInput"; export type ScalarValue = string | number | boolean; export type AssetId = string; export type Variable = [string, ScalarValue] | [string, ScalarValue, true]; export type List = [string, ScalarValue[]]; export interface Costume { assetId: AssetId; dataFormat: "png" | "svg" | "jpeg" | "jpg" | "bmp" | "gif"; name: string; md5ext?: string; bitmapResolution?: number; rotationCenterX?: number; rotationCenterY?: number; } export interface Sound { assetId: AssetId; dataFormat: "wav" | "wave" | "mp3"; name: string; md5ext?: string; rate?: number; sampleCount?: number; } interface Mutation { [attribute: string]: Mutation[] | string; children: Mutation[]; } export interface ProceduresPrototypeMutation { proccode: string; argumentnames: string; argumentids: string; argumentdefaults: string; warp: "true" | "false"; } export interface ProceduresCallMutation { proccode: string; argumentnames: string; argumentids: string; argumentdefaults: string; warp: "true" | "false"; } type MutationFor<Op extends OpCode> = Op extends OpCode.procedures_prototype ? ProceduresPrototypeMutation : Op extends OpCode.procedures_call ? ProceduresCallMutation : Mutation | undefined; export interface Block<Op extends OpCode = OpCode> { opcode: Op; next: string | null; parent: string | null; inputs: { [key: string]: BlockInput; }; fields: { [key: string]: BlockField; }; mutation: MutationFor<Op>; shadow: boolean; topLevel: boolean; x?: number; y?: number; } export type BlockField = Readonly<[string, string | null] | [string]>; interface Comment { blockId: string; x: number; y: number; width: number; height: number; minimized: boolean; text: string; } export interface Target { isStage: boolean; name: string; variables: { [key: string]: Variable; }; lists: { [key: string]: List; }; broadcasts: { [key: string]: string; }; blocks: { [key: string]: Block<OpCode>; }; comments: { [key: string]: Comment; }; currentCostume: number; costumes: Costume[]; sounds: Sound[]; volume: number; layerOrder: number; } export interface Stage extends Target { isStage: true; tempo: number; videoTransparency: number; videoState: "on" | "off"; textToSpeechLanguage: TextToSpeechLanguage | null; } export interface Sprite extends Target { isStage: false; visible: boolean; x: number; y: number; size: number; direction: number; draggable: boolean; rotationStyle: "all around" | "left-right" | "don't rotate"; } interface MonitorBase { id: string; mode: "default" | "large" | "slider" | "list"; opcode: "data_variable" | "data_listcontents"; params: { [key: string]: string; }; spriteName: string; width?: number | null; height?: number | null; x: number; y: number; visible: boolean; } export interface VariableMonitor extends MonitorBase { mode: "default" | "large" | "slider"; opcode: "data_variable"; params: { VARIABLE: string; }; value: ScalarValue; sliderMin: number; sliderMax: number; isDiscrete: boolean; } export interface ListMonitor extends MonitorBase { mode: "list"; opcode: "data_listcontents"; params: { LIST: string; }; value: ScalarValue[]; } export type Monitor = VariableMonitor | ListMonitor; interface Meta { semver: string; vm?: string; agent?: string; } export interface ProjectJSON { targets: Target[]; monitors?: Monitor[]; meta: Meta; } export declare const fieldTypeMap: { [opcode in OpCode]?: { [fieldName: string]: _BlockInput.Any["type"]; }; }; export declare enum BlockInputStatus { INPUT_SAME_BLOCK_SHADOW = 1, INPUT_BLOCK_NO_SHADOW = 2, INPUT_DIFF_BLOCK_SHADOW = 3, MATH_NUM_PRIMITIVE = 4, POSITIVE_NUM_PRIMITIVE = 5, WHOLE_NUM_PRIMITIVE = 6, INTEGER_NUM_PRIMITIVE = 7, ANGLE_NUM_PRIMITIVE = 8, COLOR_PICKER_PRIMITIVE = 9, TEXT_PRIMITIVE = 10, BROADCAST_PRIMITIVE = 11, VAR_PRIMITIVE = 12, LIST_PRIMITIVE = 13 } export import BIS = BlockInputStatus; export declare const BooleanOrSubstackInputStatus = BIS.INPUT_BLOCK_NO_SHADOW; export type BlockInput = Readonly<[BIS.INPUT_SAME_BLOCK_SHADOW, BlockInputValue | null] | [BIS.INPUT_BLOCK_NO_SHADOW, BlockInputValue | null] | [BIS.INPUT_DIFF_BLOCK_SHADOW, BlockInputValue | null, BlockInputValue]>; export type BlockInputValue = Readonly<string | [BIS.MATH_NUM_PRIMITIVE, number | string] | [BIS.POSITIVE_NUM_PRIMITIVE, number | string] | [BIS.WHOLE_NUM_PRIMITIVE, number | string] | [BIS.INTEGER_NUM_PRIMITIVE, number | string] | [BIS.ANGLE_NUM_PRIMITIVE, number | string] | [BIS.COLOR_PICKER_PRIMITIVE, string] | [BIS.TEXT_PRIMITIVE, string] | [BIS.BROADCAST_PRIMITIVE, string, string] | [BIS.VAR_PRIMITIVE, string, string] | [BIS.LIST_PRIMITIVE, string, string]>; export declare const inputPrimitiveOrShadowMap: { readonly motion_movesteps: { readonly STEPS: BlockInputStatus.MATH_NUM_PRIMITIVE; }; readonly motion_turnright: { readonly DEGREES: BlockInputStatus.MATH_NUM_PRIMITIVE; }; readonly motion_turnleft: { readonly DEGREES: BlockInputStatus.MATH_NUM_PRIMITIVE; }; readonly motion_pointindirection: { readonly DIRECTION: BlockInputStatus.ANGLE_NUM_PRIMITIVE; }; readonly motion_pointtowards: { readonly TOWARDS: OpCode.motion_pointtowards_menu; }; readonly motion_gotoxy: { readonly X: BlockInputStatus.MATH_NUM_PRIMITIVE; readonly Y: BlockInputStatus.MATH_NUM_PRIMITIVE; }; readonly motion_goto: { readonly TO: OpCode.motion_goto_menu; }; readonly motion_glidesecstoxy: { readonly SECS: BlockInputStatus.MATH_NUM_PRIMITIVE; readonly X: BlockInputStatus.MATH_NUM_PRIMITIVE; readonly Y: BlockInputStatus.MATH_NUM_PRIMITIVE; }; readonly motion_glideto: { readonly SECS: BlockInputStatus.MATH_NUM_PRIMITIVE; readonly TO: OpCode.motion_glideto_menu; }; readonly motion_changexby: { readonly DX: BlockInputStatus.MATH_NUM_PRIMITIVE; }; readonly motion_setx: { readonly X: BlockInputStatus.MATH_NUM_PRIMITIVE; }; readonly motion_changeyby: { readonly DY: BlockInputStatus.MATH_NUM_PRIMITIVE; }; readonly motion_sety: { readonly Y: BlockInputStatus.MATH_NUM_PRIMITIVE; }; readonly motion_ifonedgebounce: {}; readonly motion_setrotationstyle: {}; readonly motion_xposition: {}; readonly motion_yposition: {}; readonly motion_direction: {}; readonly motion_scroll_right: { readonly DISTANCE: BlockInputStatus.MATH_NUM_PRIMITIVE; }; readonly motion_scroll_up: { readonly DISTANCE: BlockInputStatus.MATH_NUM_PRIMITIVE; }; readonly motion_align_scene: {}; readonly looks_sayforsecs: { readonly MESSAGE: BlockInputStatus.TEXT_PRIMITIVE; readonly SECS: BlockInputStatus.MATH_NUM_PRIMITIVE; }; readonly looks_say: { readonly MESSAGE: BlockInputStatus.TEXT_PRIMITIVE; }; readonly looks_thinkforsecs: { readonly MESSAGE: BlockInputStatus.TEXT_PRIMITIVE; readonly SECS: BlockInputStatus.MATH_NUM_PRIMITIVE; }; readonly looks_think: { readonly MESSAGE: BlockInputStatus.TEXT_PRIMITIVE; }; readonly looks_show: {}; readonly looks_hide: {}; readonly looks_switchcostumeto: { readonly COSTUME: OpCode.looks_costume; }; readonly looks_nextcostume: {}; readonly looks_nextbackdrop: {}; readonly looks_switchbackdropto: { readonly BACKDROP: OpCode.looks_backdrops; }; readonly looks_switchbackdroptoandwait: { readonly BACKDROP: OpCode.looks_backdrops; }; readonly looks_changeeffectby: { readonly CHANGE: BlockInputStatus.MATH_NUM_PRIMITIVE; }; readonly looks_seteffectto: { readonly VALUE: BlockInputStatus.MATH_NUM_PRIMITIVE; }; readonly looks_changesizeby: { readonly CHANGE: BlockInputStatus.MATH_NUM_PRIMITIVE; }; readonly looks_setsizeto: { readonly SIZE: BlockInputStatus.MATH_NUM_PRIMITIVE; }; readonly looks_cleargraphiceffects: {}; readonly looks_gotofrontback: {}; readonly looks_goforwardbackwardlayers: { readonly NUM: BlockInputStatus.MATH_NUM_PRIMITIVE; }; readonly looks_costumenumbername: {}; readonly looks_backdropnumbername: {}; readonly looks_size: {}; readonly looks_hideallsprites: {}; readonly looks_changestretchby: { readonly CHANGE: BlockInputStatus.MATH_NUM_PRIMITIVE; }; readonly looks_setstretchto: { readonly STRETCH: BlockInputStatus.MATH_NUM_PRIMITIVE; }; readonly sound_play: { readonly SOUND_MENU: OpCode.sound_sounds_menu; }; readonly sound_playuntildone: { readonly SOUND_MENU: OpCode.sound_sounds_menu; }; readonly sound_stopallsounds: {}; readonly sound_changeeffectby: { readonly VALUE: BlockInputStatus.MATH_NUM_PRIMITIVE; }; readonly sound_seteffectto: { readonly VALUE: BlockInputStatus.MATH_NUM_PRIMITIVE; }; readonly sound_cleareffects: {}; readonly sound_changevolumeby: { readonly VOLUME: BlockInputStatus.MATH_NUM_PRIMITIVE; }; readonly sound_setvolumeto: { readonly VOLUME: BlockInputStatus.MATH_NUM_PRIMITIVE; }; readonly sound_volume: {}; readonly event_whenflagclicked: {}; readonly event_whenkeypressed: {}; readonly event_whenstageclicked: {}; readonly event_whenthisspriteclicked: {}; readonly event_whenbackdropswitchesto: {}; readonly event_whengreaterthan: { readonly VALUE: BlockInputStatus.MATH_NUM_PRIMITIVE; }; readonly event_whenbroadcastreceived: {}; readonly event_broadcast: { readonly BROADCAST_INPUT: BlockInputStatus.BROADCAST_PRIMITIVE; }; readonly event_broadcastandwait: { readonly BROADCAST_INPUT: BlockInputStatus.BROADCAST_PRIMITIVE; }; readonly control_wait: { readonly DURATION: BlockInputStatus.POSITIVE_NUM_PRIMITIVE; }; readonly control_repeat: { readonly TIMES: BlockInputStatus.WHOLE_NUM_PRIMITIVE; readonly SUBSTACK: BlockInputStatus.INPUT_BLOCK_NO_SHADOW; }; readonly control_forever: { readonly SUBSTACK: BlockInputStatus.INPUT_BLOCK_NO_SHADOW; }; readonly control_if: { readonly CONDITION: BlockInputStatus.INPUT_BLOCK_NO_SHADOW; readonly SUBSTACK: BlockInputStatus.INPUT_BLOCK_NO_SHADOW; }; readonly control_if_else: { readonly CONDITION: BlockInputStatus.INPUT_BLOCK_NO_SHADOW; readonly SUBSTACK: BlockInputStatus.INPUT_BLOCK_NO_SHADOW; readonly SUBSTACK2: BlockInputStatus.INPUT_BLOCK_NO_SHADOW; }; readonly control_wait_until: { readonly CONDITION: BlockInputStatus.INPUT_BLOCK_NO_SHADOW; }; readonly control_repeat_until: { readonly CONDITION: BlockInputStatus.INPUT_BLOCK_NO_SHADOW; readonly SUBSTACK: BlockInputStatus.INPUT_BLOCK_NO_SHADOW; }; readonly control_while: { readonly CONDITION: BlockInputStatus.INPUT_BLOCK_NO_SHADOW; readonly SUBSTACK: BlockInputStatus.INPUT_BLOCK_NO_SHADOW; }; readonly control_for_each: { readonly VALUE: BlockInputStatus.MATH_NUM_PRIMITIVE; readonly SUBSTACK: BlockInputStatus.INPUT_BLOCK_NO_SHADOW; }; readonly control_all_at_once: { readonly SUBSTACK: BlockInputStatus.INPUT_BLOCK_NO_SHADOW; }; readonly control_stop: {}; readonly control_start_as_clone: {}; readonly control_create_clone_of: { readonly CLONE_OPTION: OpCode.control_create_clone_of_menu; }; readonly control_delete_this_clone: {}; readonly sensing_touchingobject: { readonly TOUCHINGOBJECTMENU: OpCode.sensing_touchingobjectmenu; }; readonly sensing_touchingcolor: { readonly COLOR: BlockInputStatus.COLOR_PICKER_PRIMITIVE; }; readonly sensing_coloristouchingcolor: { readonly COLOR: BlockInputStatus.COLOR_PICKER_PRIMITIVE; readonly COLOR2: BlockInputStatus.COLOR_PICKER_PRIMITIVE; }; readonly sensing_distanceto: { readonly DISTANCETOMENU: OpCode.sensing_distancetomenu; }; readonly sensing_askandwait: { readonly QUESTION: BlockInputStatus.TEXT_PRIMITIVE; }; readonly sensing_answer: {}; readonly sensing_keypressed: { readonly KEY_OPTION: OpCode.sensing_keyoptions; }; readonly sensing_mousedown: {}; readonly sensing_mousex: {}; readonly sensing_mousey: {}; readonly sensing_setdragmode: {}; readonly sensing_loudness: {}; readonly sensing_timer: {}; readonly sensing_resettimer: {}; readonly sensing_of: { readonly OBJECT: OpCode.sensing_of_object_menu; }; readonly sensing_current: {}; readonly sensing_dayssince2000: {}; readonly sensing_username: {}; readonly sensing_userid: {}; readonly sensing_loud: {}; readonly operator_add: { readonly NUM1: BlockInputStatus.MATH_NUM_PRIMITIVE; readonly NUM2: BlockInputStatus.MATH_NUM_PRIMITIVE; }; readonly operator_subtract: { readonly NUM1: BlockInputStatus.MATH_NUM_PRIMITIVE; readonly NUM2: BlockInputStatus.MATH_NUM_PRIMITIVE; }; readonly operator_multiply: { readonly NUM1: BlockInputStatus.MATH_NUM_PRIMITIVE; readonly NUM2: BlockInputStatus.MATH_NUM_PRIMITIVE; }; readonly operator_divide: { readonly NUM1: BlockInputStatus.MATH_NUM_PRIMITIVE; readonly NUM2: BlockInputStatus.MATH_NUM_PRIMITIVE; }; readonly operator_random: { readonly FROM: BlockInputStatus.MATH_NUM_PRIMITIVE; readonly TO: BlockInputStatus.MATH_NUM_PRIMITIVE; }; readonly operator_lt: { readonly OPERAND1: BlockInputStatus.TEXT_PRIMITIVE; readonly OPERAND2: BlockInputStatus.TEXT_PRIMITIVE; }; readonly operator_equals: { readonly OPERAND1: BlockInputStatus.TEXT_PRIMITIVE; readonly OPERAND2: BlockInputStatus.TEXT_PRIMITIVE; }; readonly operator_gt: { readonly OPERAND1: BlockInputStatus.TEXT_PRIMITIVE; readonly OPERAND2: BlockInputStatus.TEXT_PRIMITIVE; }; readonly operator_and: { readonly OPERAND1: BlockInputStatus.INPUT_BLOCK_NO_SHADOW; readonly OPERAND2: BlockInputStatus.INPUT_BLOCK_NO_SHADOW; }; readonly operator_or: { readonly OPERAND1: BlockInputStatus.INPUT_BLOCK_NO_SHADOW; readonly OPERAND2: BlockInputStatus.INPUT_BLOCK_NO_SHADOW; }; readonly operator_not: { readonly OPERAND: BlockInputStatus.INPUT_BLOCK_NO_SHADOW; }; readonly operator_join: { readonly STRING1: BlockInputStatus.TEXT_PRIMITIVE; readonly STRING2: BlockInputStatus.TEXT_PRIMITIVE; }; readonly operator_letter_of: { readonly LETTER: BlockInputStatus.WHOLE_NUM_PRIMITIVE; readonly STRING: BlockInputStatus.TEXT_PRIMITIVE; }; readonly operator_length: { readonly STRING: BlockInputStatus.TEXT_PRIMITIVE; }; readonly operator_contains: { readonly STRING1: BlockInputStatus.TEXT_PRIMITIVE; readonly STRING2: BlockInputStatus.TEXT_PRIMITIVE; }; readonly operator_mod: { readonly NUM1: BlockInputStatus.MATH_NUM_PRIMITIVE; readonly NUM2: BlockInputStatus.MATH_NUM_PRIMITIVE; }; readonly operator_round: { readonly NUM: BlockInputStatus.MATH_NUM_PRIMITIVE; }; readonly operator_mathop: { readonly NUM: BlockInputStatus.MATH_NUM_PRIMITIVE; }; readonly music_playDrumForBeats: { readonly DRUM: OpCode.music_menu_DRUM; readonly BEATS: BlockInputStatus.MATH_NUM_PRIMITIVE; }; readonly music_restForBeats: { readonly BEATS: BlockInputStatus.MATH_NUM_PRIMITIVE; }; readonly music_playNoteForBeats: { readonly NOTE: OpCode.note; readonly BEATS: BlockInputStatus.MATH_NUM_PRIMITIVE; }; readonly music_setInstrument: { readonly INSTRUMENT: OpCode.music_menu_INSTRUMENT; }; readonly music_setTempo: { readonly TEMPO: BlockInputStatus.MATH_NUM_PRIMITIVE; }; readonly music_changeTempo: { readonly TEMPO: BlockInputStatus.MATH_NUM_PRIMITIVE; }; readonly music_getTempo: {}; readonly music_midiPlayDrumForBeats: { readonly DRUM: BlockInputStatus.MATH_NUM_PRIMITIVE; readonly BEATS: BlockInputStatus.MATH_NUM_PRIMITIVE; }; readonly music_midiSetInstrument: { readonly INSTRUMENT: BlockInputStatus.MATH_NUM_PRIMITIVE; }; readonly pen_clear: {}; readonly pen_stamp: {}; readonly pen_penDown: {}; readonly pen_penUp: {}; readonly pen_setPenColorToColor: { readonly COLOR: BlockInputStatus.COLOR_PICKER_PRIMITIVE; }; readonly pen_changePenColorParamBy: { readonly COLOR_PARAM: OpCode.pen_menu_colorParam; readonly VALUE: BlockInputStatus.MATH_NUM_PRIMITIVE; }; readonly pen_setPenColorParamTo: { readonly COLOR_PARAM: OpCode.pen_menu_colorParam; readonly VALUE: BlockInputStatus.MATH_NUM_PRIMITIVE; }; readonly pen_changePenSizeBy: { readonly SIZE: BlockInputStatus.MATH_NUM_PRIMITIVE; }; readonly pen_setPenSizeTo: { readonly SIZE: BlockInputStatus.MATH_NUM_PRIMITIVE; }; readonly pen_setPenShadeToNumber: { readonly SHADE: BlockInputStatus.MATH_NUM_PRIMITIVE; }; readonly pen_changePenShadeBy: { readonly SHADE: BlockInputStatus.MATH_NUM_PRIMITIVE; }; readonly pen_setPenHueToNumber: { readonly HUE: BlockInputStatus.MATH_NUM_PRIMITIVE; }; readonly pen_changePenHueBy: { readonly HUE: BlockInputStatus.MATH_NUM_PRIMITIVE; }; readonly videoSensing_whenMotionGreaterThan: { readonly REFERENCE: BlockInputStatus.MATH_NUM_PRIMITIVE; }; readonly videoSensing_videoOn: { readonly ATTRIBUTE: OpCode.videoSensing_menu_ATTRIBUTE; readonly SUBJECT: OpCode.videoSensing_menu_SUBJECT; }; readonly videoSensing_videoToggle: { readonly VIDEO_STATE: OpCode.videoSensing_menu_VIDEO_STATE; }; readonly videoSensing_setVideoTransparency: { readonly TRANSPARENCY: BlockInputStatus.MATH_NUM_PRIMITIVE; }; readonly wedo2_motorOnFor: { readonly MOTOR_ID: OpCode.wedo2_menu_MOTOR_ID; readonly DURATION: BlockInputStatus.MATH_NUM_PRIMITIVE; }; readonly wedo2_motorOn: { readonly MOTOR_ID: OpCode.wedo2_menu_MOTOR_ID; }; readonly wedo2_motorOff: { readonly MOTOR_ID: OpCode.wedo2_menu_MOTOR_ID; }; readonly wedo2_startMotorPower: { readonly MOTOR_ID: OpCode.wedo2_menu_MOTOR_ID; readonly POWER: BlockInputStatus.MATH_NUM_PRIMITIVE; }; readonly wedo2_setMotorDirection: { readonly MOTOR_ID: OpCode.wedo2_menu_MOTOR_ID; readonly MOTOR_DIRECTION: OpCode.wedo2_menu_MOTOR_DIRECTION; }; readonly wedo2_setLightHue: { readonly HUE: BlockInputStatus.MATH_NUM_PRIMITIVE; }; readonly wedo2_whenDistance: { readonly OP: OpCode.wedo2_menu_OP; readonly REFERENCE: BlockInputStatus.MATH_NUM_PRIMITIVE; }; readonly wedo2_whenTilted: { readonly TILT_DIRECTION_ANY: OpCode.wedo2_menu_TILT_DIRECTION_ANY; }; readonly wedo2_getDistance: {}; readonly wedo2_isTilted: { readonly TILT_DIRECTION_ANY: OpCode.wedo2_menu_TILT_DIRECTION_ANY; }; readonly wedo2_getTiltAngle: { readonly TILT_DIRECTION: OpCode.wedo2_menu_TILT_DIRECTION; }; readonly wedo2_playNoteFor: { readonly NOTE: BlockInputStatus.MATH_NUM_PRIMITIVE; readonly DURATION: BlockInputStatus.MATH_NUM_PRIMITIVE; }; readonly data_variable: {}; readonly data_setvariableto: { readonly VALUE: BlockInputStatus.TEXT_PRIMITIVE; }; readonly data_changevariableby: { readonly VALUE: BlockInputStatus.MATH_NUM_PRIMITIVE; }; readonly data_showvariable: {}; readonly data_hidevariable: {}; readonly data_listcontents: {}; readonly data_addtolist: { readonly ITEM: BlockInputStatus.TEXT_PRIMITIVE; }; readonly data_deleteoflist: { readonly INDEX: BlockInputStatus.INTEGER_NUM_PRIMITIVE; }; readonly data_deletealloflist: {}; readonly data_insertatlist: { readonly INDEX: BlockInputStatus.INTEGER_NUM_PRIMITIVE; readonly ITEM: BlockInputStatus.TEXT_PRIMITIVE; }; readonly data_replaceitemoflist: { readonly INDEX: BlockInputStatus.INTEGER_NUM_PRIMITIVE; readonly ITEM: BlockInputStatus.TEXT_PRIMITIVE; }; readonly data_itemoflist: { readonly INDEX: BlockInputStatus.INTEGER_NUM_PRIMITIVE; }; readonly data_itemnumoflist: { readonly ITEM: BlockInputStatus.TEXT_PRIMITIVE; }; readonly data_lengthoflist: {}; readonly data_listcontainsitem: { readonly ITEM: BlockInputStatus.TEXT_PRIMITIVE; }; readonly data_showlist: {}; readonly data_hidelist: {}; readonly argument_reporter_boolean: {}; readonly argument_reporter_string_number: {}; }; export {};