Skip to content

Commit

Permalink
add disable-monitor field
Browse files Browse the repository at this point in the history
  • Loading branch information
zmh-program committed Apr 6, 2023
1 parent ece8073 commit 85f94e6
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ turbowarp-ts-plugin是一个高效开发部署turbowarp扩展的插件, 提供:
- 🔨 **更好的开发环境**
- 📦 **自动补全**
- 🌀 **webpack 极致压缩大小**
- 🎃 **注册异常检测**
- 🎉 **Typescript 支持**

## 开发
Expand Down Expand Up @@ -43,7 +44,7 @@ webpack打包生成的js文件位于**dist/extension.js**
- `bind` 接受一个**function**, 允许异步执行返回Promise
- `text` 是一个字符串,用于定义积木在编辑器中的名称 格式为 **[参数:类型]**
- `参数` 定义积木接受的参数的对象, 可能将在`default`和`menu`字段中引用
- `类型`定义要创建的输入形状
- `类型`定义要创建的输入形状 *(不区分大小写)*
- `STRING` 字符串类型
- `NUMBER` 用于数字输入
- `BOOLEAN` 用于布尔输入 **(默认值将被忽略)**
Expand All @@ -53,6 +54,7 @@ webpack打包生成的js文件位于**dist/extension.js**
- `NOTE` 用于音乐
- `default` 是参数的初始值, 接受一个字典, 键对应`参数`, 值对应参数的`默认值`
- `menu` 如果有参数需选择多个给定的值, 则可加入至此参数, 接受一个字典, 键对应`参数`, 值对应多个给定的值的列表类型, 将生成下拉菜单
- `disableMonitor` 是否积木强制删除复选框来创建监视器, 适用类型为**REPORTER** *(带返回值的积木)*, 如果为真, 则删除变量左处的复选框
5. `docsURI`对应文档链接
每太看懂? 下面展示一个示例
Expand All @@ -76,16 +78,18 @@ new Extension({
blockType: Scratch.BlockType.REPORTER,
text: '获取一个空列表',
bind: () => [],
disableMonitor: true,
},
]
}).register();
```
上文创建并注册了一个扩展**ExampleExtension**, 并在Scratch中显示为**example**, 方块颜色#0800ff, 并创建了两个方块:

第一个方块*output*的类型为**键积木**, 共有两个参数
1. `block`参数是一个下拉菜单, **字符串**类型, 默认值为*参数2*, 可选值为 *参数1**参数2*
2. `type`参数是一个输入框, **字符串**类型, 默认值为*类型*
绑定一个方法返回`内容 {{block}} 类型 {{type}}`
1. `block`参数是一个下拉菜单, **字符串**类型, 默认值为`"参数2"`, 可选值为 *参数1**参数2*
2. `type`参数是一个输入框, **字符串**类型, 默认值为`"类型"`<br>
绑定一个方法返回`内容 {{block}} 类型 {{type}}`<br>
通过设置`disableMonitor`为真来强制删除复选框

第二个方块*list*的类型为**带返回值的积木**, 方法返回一个空列表

Expand Down
3 changes: 2 additions & 1 deletion src/option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ export default interface Option {
const $ = Scratch.BlockType;
export interface Block {
opcode: string, /** @ts-ignore */
blockType: $.Boolean | $.Button | $.Command | $.CONDITIONAL | $.EVENT | $.HAT | $.LOOP | $.REPORTER,
blockType: $.BOOLEAN | $.BUTTON | $.COMMAND | $.CONDITIONAL | $.EVENT | $.HAT | $.LOOP | $.REPORTER,
text: string,
bind: (...args: any) => Promise<any> | any,
default?: Record<string, string>, // defaultValue
menu?: Record<string, any[]>,
disableMonitor?: boolean,
}
14 changes: 10 additions & 4 deletions src/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cleanObject } from "./utils";
import { cleanObject, notification } from "./utils";
import Option from "./option";

export default class Extension {
Expand Down Expand Up @@ -34,6 +34,7 @@ export default class Extension {
blockType: block.blockType,
text: block.text,
arguments: args,
disableMonitor: block.disableMonitor,
}));
}
}
Expand All @@ -55,8 +56,13 @@ export default class Extension {
}

public register() {
console.log(this.getInfo())
// @ts-ignore
Scratch.extensions.register(this);
try {
// @ts-ignore
Scratch.extensions.register(this);
} catch (e) {
notification(`Failed to load extension ${this.option.name}`);
console.error(e);
return;
}
}
}
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ export function cleanObject(target: Record<string, any>): object {

export function notification(content: string): void {
// @ts-ignore
top.mdui.snakebar(content);
top.mdui.snackbar(content);
}

0 comments on commit 85f94e6

Please sign in to comment.