This commit is contained in:
zhandouxiaojiji committed 2020-12-02 13:06:18 +08:00
1 parent d87cba3622
commit 242a960634
3 files changed
+41 -26

No files matched your search

+1
View File
@@ -8,6 +8,7 @@ export const cloneNodeData = (nodeData: GraphNodeModel) => {
const newData: BehaviorNodeModel = { const newData: BehaviorNodeModel = {
id: Number(nodeData.id), id: Number(nodeData.id),
name: nodeData.name, name: nodeData.name,
desc: nodeData.desc,
}; };
if(nodeData.input) { if(nodeData.input) {
newData.input = []; newData.input = [];
+12 -9
View File
@@ -27,6 +27,7 @@ interface NodePanelProps {
model: BehaviorNodeModel; model: BehaviorNodeModel;
settings: Settings; settings: Settings;
updateNode: (id: string, forceUpdate: boolean) => void; updateNode: (id: string, forceUpdate: boolean) => void;
pushUndoStack: () => void;
} }
interface NodePanelState {} interface NodePanelState {}
@@ -67,20 +68,12 @@ export default class NodePanel extends React.Component<NodePanelProps> {
onFinish = (values: any) => { onFinish = (values: any) => {
console.log("Success:", values); console.log("Success:", values);
const { updateNode, model, settings } = this.props; const { updateNode, pushUndoStack, model, settings } = this.props;
const conf = settings.getNodeConf(values.name); const conf = settings.getNodeConf(values.name);
if (!conf) { if (!conf) {
notification.warn({ message: `节点${values.name}未定义` }); notification.warn({ message: `节点${values.name}未定义` });
return; return;
} }
var forceUpdate = false;
if (model.name != values.name) {
model.name = values.name;
forceUpdate = true;
}
model.desc = values.desc;
model.debug = values.debug;
var args: any = {}; var args: any = {};
if (values.customArgs) { if (values.customArgs) {
try { try {
@@ -91,6 +84,16 @@ export default class NodePanel extends React.Component<NodePanelProps> {
} }
} }
pushUndoStack();
var forceUpdate = false;
if (model.name != values.name) {
model.name = values.name;
forceUpdate = true;
}
model.desc = values.desc;
model.debug = values.debug;
if (conf.args) { if (conf.args) {
conf.args.forEach((e) => { conf.args.forEach((e) => {
const k = "args." + e.name; const k = "args." + e.name;
+28 -17
View File
@@ -50,6 +50,7 @@ export default class Editor extends React.Component<EditorProps, EditorState> {
width: window.screen.width * 0.66, width: window.screen.width * 0.66,
height: window.screen.height, height: window.screen.height,
animate: false, animate: false,
maxZoom: 2,
// fitCenter: true, // fitCenter: true,
modes: { modes: {
default: [ default: [
@@ -323,12 +324,6 @@ export default class Editor extends React.Component<EditorProps, EditorState> {
this.changeWithoutAnim(); this.changeWithoutAnim();
} }
pushUndoStack() {
this.undoStack.push(Utils.cloneNodeData(this.graph.findDataById('1') as GraphNodeModel));
console.log("push", this.undoStack);
this.redoStack = [];
}
changeWithoutAnim() { changeWithoutAnim() {
this.graph.set("animate", false); this.graph.set("animate", false);
this.graph.changeData(); this.graph.changeData();
@@ -389,16 +384,33 @@ export default class Editor extends React.Component<EditorProps, EditorState> {
} }
} }
useStackData(data: BehaviorNodeModel) {
this.graph.set("animate", false);
this.graph.changeData(Utils.createTreeData(data, this.state.settings));
this.graph.layout(true);
this.graph.set("animate", true);
}
pushUndoStack(keepRedo?: boolean) {
this.undoStack.push(Utils.cloneNodeData(this.graph.findDataById('1') as GraphNodeModel));
console.log("push undo", this.undoStack);
if (!keepRedo) {
this.redoStack = [];
}
}
pushRedoStack() {
this.redoStack.push(Utils.cloneNodeData(this.graph.findDataById('1') as GraphNodeModel));
console.log("push redo", this.redoStack);
}
undo() { undo() {
if (this.undoStack.length == 0) { if (this.undoStack.length == 0) {
return; return;
} }
const data = this.undoStack.pop(); const data = this.undoStack.pop();
this.graph.set("animate", false); this.pushRedoStack();
this.graph.changeData(Utils.createTreeData(data, this.state.settings)); this.useStackData(data);
this.graph.layout();
this.graph.set("animate", true);
this.redoStack.push(data);
} }
redo() { redo() {
@@ -406,11 +418,8 @@ export default class Editor extends React.Component<EditorProps, EditorState> {
return; return;
} }
const data = this.redoStack.pop(); const data = this.redoStack.pop();
this.graph.set("animate", false); this.pushUndoStack(true);
this.graph.changeData(Utils.createTreeData(data, this.state.settings)); this.useStackData(data);
this.graph.layout();
this.graph.set("animate", true);
this.undoStack.push(data);
} }
render() { render() {
@@ -431,7 +440,6 @@ export default class Editor extends React.Component<EditorProps, EditorState> {
settings={settings} settings={settings}
updateNode={(id, forceUpdate) => { updateNode={(id, forceUpdate) => {
if (forceUpdate) { if (forceUpdate) {
this.pushUndoStack();
const data: any = this.graph.findDataById(id); const data: any = this.graph.findDataById(id);
data.conf = settings.getNodeConf(data.name); data.conf = settings.getNodeConf(data.name);
data.size = Utils.calcTreeNodeSize(data); data.size = Utils.calcTreeNodeSize(data);
@@ -440,6 +448,9 @@ export default class Editor extends React.Component<EditorProps, EditorState> {
const item = this.graph.findById(id); const item = this.graph.findById(id);
item.draw(); item.draw();
}} }}
pushUndoStack={() => {
this.pushUndoStack();
}}
/> />
) : ( ) : (
<TreePanel model={treeModel} /> <TreePanel model={treeModel} />