该文章由 gitblock.cn 上的一位用户 夜君 撰写。
其用户页链接为 https://gitblock.cn/Users/1150660。
为方便分享,我将文章转载到了这里。
原文章发表于 2023-01-18。
前言
这里只讲最重要的targets.blocks
属性
获取
在https://turbowarp.org打开控制台输入
JSON.parse(vm.toJSON()).targets[1]
研究
获取到的结果有很多属性,都很好理解,这里只讲blocks
属性
研究 > 积木
首先,可以简单的将积木分成7种后,观察他们的blocks属性后得出结论(自定义积木放这最后将)
b:{
"opcode": "motion_movesteps",
"next": null,
"parent": null,
"inputs": {
"STEPS": [
1,
[
4,
"10"
]
]
},
"fields": {},
"shadow": false,
"topLevel": true,
"x": 300,
"y": 220,
"comment": "c"
}
d:{
"opcode": "event_whenflagclicked",
"next": null,
"parent": null,
"inputs": {},
"fields": {},
"shadow": false,
"topLevel": true,
"x": 300,
"y": 100,
"comment": "e"
}
f:{
"opcode": "control_forever",
"next": null,
"parent": null,
"inputs": {},
"fields": {},
"shadow": false,
"topLevel": true,
"x": 300,
"y": 340,
"comment": "g"
}
h:{
"opcode": "control_stop",
"next": null,
"parent": null,
"inputs": {},
"fields": {
"STOP_OPTION": [
"all",
null
]
},
"shadow": false,
"topLevel": true,
"x": 660,
"y": 260,
"mutation": {
"tagName": "mutation",
"children": [],
"hasnext": "false"
},
"comment": "i"
}
l:{
"opcode": "sensing_mousedown",
"next": null,
"parent": null,
"inputs": {},
"fields": {},
"shadow": false,
"topLevel": true,
"x": 660,
"y": 340,
"comment": "m"
}
n:{
"opcode": "sensing_username",
"next": null,
"parent": null,
"inputs": {},
"fields": {},
"shadow": false,
"topLevel": true,
"x": 660,
"y": 420,
"comment": "o"
}
根据以上信息观测得出重要的属性名
属性名 | 描述 |
---|---|
opcode | 积木种类 |
topLevel | 积木上面有无连接积木 |
next | 下面连接着的积木ID |
parent | 上面连接着的积木ID |
inputs | 积木上的输入框 |
fields | 可以理解成积木的一个属性,比如下拉框 |
研究 > 积木 > 自定义积木
还是同样的方法
{
"b": {
"opcode": "procedures_definition",
"next": null,
"parent": null,
"inputs": {
"custom_block": [
1,
"a"
]
},
"fields": {},
"shadow": false,
"topLevel": true,
"x": 60,
"y": 60
},
"a": {
"opcode": "procedures_prototype",
"next": null,
"parent": "b",
"inputs": {
"*Ew5oo4c=UA?Q29~;hDE": [
1,
"c"
],
"Fv)t#mZ+ofCFD?Ti8Q2(": [
1,
"d"
]
},
"fields": {},
"shadow": true,
"topLevel": false,
"mutation": {
"tagName": "mutation",
"children": [],
"proccode": "test %s %b label text",
"argumentids": "[\"*Ew5oo4c=UA?Q29~;hDE\",\"Fv)t#mZ+ofCFD?Ti8Q2(\"]",
"argumentnames": "[\"number or text\",\"boolean\"]",
"argumentdefaults": "[\"\",\"false\",\"\",\"false\",\"\"]",
"warp": "false"
}
},
"c": {
"opcode": "argument_reporter_string_number",
"next": null,
"parent": "a",
"inputs": {},
"fields": {
"VALUE": [
"number or text",
null
]
},
"shadow": true,
"topLevel": false
},
"d": {
"opcode": "argument_reporter_boolean",
"next": null,
"parent": "a",
"inputs": {},
"fields": {
"VALUE": [
"boolean",
null
]
},
"shadow": true,
"topLevel": false
}
}
观察发现,在代码区放置一个自定义积木,后添加了4个积木。没看懂opcode
的话可以看看翻译(能看英文最好看英文!!!因为这是机翻!!)
en | zh |
---|---|
procedures_definition | 过程_定义 |
procedures_prototype | 过程_总类型 |
argument_reporter_string_number | 参数_报告_字符串_数字 |
argument_reporter_boolean | 参数_报告_布尔 |
大胆假设,小心求证
procedures_prototype
是这个函数的样子,通过mutation
属性猜测
mutation的属性
属性名 | 描述 | 类型 |
---|---|---|
proccode | 自定义积木样式 | 字符串 |
argumentids | 参数的积木ID | 数组 |
argumentnames | 参数的名称 | 数组 |
argumentdefaults | 参数_默认值 | 数组 |
warp | 运行时屏幕不刷新 | 布尔 |
上面那个自定义积木的 proccode
就是 test %s %b label text
,%s
是字符串类型的参数,%b
是布尔类型的参数
argumentdefaults
应该是参数的默认值的意思,不过据我所知原版scratch没有默认值参数,在刚才的示例自定义积木里是["false","false"]
(有空仔细研究)
argument_reporter_string_number
和argument_reporter_boolean
就是
研究 > 积木 > inputs
inputs的结构
// 示例
{
"MESSAGE": [
3,
[
12,
"我的变量",
"`jEk@4|i[#Fk?(8x)AV.-my variable"
],
[
10,
"文字"
]
],
"SECS": [
3,
"b",
[
4,
"数字"
]
]
}
"MESSAGE": [
3, // 类型
[
12,
"我的变量",
"`jEk@4|i[#Fk?(8x)AV.-my variable"
], // 值
[
4,
"数字"
] // 值2
],
类型:
1
: 纯文字/数字输入- 值: [类型,值],
10
:字符串,4
:数字,9
:颜色
- 值: [类型,值],
2
: 积木输入,比如如果 ... 那么
所填的积木- 值: 积木ID
3
: 输入一个代码块,比如变量,或者 绝对值() 之类的返回值积木(包含布尔积木)- 值: [类型,值],
12
:变量,13
:列表,3
:积木
- 值: [类型,值],
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。