Skip to content

Commit 3343b1c

Browse files
committed
✨ Variable related logic nodes
1 parent 1eb3350 commit 3343b1c

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

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

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,41 @@
1-
export namespace ProgramFunctions {
2-
export const variables: Record<string, string> = {};
1+
import { Project } from "@/core/Project";
32

3+
export namespace ProgramFunctions {
44
/**
55
* 核心代码的获取变量值的方法
66
* @param varName
77
* @returns
88
*/
9-
export function getVarInCore(varName: string): string {
10-
if (varName in variables) {
11-
return variables[varName];
12-
}
13-
return "NaN";
9+
export function getVarInCore(project: Project, varName: string): string {
10+
return project.autoCompute.variables.get(varName) || "NaN";
1411
}
1512

16-
export function isHaveVar(varName: string): boolean {
17-
return varName in variables;
13+
export function isHaveVar(project: Project, varName: string): boolean {
14+
return project.autoCompute.variables.has(varName);
1815
}
1916

2017
/**
2118
* 设置变量,变量名不能是逻辑节点名称
2219
* @param args
2320
* @returns
2421
*/
25-
export function setVar(args: string[]): string[] {
22+
export function setVar(project: Project, args: string[]): string[] {
2623
if (args.length !== 2) {
2724
return ["error", "参数数量错误,必须保证两个"];
2825
}
2926
const varName = args[0];
30-
if (!/^[a-zA-Z\u4e00-\u9fa5]/.test(varName)) {
31-
return ["error", "变量名必须以字母或汉字开头"];
32-
}
33-
variables[varName] = args[1];
27+
project.autoCompute.variables.set(varName, args[1]);
3428
return ["success"];
3529
}
3630

3731
/**
3832
* 获取现存变量,如果没有,则返回NaN
3933
* @param args
4034
*/
41-
export function getVar(args: string[]): string[] {
35+
export function getVar(project: Project, args: string[]): string[] {
4236
if (args.length === 1) {
4337
const varName = args[0];
44-
return [getVarInCore(varName)];
38+
return [project.autoCompute.variables.get(varName) || "NaN"];
4539
}
4640
return ["error", "参数数量错误"];
4741
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ export class AutoCompute {
153153
[LogicNodeNameEnum.DELAY_COPY]: NodeLogic.delayCopy,
154154
};
155155

156+
variables = new Map<string, string>();
157+
156158
constructor(private readonly project: Project) {}
157159

158160
private tickNumber = 0;

0 commit comments

Comments
 (0)