Skip to content

Commit a4faf5d

Browse files
committed
🐛 Fix some bug of logic node
1 parent 3343b1c commit a4faf5d

File tree

5 files changed

+33
-15
lines changed

5 files changed

+33
-15
lines changed

app/src/core/render/canvas2d/basicRenderer/textRenderer.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ export class TextRenderer {
167167
lineHeight: number = 1.2,
168168
limitLines: number = Infinity,
169169
): void {
170+
if (!text) return;
170171
if (text.length === 0) return;
171172
// 如果文本里面没有换行符就直接渲染单行文本,不要计算了
172173
if (!text.includes("\n")) {

app/src/core/render/canvas2d/entityRenderer/textNode/TextNodeRenderer.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import { Random } from "@/core/algorithm/random";
22
import { Project, service } from "@/core/Project";
33
import { Renderer } from "@/core/render/canvas2d/renderer";
4+
import {
5+
getLogicNodeRenderName,
6+
LogicNodeNameEnum,
7+
LogicNodeNameToRenderNameMap,
8+
} from "@/core/service/dataGenerateService/autoComputeEngine/logicNodeNameEnum";
49
import { Settings } from "@/core/service/Settings";
510
import { TextNode } from "@/core/stage/stageObject/entity/TextNode";
611
import { Color, colorInvert, Vector } from "@graphif/data-structures";

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,8 @@ export class AutoComputeUtils {
199199
* @returns
200200
*/
201201
stringToNumber(str: string) {
202-
if (ProgramFunctions.isHaveVar(str)) {
203-
return parseFloat(ProgramFunctions.getVarInCore(str));
202+
if (ProgramFunctions.isHaveVar(this.project, str)) {
203+
return parseFloat(ProgramFunctions.getVarInCore(this.project, str));
204204
}
205205
return parseFloat(str);
206206
}

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

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ type OtherFunctionType = (
2222
fatherNodes: ConnectableEntity[],
2323
childNodes: ConnectableEntity[],
2424
) => string[];
25+
type VariableFunctionType = (project: Project, args: string[]) => string[];
2526
type StringFunctionMap = Record<string, StringFunctionType>;
2627
type OtherFunctionMap = Record<string, OtherFunctionType>;
28+
type VariableFunctionMap = Record<string, VariableFunctionType>;
2729

2830
@service("autoCompute")
2931
export class AutoCompute {
@@ -113,6 +115,9 @@ export class AutoCompute {
113115
[LogicNodeNameEnum.REPLACE]: StringFunctions.replace,
114116
[LogicNodeNameEnum.CONNECT]: StringFunctions.connect,
115117
[LogicNodeNameEnum.CHECK_REGEX_MATCH]: StringFunctions.checkRegexMatch,
118+
};
119+
120+
MapVariableFunction: VariableFunctionMap = {
116121
// 编程类功能
117122
[LogicNodeNameEnum.SET_VAR]: ProgramFunctions.setVar,
118123
[LogicNodeNameEnum.GET_VAR]: ProgramFunctions.getVar,
@@ -223,17 +228,12 @@ export class AutoCompute {
223228
}
224229

225230
isTextNodeLogic(node: TextNode): boolean {
226-
for (const name of Object.keys(this.MapNameFunction)) {
227-
if (node.text === name) {
228-
return true;
229-
}
230-
}
231-
for (const name of Object.keys(this.MapOtherFunction)) {
232-
if (node.text === name) {
233-
return true;
234-
}
235-
}
236-
return false;
231+
const names = [
232+
...Object.keys(this.MapNameFunction),
233+
...Object.keys(this.MapOtherFunction),
234+
...Object.keys(this.MapVariableFunction),
235+
];
236+
return names.includes(node.text);
237237
}
238238

239239
private isSectionLogic(section: Section): boolean {
@@ -301,6 +301,17 @@ export class AutoCompute {
301301
this.project.autoComputeUtils.generateMultiResult(node, result);
302302
}
303303
}
304+
// 变量计算
305+
for (const name of Object.keys(this.MapVariableFunction)) {
306+
if (node.text === name) {
307+
// 发现了一个变量节点
308+
const result = this.MapVariableFunction[name](
309+
this.project,
310+
this.project.autoComputeUtils.getParentTextNodes(node).map((p) => p.text),
311+
);
312+
this.project.autoComputeUtils.generateMultiResult(node, result);
313+
}
314+
}
304315
}
305316

306317
private computeSection(section: Section) {

app/src/sub/AutoCompleteWindow.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import { SubWindow } from "@/core/service/SubWindow";
12
import { Vector } from "@graphif/data-structures";
23
import { Rectangle } from "@graphif/shapes";
3-
import { SubWindow } from "@/core/service/SubWindow";
44

55
export default function AutoCompleteWindow({
66
// winId = "",
@@ -25,9 +25,10 @@ export default function AutoCompleteWindow({
2525

2626
AutoCompleteWindow.open = (location: Vector, items: Record<string, string>, onSelect: (value: string) => void) => {
2727
return SubWindow.create({
28-
title: "自动补全",
2928
children: <AutoCompleteWindow items={items} onSelect={onSelect} />,
3029
rect: new Rectangle(location, Vector.same(-1)),
3130
closeWhenClickOutside: true,
31+
titleBarOverlay: true,
32+
closable: false,
3233
});
3334
};

0 commit comments

Comments
 (0)