该文章由 gitblock.cn 上的一位用户 夜君 撰写。
其用户页链接为 https://gitblock.cn/Users/1150660。
为方便分享,我将文章转载到了这里。
原文章发表于 2023-01-18。

前言

这里只讲最重要的targets.blocks属性

获取

https://turbowarp.org打开控制台输入

JSON.parse(vm.toJSON()).targets[1]

研究

获取到的结果有很多属性,都很好理解,这里只讲blocks属性

研究 > 积木

首先,可以简单的将积木分成7种后,观察他们的blocks属性后得出结论(自定义积木放这最后将)
图片.png


图片.png

b:{
    "opcode": "motion_movesteps",
    "next": null,
    "parent": null,
    "inputs": {
        "STEPS": [
            1,
            [
                4,
                "10"
            ]
        ]
    },
    "fields": {},
    "shadow": false,
    "topLevel": true,
    "x": 300,
    "y": 220,
    "comment": "c"
}

图片.png

d:{
    "opcode": "event_whenflagclicked",
    "next": null,
    "parent": null,
    "inputs": {},
    "fields": {},
    "shadow": false,
    "topLevel": true,
    "x": 300,
    "y": 100,
    "comment": "e"
}

图片.png

f:{
    "opcode": "control_forever",
    "next": null,
    "parent": null,
    "inputs": {},
    "fields": {},
    "shadow": false,
    "topLevel": true,
    "x": 300,
    "y": 340,
    "comment": "g"
}

图片.png

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"
}

图片.png

l:{
    "opcode": "sensing_mousedown",
    "next": null,
    "parent": null,
    "inputs": {},
    "fields": {},
    "shadow": false,
    "topLevel": true,
    "x": 660,
    "y": 340,
    "comment": "m"
}

图片.png

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可以理解成积木的一个属性,比如下拉框

研究 > 积木 > 自定义积木

还是同样的方法

图片.png

{
    "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的话可以看看翻译(能看英文最好看英文!!!因为这是机翻!!)

enzh
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_numberargument_reporter_boolean就是图片.png


研究 > 积木 > 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:积木

未完待续


voyage200
1 声望0 粉丝

引用和评论

0 条评论