mirror of
https://github.com/tengge1/ShadowEditor.git
synced 2026-01-25 15:08:11 +00:00
修复保存场景引用bug。
This commit is contained in:
parent
a9ca17a71b
commit
eae35a4aeb
@ -244,10 +244,6 @@ Editor.prototype.load = function () { // 加载场景
|
||||
this.app.call('load', this);
|
||||
};
|
||||
|
||||
Editor.prototype.save = function () { // 保存场景
|
||||
this.app.call('save', this);
|
||||
};
|
||||
|
||||
// --------------------- 命令事件 ------------------------
|
||||
|
||||
Editor.prototype.execute = function (cmd, optionalName) { // 执行事件
|
||||
|
||||
@ -33,7 +33,6 @@ import RemoveScriptEvent from './editor/RemoveScriptEvent';
|
||||
import SelectEvent from './editor/SelectEvent';
|
||||
import ClearEvent from './editor/ClearEvent';
|
||||
import LoadEvent from './editor/LoadEvent';
|
||||
import SaveEvent from './editor/SaveEvent';
|
||||
|
||||
// 工具栏
|
||||
import SelectModeEvent from './toolbar/SelectModeEvent';
|
||||
@ -183,7 +182,6 @@ function EventDispatcher(app) {
|
||||
new SelectEvent(this.app),
|
||||
new ClearEvent(this.app),
|
||||
new LoadEvent(this.app),
|
||||
new SaveEvent(this.app),
|
||||
|
||||
// 工具栏
|
||||
new SelectModeEvent(this.app),
|
||||
|
||||
@ -112,7 +112,6 @@ var EventList = [
|
||||
'select', // 选中事件
|
||||
'clear', // 清空场景
|
||||
'load', // 加载场景
|
||||
'save', // 保存场景
|
||||
|
||||
// signal事件
|
||||
'editScript', // 编辑脚本事件
|
||||
|
||||
@ -1,54 +0,0 @@
|
||||
import BaseEvent from '../BaseEvent';
|
||||
import UI from '../../ui/UI';
|
||||
import Converter from '../../serialization/Converter';
|
||||
import Ajax from '../../utils/Ajax';
|
||||
|
||||
/**
|
||||
* 保存场景事件
|
||||
* @param {*} app
|
||||
*/
|
||||
function SaveEvent(app) {
|
||||
BaseEvent.call(this, app);
|
||||
}
|
||||
|
||||
SaveEvent.prototype = Object.create(BaseEvent.prototype);
|
||||
SaveEvent.prototype.constructor = SaveEvent;
|
||||
|
||||
SaveEvent.prototype.start = function () {
|
||||
this.app.on(`save.${this.id}`, this.onBeforeSave.bind(this));
|
||||
};
|
||||
|
||||
SaveEvent.prototype.stop = function () {
|
||||
this.app.on(`save.${this.id}`, null);
|
||||
};
|
||||
|
||||
SaveEvent.prototype.onBeforeSave = function () {
|
||||
var sceneName = this.app.editor.sceneName;
|
||||
|
||||
if (sceneName == null) {
|
||||
var tempName = 'Scene' + new Date().getTime();
|
||||
UI.prompt('正在保存...', '场景名称', tempName, (event, name) => {
|
||||
this.app.editor.sceneName = name;
|
||||
document.title = name;
|
||||
this.onSave(name);
|
||||
});
|
||||
} else {
|
||||
this.onSave(sceneName);
|
||||
}
|
||||
};
|
||||
|
||||
SaveEvent.prototype.onSave = function (sceneName) {
|
||||
var obj = Converter.toJSON(this.app);
|
||||
|
||||
Ajax.post(this.app.options.server + '/api/Scene/Save', {
|
||||
Name: sceneName,
|
||||
Data: JSON.stringify(obj)
|
||||
}, function (result) {
|
||||
var obj = JSON.parse(result);
|
||||
UI.msg(obj.Msg);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
|
||||
export default SaveEvent;
|
||||
@ -25,7 +25,6 @@ export { default as NameObjectEvent } from './editor/NameObjectEvent';
|
||||
export { default as RemoveHelperEvent } from './editor/RemoveHelperEvent';
|
||||
export { default as RemoveObjectEvent } from './editor/RemoveObjectEvent';
|
||||
export { default as RemoveScriptEvent } from './editor/RemoveScriptEvent';
|
||||
export { default as SaveEvent } from './editor/SaveEvent';
|
||||
export { default as SelectEvent } from './editor/SelectEvent';
|
||||
export { default as SetGeometryNameEvent } from './editor/SetGeometryNameEvent';
|
||||
export { default as SetMaterialNameEvent } from './editor/SetMaterialNameEvent';
|
||||
|
||||
@ -1,4 +1,6 @@
|
||||
import MenuEvent from '../MenuEvent';
|
||||
import Converter from '../../../serialization/Converter';
|
||||
import Ajax from '../../../utils/Ajax';
|
||||
|
||||
/**
|
||||
* 保存场景
|
||||
@ -23,9 +25,30 @@ SaveSceneEvent.prototype.stop = function () {
|
||||
};
|
||||
|
||||
SaveSceneEvent.prototype.onSaveScene = function () {
|
||||
var editor = this.app.editor;
|
||||
var sceneName = this.app.editor.sceneName;
|
||||
|
||||
editor.save();
|
||||
if (sceneName == null) {
|
||||
var tempName = 'Scene' + new Date().getTime();
|
||||
UI.prompt('正在保存...', '场景名称', tempName, (event, name) => {
|
||||
this.app.editor.sceneName = name;
|
||||
document.title = name;
|
||||
this.commitSave(name);
|
||||
});
|
||||
} else {
|
||||
this.commitSave(sceneName);
|
||||
}
|
||||
};
|
||||
|
||||
SaveSceneEvent.prototype.commitSave = function (sceneName) {
|
||||
var obj = (new Converter()).toJSON(this.app);
|
||||
|
||||
Ajax.post(this.app.options.server + '/api/Scene/Save', {
|
||||
Name: sceneName,
|
||||
Data: JSON.stringify(obj)
|
||||
}, function (result) {
|
||||
var obj = JSON.parse(result);
|
||||
UI.msg(obj.Msg);
|
||||
});
|
||||
};
|
||||
|
||||
export default SaveSceneEvent;
|
||||
@ -26,23 +26,12 @@ function Converter() {
|
||||
BaseSerializer.call(this);
|
||||
|
||||
this.serializers = [
|
||||
new ConfigSerializer(),
|
||||
new ScriptSerializer(),
|
||||
new Object3DSerializer(),
|
||||
new SceneSerializer(),
|
||||
|
||||
new CameraSerializer(),
|
||||
new OrthographicCameraSerializer(),
|
||||
new PerspectiveCameraSerializer(),
|
||||
|
||||
new LightSerializer(),
|
||||
new PointLightSerializer(),
|
||||
new SpotLightSerializer(),
|
||||
new HemisphereLightSerializer(),
|
||||
new RectAreaLightSerializer(),
|
||||
new GeometrySerializer(),
|
||||
|
||||
new MaterialSerializer(),
|
||||
|
||||
new MeshSerializer()
|
||||
];
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user