node menu add classify

This commit is contained in:
zhandouxiaojiji committed 2020-10-15 11:28:58 +08:00
1 parent 78aec1afb1
commit 31d986c5d2
3 files changed
+56 -8

No files matched your search

+36 -4
View File
@@ -167,18 +167,50 @@ export default class AppMenu {
}
private createNodeMenu() {
const nodeItems: MenuItemConstructorOptions[] = [];
const typeItems: MenuItemConstructorOptions[] = [];
const map: { [key: string]: MenuItemConstructorOptions } = {}
for (let t of this.settings.nodeTypes) {
let item: MenuItemConstructorOptions = {
id: t.type,
label: `${t.type}(${t.desc})`,
submenu: [],
};
typeItems.push(item);
map[t.type] = item;
}
const other: MenuItemConstructorOptions = {
id: 'other',
label: "其它",
submenu: [],
};
var hasOther = false;
for (let node of this.settings.nodeConfig) {
nodeItems.push({
const item: MenuItemConstructorOptions = {
label: `${node.name}(${node.desc})`,
click: () => {
console.log("create node", node.name);
}
})
}
let typeItem = map[node.type];
if(!typeItem) {
typeItem = other;
hasOther = true;
}
if (typeItem.submenu instanceof Menu) {
console.log("typeItem.submenu error", typeItem);
} else {
typeItem.submenu.push(item);
}
}
if(hasOther) {
typeItems.push(other);
}
return new MenuItem({
label: "新建节点",
submenu: nodeItems
submenu: typeItems
});
}
}
+19 -3
View File
@@ -1,18 +1,30 @@
import * as fs from 'fs';
const settingPath = 'settings.json';
const sampleNodeConfig = 'sample-node-config.json'
export interface BehaviorNodeType {
type: string;
desc?: string;
}
export interface SettingsModel {
recentWorkspaces?: string[];
recentFiles?: string[];
nodeConfigPath?: string; // 节点配置路径
nodeTypes?: BehaviorNodeType[];
}
const settingPath = 'settings.json';
const sampleNodeConfig = 'sample-node-config.json';
const sampleNodeTypes: BehaviorNodeType[] = [
{ type: "Composite", desc: "复合节点" },
{ type: "Decorator", desc: "修饰节点" },
{ type: "Condition", desc: "条件节点" },
{ type: "Action", desc: "行为节点" },
]
export default class Settings {
private settings: SettingsModel;
constructor() {
if(fs.existsSync(settingPath)) {
if (fs.existsSync(settingPath)) {
const str = fs.readFileSync(settingPath, 'utf8');
this.settings = JSON.parse(str);
} else {
@@ -20,6 +32,7 @@ export default class Settings {
recentWorkspaces: [],
recentFiles: [],
nodeConfigPath: sampleNodeConfig,
nodeTypes: sampleNodeTypes,
};
this.save();
}
@@ -38,6 +51,9 @@ export default class Settings {
const str = fs.readFileSync(this.nodeConfigPath, 'utf8');
return JSON.parse(str);
}
get nodeTypes() {
return this.settings.nodeTypes;
}
set(config: SettingsModel) {
this.settings = {