Scratch 文件格式内容详解(官网翻译)

        Scratch 3.0 文件格式是用于保存 Scratch 3.0 项目文件和角色文件的格式。其本质是一个 .zip 格式的压缩文件,包含了一个文本格式的json文件以及媒体文件(图片和音频)。 项目文件和角色文件的扩展名分别为 .sb3 和 .sprite3.sb3 文件的MIME类型为application/x.scratch.sb3.

项目(Project)文件

.sb3 文件表示了整个项目,是包含单个JSON文件和若干媒体文件的 ZIP 压缩包。JSON 文件名为 project.json。(在绝大多数操作系统中, 可将.sb3 后缀重命名为 .zip 以解压文件,或者也可以使用诸如7-Zip这样的压缩软件直接解压文件。有时需要调整系统设置才能显示和修改文件扩展名。)背景、造型和声音以单独文件的形式存储,其文件名为素材的MD5校验和加上原本的文件后缀名。

角色(Sprite)文件

.sprite3 文件表示一个角色,即一个对象(target),其内容与项目文件相同,但其中的JSON文件命名为了 sprite.json。

项目(Project)

一个项目包含如下属性

targets (对象)

对象数组,其排列顺序与Scratch编辑器界面中的显示顺序相同。

monitors (数显小控件)

数显小控件数组,按其图层顺序排序。

extensions (括展模块)

数组,包含项目所使用的括展模块标识。合法的标识有(此处只列出了原生Scratch

中的标识,不包含第三方的标识):

元数据(meta)

关于项目作者和Scratch版本信息的元数据。

对象(Targets)

对象是舞台和角色的统称。舞台或者一个角色即成为一个对象。对象包含如下属性:

isStage (是否为舞台)

若为舞台则为true,否则为false。默认值为false。

name (角色名)

角色名。若为舞台,则名称为 "Stage"。如果缺少此项,该对象将不会被加载。

variables (变量)

一个对象,key为变量所对应ID,value为一个数组。数组第一个元素为变量名,第二个元素为变量值,如果是云变量则有第三个元素true,普通变量没有第三个元素。

lists (列表)

一个对象,key为列表所对应ID,value为一个数组。数组第一个元素为列表名,第二个元素为列表值。

broadcasts (广播)

一个对象,key为广播所对应ID,value为广播名。通常只在舞台中该属性的值非空。

blocks(积木)

一个对象,key为积木所对应ID,value为积木名。

comments(注释)

一个对象,key为注释所对应ID,value为注释内容。

currentCostume (当前活动造型)

造型编号。

costumes (造型)

造型数组。

sounds(声音)

声音数组。

layerOrder(图层编号)

图层编号。

volume(音量)

音量。

舞台(Stage)

除上述属性以外,舞台还具有以下属性:

tempo

The tempo in BPM.

videoState

Possible values are "on""off" and "on-flipped".[4] Determines if video is visible on the stage and if it is flipped. Has no effect if the project does not use an extension with video input.

videoTransparency

The video transparency. Defaults to 50. Has no effect if videoState is "off" or if the project does not use an extension with video input.

textToSpeechLanguage

The language of the Text to Speech extension. Defaults to the editor language.[5]

Sprites

Sprites have the following properties as well as those of all targets:

visible

True if the sprite is visible and false otherwise. Defaults to true.

x

The x-coordinate. Defaults to 0.

y

The y-coordinate. Defaults to 0.

size

The sprite's size as a percentage. Defaults to 100.

direction

The sprite's direction in degrees clockwise from up. Defaults to 90.

draggable

True if the sprite is draggable and false otherwise. Defaults to false.

rotationStyle

The Rotation Style. Possible values are "all around""left-right", or "don't rotate".[6]

Blocks

Fields are text boxes, drop-down menus, etc. These are used directly in blocks where there is an input into which one cannot drop a reporter. However, more often than not, one should be able to do this; in this case no field exists directly in the block, but an input does, and that input may have a shadow block in it.

shadow block is a reporter in an input for which one can enter or pick a value, and which cannnot be dragged around but can be replaced by a normal reporter.[7] Scratch internally considers these to be blocks although they are not usually thought of as such. (These notions come from Blockly, which Scratch Blocks is based on.)

Most blocks are represented by objects with the following properties:

opcode

string naming the block. The opcode of a "core" block may be found in the Scratch source code here or here for shadows, and the opcode of an extension's block may be found in the extension's source code here.

next

The ID of the following block or null.

parent

If the block is a stack block and is preceded, this is the ID of the preceding block. If the block is the first stack block in a C mouth, this is the ID of the C block. If the block is an input to another block, this is the ID of that other block. Otherwise it is null.

inputs

An object associating names with arrays representing inputs into which other blocks may be dropped, including C mouths. The first element of each array is 1 if the input is a shadow, 2 if there is no shadow, and 3 if there is a shadow but it is obscured by the input.[8] The second is either the ID of the input or an array representing it as described in the table below. If there is an obscured shadow, the third element is its ID or an array representing it.[9]

fields

An object associating names with arrays representing fields. The first element of each array is the field's value. For certain fields, such as variable and broadcast dropdown menus, there is also a second element, which is the ID of the field's value.[10]

shadow

True if this is a shadow block and false otherwise.

topLevel

False if the block has a parent and true otherwise.

A top-level block object also has the x- and y-coordinates of the block in the code area as x and y. A block with a comment attached has a comment property whose value is the comment's ID. A block with a mutation also has a mutation property whose value is an object representing the mutation.

A few blocks are instead represented by arrays whose first element is a number representing the block applied.[11][12]

Block1st element2nd element3rd element4th element5th element
Number4the value
Positive number5"
Positive integer6"
Integer7"
Angle8"
Color9"#" followed by a hexadecimal numeral representing the color
String10the value
Broadcast11the namethe ID
Variable12""the x-coordinate, if it is top-levelthe y-coordinate, if it is top-level
List 13""""
Mutations

Mutations are present on blocks where the opcode property is equal to "procedures_call" (i.e. customblock ), "procedures_prototype" (i.e. the inner part of definecustomblock) or "control_stop". Mutations have the following properties:

tagName

Always equal to "mutation".

children

Seems to always be an empty array.

"procedures_prototype" and "procedures_call" mutations have the following additional properties:

proccode

The name of the custom block, including inputs: %s for string/number inputs and %b for boolean inputs.

argumentids

An array of the ids of the arguments; these can also be found in the input property of the main block.

warp

Whether to run the block without screen refresh or not.

"procedures_prototype" mutations also have the following additional properties:

argumentnames

An array of the names of the arguments. This is only present when the block has an opcode of procedures_prototype.

argumentdefaults

An array of the defaults of the arguments; for string/number arguments, this is an empty string, and for boolean arguments it is false. This is only present when the block has an opcode of procedures_prototype.

"control_stop" mutations have the following additional property:

hasnext

Whether the block has a block following it or not (false for stop all and stop all in spritetrue for stop other scripts in sprite)

Comments

Comments have the following properties:

blockId

The ID of the block the comment is attached to.

x

The x-coordinate of the comment in the code area.

y

The y-coordinate.

width

The width.

height

The height.

minimized

True if the comment is collapsed and false otherwise.

text

The text.

Assets

An asset is a costume or sound. (Backdrops are considered costumes.) They have the following properties:[13]

assetId

The MD5 hash of the asset file.

name

The name.

md5ext

The name of the asset file.

dataFormat

The name of the format of the asset file.

Costumes

Costumes have the following properties as well as those of all assets:

bitmapResolution

The reciprocal of a costume scaling factor for bitmap costumes. This may be absent. In Scratch 3.0, all bitmap costumes are double-resolution.[14]

rotationCenterX

The x-coordinate of the rotation center.

rotationCenterY

The y-coordinate of the rotation center.

Sounds

Sounds have the following properties as well as those of all assets:

rate

The sampling rate of the sound in Hertz.

sampleCount.

The number of samples.

Monitors

Monitors have the following properties:

id

The ID.

mode

The name of the monitor's mode: "default", "large", "slider", or "list".

opcode

The opcode of the block the monitor belongs to.

params

An object associating names of inputs of the block the monitor belongs to with their values.

spriteName

The name of the target the monitor belongs to, if any.

value

The value appearing on the monitor.

width

The width.

height

The height.

x

The x-coordinate.

y

The y-coordinate.

visible

True if the monitor is visible and false otherwise.

Monitors that do not belong to lists also have these properties:

sliderMin

The minimum value of the monitor's slider.

sliderMax

The maximum value of the monitor's slider.

isDiscrete

True if the monitor's slider allows only integer values and false otherwise.

Metadata

The meta property of project JSON files has the following properties:

semver

Always 3.0.0.

vm

The version of the Scratch VM that the project was created with.

agent

The user agent of the last person to edit the project.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值