Skip to content

Commit ffbb043

Browse files
committed
✨ 增加逻辑节点:SEARCH_CONTENT,搜索全部匹配的节点内容
1 parent 30b0300 commit ffbb043

File tree

5 files changed

+47
-0
lines changed

5 files changed

+47
-0
lines changed

app/src/core/service/dataGenerateService/autoComputeEngine/functions/nodeLogic.tsx

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,42 @@ export namespace NodeLogic {
581581
return [`替换了${replacedCount}处内容`];
582582
}
583583

584+
/**
585+
* 搜索内容
586+
* @param fatherNodes 被搜索字符串,是否大小写敏感
587+
* @param _childNodes
588+
*/
589+
export function searchContent(
590+
fatherNodes: ConnectableEntity[],
591+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
592+
_childNodes: ConnectableEntity[],
593+
): string[] {
594+
if (fatherNodes.length !== 2) {
595+
return ["输入数量不正确,第一个参数为被搜索字符串,第二个是否大小写敏感(0/1)"];
596+
}
597+
if (fatherNodes[0] instanceof TextNode && fatherNodes[1] instanceof TextNode) {
598+
const searchString = fatherNodes[0].text;
599+
const isCaseSensitive = parseInt(fatherNodes[1].text);
600+
if (!(isCaseSensitive === 0 || isCaseSensitive === 1)) {
601+
return ["第二个参数只能输入 0/1"];
602+
}
603+
const searchResultNodes: TextNode[] = [];
604+
for (const node of StageManager.getTextNodes()) {
605+
if (isCaseSensitive) {
606+
if (node.text.includes(searchString)) {
607+
searchResultNodes.push(node);
608+
}
609+
} else {
610+
if (node.text.toLowerCase().includes(searchString.toLowerCase())) {
611+
searchResultNodes.push(node);
612+
}
613+
}
614+
}
615+
return searchResultNodes.map((node) => node.uuid);
616+
}
617+
return ["输入的节点格式必须都是TextNode"];
618+
}
619+
584620
export function deletePenStrokeByColor(
585621
fatherNodes: ConnectableEntity[],
586622
// eslint-disable-next-line @typescript-eslint/no-unused-vars

app/src/core/service/dataGenerateService/autoComputeEngine/logicNodeNameEnum.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ export enum LogicNodeNameEnum {
9595
CREATE_TEXT_NODE_ON_LOCATION = "#CREATE_TEXT_NODE_ON_LOCATION#",
9696
IS_HAVE_ENTITY_ON_LOCATION = "#IS_HAVE_ENTITY_ON_LOCATION#",
9797
REPLACE_GLOBAL_CONTENT = "#REPLACE_GLOBAL_CONTENT#",
98+
SEARCH_CONTENT = "#SEARCH_CONTENT#",
9899
DELETE_PEN_STROKE_BY_COLOR = "#DELETE_PEN_STROKE_BY_COLOR#",
99100
}
100101
export const LogicNodeNameToRenderNameMap: {
@@ -179,6 +180,7 @@ export const LogicNodeNameToRenderNameMap: {
179180
[LogicNodeNameEnum.CREATE_TEXT_NODE_ON_LOCATION]: "在指定位置创建节点",
180181
[LogicNodeNameEnum.IS_HAVE_ENTITY_ON_LOCATION]: "判断某位置是否存在实体",
181182
[LogicNodeNameEnum.REPLACE_GLOBAL_CONTENT]: "全局替换内容",
183+
[LogicNodeNameEnum.SEARCH_CONTENT]: "搜索内容",
182184
[LogicNodeNameEnum.DELETE_PEN_STROKE_BY_COLOR]: "删除画笔颜色的笔画",
183185

184186
[LogicNodeNameEnum.SET_VAR]: "设置变量",
@@ -269,6 +271,7 @@ export const LogicNodeNameToArgsTipsMap: {
269271
[LogicNodeNameEnum.CREATE_TEXT_NODE_ON_LOCATION]: "a0: x, a1: y, a2: text, a3: 0/1",
270272
[LogicNodeNameEnum.IS_HAVE_ENTITY_ON_LOCATION]: "a0: x, a1: y",
271273
[LogicNodeNameEnum.REPLACE_GLOBAL_CONTENT]: "a0: 被替换内容, a1: 新内容",
274+
[LogicNodeNameEnum.SEARCH_CONTENT]: "a0: 被搜索内容, a1: 是否大小写敏感0/1",
272275
[LogicNodeNameEnum.DELETE_PEN_STROKE_BY_COLOR]: "a0: red, a1: green, a2: blue, a3: alpha",
273276

274277
[LogicNodeNameEnum.SET_VAR]: "a0: name, a1: value",

app/src/core/service/dataGenerateService/autoComputeEngine/mainTick.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ const MapOtherFunction: OtherFunctionMap = {
153153
[LogicNodeNameEnum.CREATE_TEXT_NODE_ON_LOCATION]: NodeLogic.createTextNodeOnLocation,
154154
[LogicNodeNameEnum.IS_HAVE_ENTITY_ON_LOCATION]: NodeLogic.isHaveEntityOnLocation,
155155
[LogicNodeNameEnum.REPLACE_GLOBAL_CONTENT]: NodeLogic.replaceGlobalContent,
156+
[LogicNodeNameEnum.SEARCH_CONTENT]: NodeLogic.searchContent,
156157
[LogicNodeNameEnum.DELETE_PEN_STROKE_BY_COLOR]: NodeLogic.deletePenStrokeByColor,
157158
};
158159

app/src/core/service/dataManageService/copyEngine/pasteImage.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ import { StageManager } from "../../../stage/stageManager/StageManager";
77
import { ImageNode } from "../../../stage/stageObject/entity/ImageNode";
88
import { v4 as uuidv4 } from "uuid";
99

10+
/**
11+
* 把粘贴板中的PNG图片读取并写入到磁盘和舞台上
12+
* @param item
13+
* @param mouseLocation
14+
* @returns
15+
*/
1016
export async function copyEnginePasteImage(item: ClipboardItem, mouseLocation: Vector) {
1117
// 图片在草稿情况下不能粘贴
1218
if (Stage.path.isDraft()) {

docs/src/zh_CN/guide/features/compute-engine.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@
142142
- `#CREATE_TEXT_NODE_ON_LOCATION#`: 在特定位置创建一个文本节点,第一个输入x值,第二个输入y值,第三个输入节点文本内容,第四个输入0/1代表是否创建(1代表创建,0代表不创建,可以在上游增加一个瞬时脉冲电路来防止按下x后创建很多重叠的重复节点)。
143143
- `#IS_HAVE_ENTITY_ON_LOCATION#`: 检测某位置是否存在实体,输入一个x值和y值,输出一个0/1的节点,如果在该位置有实体,则输出值为1
144144
- `#REPLACE_GLOBAL_CONTENT#`: 输入两个节点,第一个是原字符串,第二个是新字符串,运行后将舞台上全部的文本节点中的文字中,含有原字符串的部分替换为新字符串。
145+
- `#SEARCH_CONTENT#`: 输入两个节点,第一个是搜索的关键字,第二个是数字0或1,0代表不开启大小写敏感,1代表开启大小写敏感,运行后将所有匹配的节点的UUID输出。注意如果更换了关键字,需要手动删除所有子节点。否则可能造成干扰。
145146
- `#DELETE_PEN_STROKE_BY_COLOR#`: 输入 r,g,b,a 四个值,运行后删除舞台上所有颜色相同的涂鸦笔画。主要用于讲课、录制视频教程的场景使用。注:在没有自动上色时,且为黑色主题下,涂鸦颜色看上去是略微暗一点点的白色,和节点的边框一个颜色,但实际上在数据层面,涂鸦颜色为 (0,0,0,0)。这是一个特殊规定,当涂鸦颜色为 (0,0,0,0) 时,渲染的颜色会自动跟随当前颜色主题下的(实体边框颜色)。这样就能够在切换成白色或者其他主题颜色的时候,自动更改这些涂鸦的颜色了。
146147
- `#GET_NODE_UUID#`: 输入一个节点,输出该节点的UUID。
147148
- `#SET_LOCATION_BY_UUID#`: 输入 UUID,x,y 三个值,运行后,将指定 UUID 的节点的移动到 (x,y)位置上。

0 commit comments

Comments
 (0)