update project template

This commit is contained in:
codetypes committed 2024-05-12 13:22:17 +08:00
1 parent eece90d233
commit fa5644fda7
8 files changed
+337 -216

No files matched your search

+1 -1
View File
@@ -1 +1 @@
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1603437225887" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1131" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><defs><style type="text/css"></style></defs><path d="M89.6 806.4h844.8V217.6H89.6v588.8zM0 128h1024v768H0V128z m242.816 577.536L192 654.72l154.304-154.368L192 346.048l50.816-50.816L448 500.352l-205.184 205.184z m584.32 13.248H512V640h315.072v78.72z" fill="#000000" p-id="1132"></path></svg> <svg stroke="currentColor" fill="none" stroke-width="0" viewBox="0 0 24 24" height="200px" width="200px" xmlns="http://www.w3.org/2000/svg"><path d="M5.0333 14.8284L6.44751 16.2426L10.6902 12L6.44751 7.75733L5.0333 9.17155L7.86172 12L5.0333 14.8284Z" fill="currentColor"></path><path d="M15 14H11V16H15V14Z" fill="currentColor"></path><path fill-rule="evenodd" clip-rule="evenodd" d="M2 2C0.895431 2 0 2.89543 0 4V20C0 21.1046 0.89543 22 2 22H22C23.1046 22 24 21.1046 24 20V4C24 2.89543 23.1046 2 22 2H2ZM22 4H2L2 20H22V4Z" fill="currentColor"></path></svg>

Before

Width:  |  Height:  |  Size: 614 B

After

Width:  |  Height:  |  Size: 557 B

+1 -1
View File
@@ -1 +1 @@
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1603437247082" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1395" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><defs><style type="text/css"></style></defs><path d="M213.312 682.688v170.624h469.312V768H1024v256h-341.312l-0.064-85.376H128v-256h85.312zM1024 384v256h-341.312l-0.064-85.376h-341.12V469.376h341.12V384H1024z m-85.312 85.312H768v85.376h170.688V469.312zM1024 0v256h-341.312l-0.064-85.376H213.312v170.688H128v-256h554.624V0H1024z m-85.312 85.312H768v85.376h170.688V85.312z m-170.688 768v85.376h170.688v-85.376H768z m-768-512h341.312v341.376H0V341.312z m85.312 85.376v170.624H256V426.688H85.312z" fill="#000000" p-id="1396"></path></svg> <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" preserveAspectRatio="none" width="200" height="200"><defs><path d="M196.55 17.95Q196.55 0 178.65 0H136.2q-17.95 0-17.95 17.95v2.6h-78.5Q23 21 22.65 37.1v27.85h-4.7Q0 64.95 0 82.9v32.05q0 17.95 17.95 17.95h4.7v29.55q.2 16.5 17.9 16.5h77.7v3.15q0 17.9 17.95 17.9h42.45q17.9 0 17.9-17.9v-22.65q0-17.95-17.9-17.95H136.2q-17.95 0-17.95 17.95V162h-77.7q-.7 0-.9-.1v-29H50q17.95 0 17.95-17.95v-6.4h50.3v2.65q0 17.9 17.95 17.9h42.45q17.9 0 17.9-17.9V88.55q0-17.95-17.9-17.95H136.2q-17.95 0-17.95 17.95v3h-50.3V82.9q0-17.95-17.95-17.95H39.65V37.7q.15-.2.6-.2h78v3.1q0 17.9 17.95 17.9h42.45q17.9 0 17.9-17.9V17.95M179.6 40.6q0 .9-.95.9H136.2q-.95 0-.95-.9V17.95q0-.95.95-.95h42.45q.95 0 .95.95V40.6m-.95 47q.95 0 .95.95v22.65q0 .95-.95.95H136.2q-.95 0-.95-.95V88.55q0-.95.95-.95h42.45m.95 94.5q0 .95-.95.95H136.2q-.95 0-.95-.95v-22.65q0-.95.95-.95h42.45q.95 0 .95.95v22.65M17 82.9q0-.95.95-.95H50q.95 0 .95.95v32.05q0 .95-.95.95H17.95q-.95 0-.95-.95V82.9z" id="prefix__a"/></defs><use xlink:href="#prefix__a"/></svg>

Before

Width:  |  Height:  |  Size: 857 B

After

Width:  |  Height:  |  Size: 1.1 KiB

+1 -37
View File
@@ -94,41 +94,5 @@
"node.subtree": "Subtree", "node.subtree": "Subtree",
"node.subtreePathError": "You should save the subtree inside the current workspace", "node.subtreePathError": "You should save the subtree inside the current workspace",
"node.unknown.desc": "New node", "node.unknown.desc": "New node"
"node.alwaysFail.desc": "Always return failure",
"node.alwaysFail.doc": "+ Only one child node, multiple child nodes will be executed first\n+ If any child node fails, return failure",
"node.alwaysSuccess.desc": "Always return success",
"node.alwaysSuccess.doc": "+ Only one child node, multiple child nodes will be executed first\n+ If any child node fails, return success",
"node.check.arg1.desc": "Expression",
"node.check.desc": "Evaluate expression",
"node.check.doc": "+ Do simple calculation, return success or failure",
"node.clear.desc": "Clear variable",
"node.clear.output1": "Variable name",
"node.forEach.desc": "Iterate array",
"node.forEach.input1": "Array",
"node.forEach.output1": "Variable name",
"node.forEach.doc": "+ Before executing each child node, set the current variable to the output\n+ Execute all child nodes\n+ Return success or running",
"node.getTime.desc": "Get current time",
"node.getTime.output1": "Current time",
"node.isNull.desc": "Check variable is null",
"node.isNull.input1": "Variable",
"node.log.desc": "Print log",
"node.log.arg1.desc": "Log content",
"node.loop.desc": "Loop execute",
"node.loop.arg1.desc": "Loop times",
"node.loop.input1": "Loop times",
"node.not.desc": "Invert",
"node.not.doc": "+ Invert the return value",
"node.notNull.desc": "Check variable is not null",
"node.notNull.input1": "Variable",
"node.once.desc": "Execute once",
"node.once.doc": "+ Execute all child nodes\n+ Return success or running",
"node.parallel.desc": "Parallel execute",
"node.parallel.doc": "+ Execute all child nodes\n+ Return success",
"node.selector.desc": "Selector execute",
"node.selector.doc": "+ Execute all child nodes\n+ Return success or failure",
"node.sequence.desc": "Sequence execute",
"node.sequence.doc": "+ Execute all child nodes\n+ Return success or failure",
"node.wait.desc": "Wait",
"node.wait.arg1.desc": "Wait time"
} }
+1 -37
View File
@@ -94,41 +94,5 @@
"node.subtree": "子树", "node.subtree": "子树",
"node.subtreePathError": "子树必须保存在当前工作区的目录内", "node.subtreePathError": "子树必须保存在当前工作区的目录内",
"node.unknown.desc": "新建节点", "node.unknown.desc": "新建节点"
"node.alwaysFail.desc": "始终返回失败",
"node.alwaysFail.doc": "+ 只能有一个子节点,多个仅执行第一个\n+ 不管子节点是否成功都返回失败",
"node.alwaysSuccess.desc": "始终返回成功",
"node.alwaysSuccess.doc": "+ 只能有一个子节点,多个仅执行第一个\n+ 不管子节点是否成功都返回成功",
"node.check.arg1.desc": "表达式",
"node.check.desc": "对表达式进行求值",
"node.check.doc": "+ 做简单数值公式判定,返回成功或失败",
"node.clear.desc": "清除变量",
"node.clear.output1": "清除的变量名",
"node.forEach.desc": "遍历数组",
"node.forEach.input1": "数组",
"node.forEach.output1": "变量名",
"node.forEach.doc": "+ 每次执行子节点前会设置当前遍历到的变量\n+ 会执行所有子节点\n+ 永远返回成功/正在运行",
"node.getTime.desc": "获取当前时间",
"node.getTime.output1": "当前时间",
"node.isNull.desc": "判断变量是否为空",
"node.isNull.input1": "判断的变量",
"node.log.desc": "打印日志",
"node.log.arg1.desc": "日志内容",
"node.loop.desc": "循环执行",
"node.loop.arg1.desc": "循环次数",
"node.loop.input1": "循环次数",
"node.not.desc": "取反",
"node.not.doc": "+ 将子节点的返回值取反",
"node.notNull.desc": "判断变量是否存在",
"node.notNull.input1": "判断的变量",
"node.once.desc": "只执行一次",
"node.once.doc": "+ 可以接多个子节点,子节点默认全部执行\n+ 被打断后该节点后的子节点依旧不会执行\n+ 该节点执行后永远返回成功",
"node.parallel.desc": "并行执行",
"node.parallel.doc": "+ 执行所有子节点并返回成功",
"node.selector.desc": "选择执行",
"node.selector.doc": "+ 一直往下执行,有子节点返回成功则返回成功,若全部节点返回失败则返回失败\n+ 子节点是或 (OR) 的关系",
"node.sequence.desc": "顺序执行",
"node.sequence.doc": "+ 一直往下执行,只有当所有子节点都返回成功, 才返回成功\n+ 子节点是与(AND)的关系",
"node.wait.desc": "等待",
"node.wait.arg1.desc": "等待时间"
} }
+7 -7
View File
@@ -7,10 +7,10 @@ import Path from "@/misc/path";
import G6 from "@antv/g6"; import G6 from "@antv/g6";
const NODE_COLORS: any = { const NODE_COLORS: any = {
["Composite"]: "#5aed20", ["Composite"]: "#34d800",
["Decorator"]: "#faad14", ["Decorator"]: "#ff6700",
["Condition"]: "#e4148b", ["Condition"]: "#e4148b",
["Action"]: "#5b90f9", ["Action"]: "#1668dc",
["Other"]: "#707070", ["Other"]: "#707070",
["Error"]: "#ff0000", ["Error"]: "#ff0000",
}; };
@@ -193,9 +193,9 @@ G6.registerNode(
addShape("image", { addShape("image", {
attrs: { attrs: {
x: 5, x: 5,
y: 3.5, y: 3,
height: 16, height: 18,
width: 16, width: 18,
img, img,
}, },
name: "node-icon", name: "node-icon",
@@ -205,7 +205,7 @@ G6.registerNode(
addShape("text", { addShape("text", {
attrs: { attrs: {
textBaseline: "top", textBaseline: "top",
x: 25, x: 26,
y: 5, y: 5,
fontWeight: 800, fontWeight: 800,
text: cfg.name, text: cfg.name,
+1
View File
@@ -65,6 +65,7 @@ export const Workspace: FC = () => {
workspace.close(workspace.editing.path); workspace.close(workspace.editing.path);
} }
} }
keysRef.current?.focus();
} else if (isHotkeyPressed(Hotkey.SearchTree)) { } else if (isHotkeyPressed(Hotkey.SearchTree)) {
event.preventDefault(); event.preventDefault();
workspace.onShowingSearch(true); workspace.onShowingSearch(true);
+2 -133
View File
@@ -4,6 +4,7 @@ import * as fs from "fs";
import { message } from "./hooks"; import { message } from "./hooks";
import i18n from "./i18n"; import i18n from "./i18n";
import Path from "./path"; import Path from "./path";
import { zhNodeDef } from "./template";
export const isSubtreeRoot = (data: TreeGraphData) => { export const isSubtreeRoot = (data: TreeGraphData) => {
return data.path && data.id.toString() !== "1"; return data.path && data.id.toString() !== "1";
@@ -415,139 +416,7 @@ export const cutWordTo = (str: string, maxlen: number) => {
}; };
export const createProject = (path: string) => { export const createProject = (path: string) => {
fs.writeFileSync( fs.writeFileSync(Path.dirname(path) + "/node-config.b3-setting", zhNodeDef());
Path.dirname(path) + "/node-config.b3-setting",
JSON.stringify(
[
{
name: "AlwaysFail",
type: "Decorator",
desc: i18n.t("node.alwaysFail.desc"),
doc: i18n.t("node.alwaysFail.doc"),
},
{
name: "AlwaysSuccess",
type: "Decorator",
desc: i18n.t("node.alwaysSuccess.desc"),
doc: i18n.t("node.alwaysSuccess.doc"),
},
{
name: "Check",
type: "Condition",
desc: i18n.t("node.check.desc"),
args: [
{
name: "value",
type: "code",
desc: i18n.t("node.check.arg1.desc"),
},
],
doc: i18n.t("node.check.doc"),
},
{
name: "Clear",
type: "Action",
desc: i18n.t("node.clear.desc"),
output: [i18n.t("node.clear.output1")],
},
{
name: "ForEach",
type: "Composite",
desc: i18n.t("node.forEach.desc"),
input: [i18n.t("node.forEach.input1")],
output: [i18n.t("node.forEach.output1")],
doc: i18n.t("node.forEach.doc"),
},
{
name: "GetTime",
type: "Action",
desc: i18n.t("node.getTime.desc"),
output: [i18n.t("node.getTime.output1")],
},
{
name: "IsNull",
type: "Condition",
desc: i18n.t("node.isNull.desc"),
input: [i18n.t("node.isNull.input1")],
},
{
name: "Log",
type: "Action",
desc: i18n.t("node.log.desc"),
args: [
{
name: "message",
type: "string",
desc: i18n.t("node.log.arg1.desc"),
},
],
},
{
name: "Loop",
type: "Composite",
desc: i18n.t("node.loop.desc"),
args: [
{
name: "count",
type: "int?",
desc: i18n.t("node.loop.arg1.desc"),
},
],
input: [i18n.t("node.loop.input1") + "?"],
},
{
name: "Not",
type: "Decorator",
desc: i18n.t("node.not.desc"),
doc: i18n.t("node.not.doc"),
},
{
name: "NotNull",
type: "Condition",
desc: i18n.t("node.notNull.desc"),
input: [i18n.t("node.notNull.input")],
},
{
name: "Once",
type: "Composite",
desc: i18n.t("node.once.desc"),
doc: i18n.t("node.once.doc"),
},
{
name: "Parallel",
type: "Composite",
desc: i18n.t("node.parallel.desc"),
doc: i18n.t("node.parallel.doc"),
},
{
name: "Selector",
type: "Composite",
desc: i18n.t("node.selector.desc"),
doc: i18n.t("node.selector.doc"),
},
{
name: "Sequence",
type: "Composite",
desc: i18n.t("node.sequence.desc"),
doc: i18n.t("node.sequence.doc"),
},
{
name: "Wait",
type: "Action",
desc: i18n.t("node.wait.desc"),
args: [
{
name: "time",
type: "float",
desc: i18n.t("node.wait.arg1.desc"),
},
],
},
],
null,
2
)
);
fs.writeFileSync( fs.writeFileSync(
Path.dirname(path) + "/example.json", Path.dirname(path) + "/example.json",
JSON.stringify( JSON.stringify(
+323
View File
@@ -0,0 +1,323 @@
type Status = "success" | "failure" | "running";
type Constructor<T = unknown> = new (...args: unknown[]) => T;
interface TreeEnv {}
interface Node {}
interface NodeDef {
name: string;
type: "Action" | "Decorator" | "Condition" | "Composite";
desc: string;
icon?: string;
color?: string;
input?: string[];
args?: {
name: string;
type:
| "boolean"
| "boolean?"
| "int"
| "int?"
| "float"
| "float?"
| "enum"
| "enum?"
| "string"
| "string?"
| "code"
| "code?";
desc: string;
options?: { name: string; value: unknown }[];
}[];
output?: string[];
doc?: string;
}
abstract class Process {
init(node: Node): void {}
run(node: Node, env: TreeEnv): Status {
return "success";
}
abstract get descriptor(): NodeDef;
}
namespace zh {
export namespace action {
export class Clear extends Process {
override get descriptor(): NodeDef {
return {
name: "Clear",
type: "Action",
desc: "清除变量",
output: ["清除的变量名"],
};
}
}
export class Log extends Process {
override get descriptor(): NodeDef {
return {
name: "Log",
type: "Action",
desc: "打印日志",
args: [{ name: "message", type: "string", desc: "日志" }],
};
}
}
export class Now extends Process {
override get descriptor(): NodeDef {
return {
name: "Now",
type: "Action",
desc: "获取当前时间",
output: ["当前时间"],
};
}
}
export class Wait extends Process {
override get descriptor(): NodeDef {
return {
name: "Wait",
type: "Action",
desc: "等待",
input: ["等待时间?"],
args: [
{ name: "time", type: "float", desc: "等待时间" },
{ name: "random", type: "float?", desc: "随机范围" },
],
};
}
}
}
export namespace composite {
export class Foreach extends Process {
override get descriptor(): NodeDef {
return {
name: "ForEach",
type: "Composite",
desc: "遍历数组",
input: ["数组"],
output: ["变量"],
doc: `
+ 每次执行子节点前会设置当前遍历到的变量
+ 会执行所有子节点
+ 永远返回「成功」/「运行中」`,
};
}
}
export class Loop extends Process {
override get descriptor(): NodeDef {
return {
name: "Loop",
type: "Composite",
desc: "循环执行",
input: ["循环次数?"],
args: [{ name: "count", type: "int", desc: "循环次数" }],
};
}
}
export class Parallel extends Process {
override get descriptor(): NodeDef {
return {
name: "Parallel",
type: "Composite",
desc: "并行执行",
doc: `执行所有子节点并返回「成功」/「运行中」`,
};
}
}
export class Selector extends Process {
override get descriptor(): NodeDef {
return {
name: "Selector",
type: "Composite",
desc: "选择执行",
doc: `
+ 一直往下执行,有子节点返回「成功」则返回「成功」
+ 若全部节点返回「失败」则返回「失败」
+ 子节点是或 (OR) 的关系`,
};
}
}
export class Sequence extends Process {
override get descriptor(): NodeDef {
return {
name: "Sequence",
type: "Composite",
desc: "顺序执行",
doc: `
+ 一直往下执行,只有当所有子节点都返回「成功」, 才返回「成功」
+ 子节点是与(AND)的关系`,
};
}
}
}
export namespace condition {
export class Check extends Process {
override get descriptor(): NodeDef {
return {
name: "Check",
type: "Condition",
desc: "检查True或False",
args: [{ name: "value", type: "code", desc: "值" }],
doc: `
+ 做简单数值公式判定,返回「成功」或「失败」`,
};
}
}
export class IsNull extends Process {
override get descriptor(): NodeDef {
return {
name: "IsNull",
type: "Condition",
desc: "判断变量是否不存在",
input: ["判断的变量"],
};
}
}
export class NotNull extends Process {
override get descriptor(): NodeDef {
return {
name: "NotNull",
type: "Condition",
desc: "判断变量是否存在",
input: ["判断的变量"],
};
}
}
}
export namespace decorator {
export class AlwaysFail extends Process {
override get descriptor(): NodeDef {
return {
name: "AlwaysFail",
type: "Decorator",
desc: "始终返回失败",
doc: `
+ 只能有一个子节点,多个仅执行第一个
+ 不管子节点是否成功都返回「失败」`,
};
}
}
export class AlwaysSuccess extends Process {
override get descriptor(): NodeDef {
return {
name: "AlwaysSuccess",
type: "Decorator",
desc: "始终返回成功",
doc: `
+ 只能有一个子节点,多个仅执行第一个
+ 不管子节点是否成功都返回「成功」`,
};
}
}
export class Inverter extends Process {
override get descriptor(): NodeDef {
return {
name: "Inverter",
type: "Decorator",
desc: "反转子节点运行结果",
doc: `
+ 只能有一个子节点,多个仅执行第一个
+ 当子节点返回「成功」时返回「失败」
+ 当子节点返回「失败」时返回「成功」
+ 其余返回「运行中」`,
};
}
}
export class Once extends Process {
override get descriptor(): NodeDef {
return {
name: "Once",
type: "Decorator",
desc: "只执行一次",
doc: `
+ 可以接多个子节点,子节点默认全部执行
+ 被打断后该节点后的子节点依旧不会执行
+ 该节点执行后永远返回「成功」`,
};
}
}
export class RepeatUntilFailure extends Process {
override get descriptor(): NodeDef {
return {
name: "RepeatUntilFailure",
type: "Decorator",
desc: "一直尝试直到子节点返回失败",
input: ["最大循环次数?"],
args: [{ name: "maxLoop", type: "int?", desc: "最大循环次数" }],
doc: `
+ 只能有一个子节点,多个仅执行第一个
+ 只有当子节点返回「失败」时,才返回「成功」,其它情况返回「运行中」状态
+ 如果设定了尝试次数,超过指定次数则返回「失败」`,
};
}
}
export class RepeatUntilSuccess extends Process {
override get descriptor(): NodeDef {
return {
name: "RepeatUntilSuccess",
type: "Decorator",
desc: "一直尝试直到子节点返回成功",
input: ["最大循环次数?"],
args: [{ name: "maxLoop", type: "int?", desc: "最大循环次数" }],
doc: `
+ 只能有一个子节点,多个仅执行第一个
+ 只有当子节点返回「成功」时,才返回「成功」,其它情况返回「运行中」状态
+ 如果设定了尝试次数,超过指定次数则返回「失败」`,
};
}
}
}
}
const toString = (nodes: Constructor<Process>[]) => {
const defs: NodeDef[] = [];
for (const cls of nodes) {
defs.push(new cls().descriptor);
}
defs.sort((a, b) => a.name.localeCompare(b.name));
let str = JSON.stringify(defs, null, 2);
str = str.replace(/"doc": "\\n +/g, '"doc": "');
str = str.replace(/\\n +/g, "\\n");
return str;
};
export const zhNodeDef = () => {
return toString([
zh.action.Clear,
zh.action.Log,
zh.action.Now,
zh.action.Wait,
zh.composite.Foreach,
zh.composite.Loop,
zh.composite.Parallel,
zh.composite.Selector,
zh.composite.Sequence,
zh.condition.Check,
zh.condition.IsNull,
zh.condition.NotNull,
zh.decorator.AlwaysFail,
zh.decorator.AlwaysSuccess,
zh.decorator.Inverter,
zh.decorator.Once,
zh.decorator.RepeatUntilFailure,
zh.decorator.RepeatUntilSuccess,
]);
};