refreshNodeId when save tree
This commit is contained in:
1 parent
db709a28ec
commit
c30c81d53b
4 files changed
+22
-6
No files matched your search
@@ -56,8 +56,7 @@ npm run dist # 编译exe可执行文件
|
||||
## TODO
|
||||
+ 右键菜单
|
||||
+ 面板拖拽新建节点
|
||||
+ 未保存的行为树标星号
|
||||
+ 异步加载界面
|
||||
+ 变量自动补全
|
||||
|
||||
## About
|
||||
目前编辑器还处于非常简陋的阶段,有问题可以联系作者(QQ1013299930),本项目将长期维护,望前端大佬们多提点~
|
||||
@@ -364,7 +364,7 @@ export default class AppMenu {
|
||||
submenu: serverItems,
|
||||
},
|
||||
{
|
||||
label: "处理脚本",
|
||||
label: "批处理脚本",
|
||||
click: () => {
|
||||
(async () => {
|
||||
const res = await dialog.showOpenDialog({
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "behavior3editor",
|
||||
"version": "0.1.6",
|
||||
"version": "0.1.7",
|
||||
"description": "行为树编辑器",
|
||||
"main": "./dist/main.js",
|
||||
"scripts": {
|
||||
|
||||
@@ -39,6 +39,7 @@ export default class Editor extends React.Component<EditorProps, EditorState> {
|
||||
private treeModel: BehaviorTreeModel;
|
||||
private settings: Settings;
|
||||
private data: GraphNodeModel;
|
||||
private unsave: boolean = false;
|
||||
|
||||
constructor(props: EditorProps) {
|
||||
super(props);
|
||||
@@ -336,11 +337,17 @@ export default class Editor extends React.Component<EditorProps, EditorState> {
|
||||
this.graph.set("animate", true);
|
||||
|
||||
this.props.onChangeSaveState(true);
|
||||
this.unsave = true;
|
||||
}
|
||||
|
||||
save() {
|
||||
if(!this.unsave) {
|
||||
return;
|
||||
}
|
||||
const { filepath } = this.props;
|
||||
const root = Utils.createFileData(this.graph.findDataById("1") as GraphNodeModel);
|
||||
const data = this.graph.findDataById("1") as GraphNodeModel;
|
||||
this.autoId = Utils.refreshNodeId(data);
|
||||
const root = Utils.createFileData(data);
|
||||
const treeModel = {
|
||||
name: path.basename(filepath).slice(0, -5),
|
||||
root,
|
||||
@@ -348,9 +355,17 @@ export default class Editor extends React.Component<EditorProps, EditorState> {
|
||||
} as BehaviorTreeModel;
|
||||
fs.writeFileSync(
|
||||
filepath,
|
||||
JSON.stringify(treeModel)
|
||||
JSON.stringify(treeModel, null, 2)
|
||||
);
|
||||
this.props.onChangeSaveState(false);
|
||||
this.unsave = false;
|
||||
|
||||
this.graph.set("animate", false);
|
||||
this.graph.changeData(Utils.createTreeData(root, this.settings));
|
||||
this.graph.layout();
|
||||
this.graph.fitCenter();
|
||||
this.graph.set("animate", true);
|
||||
|
||||
return treeModel;
|
||||
}
|
||||
|
||||
@@ -400,6 +415,7 @@ export default class Editor extends React.Component<EditorProps, EditorState> {
|
||||
this.graph.set("animate", true);
|
||||
|
||||
this.props.onChangeSaveState(true);
|
||||
this.unsave = true;
|
||||
}
|
||||
|
||||
pushUndoStack(keepRedo?: boolean) {
|
||||
@@ -460,6 +476,7 @@ export default class Editor extends React.Component<EditorProps, EditorState> {
|
||||
const item = this.graph.findById(id);
|
||||
item.draw();
|
||||
this.props.onChangeSaveState(true);
|
||||
this.unsave = true;
|
||||
}}
|
||||
pushUndoStack={() => {
|
||||
this.pushUndoStack();
|
||||
|
||||
Reference in new issue
Block a user