Skip to content
This repository was archived by the owner on Nov 19, 2025. It is now read-only.

Commit 745cacd

Browse files
committed
1.1.3 template: MyBlock添加addCommandAfterThis属性
1 parent 6124976 commit 745cacd

6 files changed

Lines changed: 191 additions & 78 deletions

File tree

package-lock.json

Lines changed: 165 additions & 74 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "create-makeccx",
3-
"version": "1.1.2",
3+
"version": "1.1.3",
44
"author": "bddjr",
55
"packageManager": "npm@10.8.3",
66
"bin": {

template/src-js/global.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ declare global {
1717
interface MyBlock<T extends BlockParams> {
1818
id: string;
1919
type: type.BlockType;
20+
/**
21+
* 在添加该积木之后,添加 COMMAND 类型的积木。
22+
* 该选项仅当 type 属性的值不是 type.BlockType.COMMAND 时有效。
23+
*/
24+
addCommandAfterThis?: boolean;
2025
option?: type.BlockOption;
2126
branchCount?: number;
2227
param?: T;

template/src-js/merge-categories.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export const categories = input.filter((c) => (typeof c === 'object')).map((c) =
3131

3232
const cid = appendID(ccxID, c.id)
3333

34-
let blocks = c.blocks.filter((b) => (typeof b === 'object')).map((myBlock) => {
34+
let blocks = c.blocks.filter((b) => (typeof b === 'object')).flatMap((myBlock) => {
3535
const blockID = appendID(cid, myBlock.id)
3636
/** @type {type.BlockPrototype} */
3737
const out = {
@@ -96,6 +96,12 @@ export const categories = input.filter((c) => (typeof c === 'object')).map((c) =
9696
out.param[key] = outParam
9797
}
9898
}
99+
if (myBlock.addCommandAfterThis && myBlock.type !== type.BlockType.COMMAND) {
100+
const cmdBlock = Object.assign({}, out)
101+
cmdBlock.type = type.BlockType.COMMAND
102+
cmdBlock.opcode += '_command'
103+
return [out, cmdBlock]
104+
}
99105
return out
100106
})
101107

template/src-ts/global.d.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ declare global {
1616

1717
interface MyBlock<T extends BlockParams> {
1818
id: string;
19-
type: type.BlockType | undefined;
19+
type: type.BlockType;
20+
/**
21+
* 在添加该积木之后,添加 COMMAND 类型的积木。
22+
* 该选项仅当 type 属性的值不是 type.BlockType.COMMAND 时有效。
23+
*/
24+
addCommandAfterThis?: boolean;
2025
option?: type.BlockOption;
2126
branchCount?: number;
2227
param?: T;

0 commit comments

Comments
 (0)