node add desc

This commit is contained in:
zhandouxiaojiji committed 2020-10-23 18:04:54 +08:00
1 parent ad320d73a5
commit 1c7ef5903d
4 files changed
+35 -27

No files matched your search

+1
View File
@@ -29,6 +29,7 @@ export const createTreeData = (bNode: BehaviorNodeModel) => {
const treeData: any = { const treeData: any = {
id: bNode.id.toString(), id: bNode.id.toString(),
name: bNode.name, name: bNode.name,
desc: bNode.desc,
} }
if (bNode.children) { if (bNode.children) {
treeData.children = []; treeData.children = [];
+5 -5
View File
@@ -24,7 +24,7 @@ const sampleNodeClassify: BehaviorNodeClassify[] = [
export default class Settings { export default class Settings {
private settings: SettingsModel; private settings: SettingsModel;
private name2classify: { [name: string]: string } = {}; private name2conf: { [name: string]: BehaviorNodeTypeModel } = {};
constructor() { constructor() {
this.load(); this.load();
} }
@@ -41,9 +41,9 @@ export default class Settings {
get nodeConfig() { get nodeConfig() {
const str = fs.readFileSync(this.nodeConfigPath, 'utf8'); const str = fs.readFileSync(this.nodeConfigPath, 'utf8');
const types: BehaviorNodeTypeModel[] = JSON.parse(str); const types: BehaviorNodeTypeModel[] = JSON.parse(str);
this.name2classify = {}; this.name2conf = {};
types.forEach(t => { types.forEach(t => {
this.name2classify[t.name] = t.type; this.name2conf[t.name] = t;
}) })
return types; return types;
} }
@@ -78,7 +78,7 @@ export default class Settings {
fs.writeFileSync(settingPath, JSON.stringify(this.settings, null, 2)); fs.writeFileSync(settingPath, JSON.stringify(this.settings, null, 2));
} }
getClassify(name: string) { getNodeConf(name: string) {
return this.name2classify[name]; return this.name2conf[name];
} }
} }
+6
View File
@@ -80,11 +80,17 @@ export default class Editor extends React.Component<EditorProps, EditorState> {
graph.on('node:mouseenter', (e: G6GraphEvent) => { graph.on('node:mouseenter', (e: G6GraphEvent) => {
const { item } = e; const { item } = e;
if(item.hasState('selected')) {
return;
}
graph.setItemState(item, 'hover', true); graph.setItemState(item, 'hover', true);
}); });
graph.on('node:mouseleave', (e: G6GraphEvent) => { graph.on('node:mouseleave', (e: G6GraphEvent) => {
const { item } = e; const { item } = e;
if(item.hasState('selected')) {
return;
}
graph.setItemState(item, 'hover', false); graph.setItemState(item, 'hover', false);
}); });
+23 -22
View File
@@ -20,12 +20,12 @@ const { Header, Sider, Content, Footer } = Layout;
const { TabPane } = Tabs; const { TabPane } = Tabs;
const NODE_COLORS: any = { const NODE_COLORS: any = {
['Composite'] : 'rgb(91,237,32)', ['Composite']: 'rgb(91,237,32)',
['Decorator'] : 'rgb(218,167,16)', ['Decorator']: 'rgb(218,167,16)',
['Condition'] : 'rgb(228,20,139)', ['Condition']: 'rgb(228,20,139)',
['Action'] : 'rgb(91,143,249)', ['Action']: 'rgb(91,143,249)',
['Other'] : 'rgb(112,112,112)', ['Other']: 'rgb(112,112,112)',
} }
interface MainState { interface MainState {
workspace: string; workspace: string;
@@ -60,17 +60,17 @@ export default class Main extends Component {
width: 150, width: 150,
}, },
stateStyles: { stateStyles: {
hover: {
'main-box': {
fill: 'gray',
}
},
selected: { selected: {
'main-box': { 'main-box': {
stroke: 'black', stroke: 'black',
lineWidth: 3, lineWidth: 3,
}, },
}, },
hover: {
'name-text': {
stroke: 'white',
}
},
dragSrc: { dragSrc: {
fill: 'gray', fill: 'gray',
}, },
@@ -92,8 +92,9 @@ export default class Main extends Component {
}, },
}, },
draw(cfg, group) { draw(cfg, group) {
const classfiy = settings.getClassify(cfg.name as string) || 'Other'; const nodeConf = settings.getNodeConf(cfg.name as string);
const color = NODE_COLORS[classfiy]; const classify = nodeConf.type || 'Other';
const color = NODE_COLORS[classify] || 'Other';
var size = cfg.size ? cfg.size as number[] : [150, 40]; var size = cfg.size ? cfg.size as number[] : [150, 40];
const w = size[0]; const w = size[0];
const h = size[1]; const h = size[1];
@@ -118,9 +119,9 @@ export default class Main extends Component {
// name bg // name bg
group.addShape('rect', { group.addShape('rect', {
attrs: { attrs: {
x: x0+1.5, x: x0 + 1.5,
y: y0+1.5, y: y0 + 1.5,
width: w-3, width: w - 3,
height: 16, height: 16,
fill: color, fill: color,
// radius: r, // radius: r,
@@ -144,8 +145,8 @@ export default class Main extends Component {
}); });
// icon // icon
var img = `./static/icons/${classfiy}.svg`; var img = `./static/icons/${classify}.svg`;
console.log(cfg.type, classfiy); console.log(cfg.type, classify);
group.addShape('image', { group.addShape('image', {
attrs: { attrs: {
x: x0 + 15, x: x0 + 15,
@@ -173,20 +174,20 @@ export default class Main extends Component {
var x = x0 + 2; var x = x0 + 2;
var y = y0 + 20; var y = y0 + 20;
// desc text // desc text
if(cfg.desc) { const desc = cfg.desc || nodeConf.desc;
if (desc) {
group.addShape('text', { group.addShape('text', {
attrs: { attrs: {
textBaseline: 'top', textBaseline: 'top',
x, x,
y, y,
lineHeight: 20, lineHeight: 20,
text: cfg.name, text: `备注:${desc}`,
fill: 'black', fill: 'black',
}, },
name: 'name-text', name: 'desc-text',
}); });
} }
group.addShape('rect', { group.addShape('rect', {
name: 'drag-up', name: 'drag-up',